-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
134 lines (115 loc) · 3.98 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
require('plugins')
-- <Space> is <Leader>
vim.g.mapleader = ' '
-- Main config
vim.opt.clipboard = 'unnamed' -- yank goes to clipboard
vim.opt.number = true -- display line numbers
vim.opt.autoindent = true -- copy indent from prev line
vim.opt.tabstop = 2 -- set tab to 2 spaces
vim.opt.shiftwidth = 2 -- set '>>' and '<<' spacing indent
vim.opt.ignorecase = true -- ignore case in search
vim.opt.hlsearch = true -- highlight all search matches
vim.opt.smartcase = true -- pay attention to case when caps are used
vim.opt.incsearch = true -- show search results as I type
vim.opt.ttimeoutlen = 100 -- decrease timeout for faster insert with 'O'
vim.opt.ruler = true -- show row and column in footer
vim.opt.scrolloff = 2 -- minimum lines above/below cursor
vim.opt.laststatus = 2 -- always show status bar
vim.opt.expandtab = true -- use spaces instead of tabs
vim.opt.listchars = 'tab:»·,nbsp:·,trail:·,extends:>,precedes:<'
vim.opt.list = true -- display unprintable characters
-- Auto-removal of trailing whitespaces on save
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
pattern = { '*' },
command = [[%s/\s\+$//e]],
})
-- Auto-fix imports and format Golang files
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
pattern = { '*.go' },
callback = function()
vim.lsp.buf.format()
vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true })
end
})
function map(mode, shortcut, command)
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
end
function nmap(shortcut, command)
map('n', shortcut, command)
end
function imap(shortcut, command)
map('i', shortcut, command)
end
function vmap(shortcut, command)
map('v', shortcut, command)
end
function cmap(shortcut, command)
map('c', shortcut, command)
end
function tmap(shortcut, command)
map('t', shortcut, command)
end
-- Mappings
-- <Space> + <Space> = NvimTree
nmap('<Leader><Leader>', ':NvimTreeToggle<CR>')
-- <Space> + <p> = Toggle paste mode
nmap('<Leader>p', ':set invpaste<CR>')
-- <Space> + <T> = New tab
nmap('<Leader>t', ':tabnew<CR>')
-- <Space> + <f> = Telescope search
nmap('<Leader>f', '<CMD>Telescope find_files<CR>')
-- <Ctrl> + <\> = Open console
require('toggleterm').setup{ direction = 'horizontal', size = 15, open_mapping = [[<C-\>]] }
-- <Space> + <e> = Show LSP error diagnostics
nmap('<Leader>e', ":lua vim.diagnostic.open_float(0, {scope='line'})<CR>")
-- <Ctrl> + <key> = Navigate LSP items
-- <Tab> = Confirm LSP suggestion
local cmp = require('cmp')
local cmp_action = require('lsp-zero').cmp_action()
cmp.setup({
mapping = {
-- Navigate between completion item
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
-- toggle completion
['<C-u>'] = cmp_action.toggle_completion(),
-- navigate between snippet placeholder
['<C-a>'] = cmp_action.luasnip_jump_backward(),
['<C-d>'] = cmp_action.luasnip_jump_forward(),
-- Confirm item
['<Tab>'] = cmp.mapping.confirm({select = true}),
}
})
-- Reminder
-- <K> = See docs
-- gd = Go to definition(<Ctrl> + <o> back)
-- <Ctrl> + <i> = go forward
-- <Ctrl> + <o> = go back
-- Language
vim.cmd('language en_US')
-- Colorscheme
vim.cmd('colorscheme tokyonight-storm')
-- Turn off LSP logger which grows indefinitely
-- Switch to "debug" or comment if you need to debug LSP
vim.lsp.set_log_level("off")
-- LSP
local lsp = require('lsp-zero').preset({})
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({buffer = bufnr})
end)
lsp.ensure_installed({
-- Replace these with whatever servers you want to install
-- Servers list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- Type :Mason to update/install LSPs
'gopls',
'solargraph',
'terraformls',
})
-- Don't use terraformls on .tfvars as it's full of errors
vim.cmd([[
augroup FileTypeTerraform
autocmd!
autocmd BufRead,BufNewFile *.tfvars setlocal filetype=plaintext
augroup END
]])
lsp.setup()