-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvimrc
202 lines (182 loc) · 6.73 KB
/
vimrc
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
set termguicolors
colorscheme solarized
set background=light
set cursorline
set expandtab
set ignorecase
set list
set listchars=tab:»\ ,trail:·
set notimeout " for example between <leader> and the rest of a mapping
set number
set scrolloff=1
set shiftwidth=4
set smartcase
set tabstop=4
" Leader key is space.
let mapleader = " "
noremap <space> <nop>
" remain in visual mode when indenting or dedenting
vnoremap < <gv
vnoremap > >gv
" remap backspace to last file
nnoremap <bs> <c-^>
" a keybinding to insert a [hyper](link) in markdown
vnoremap <c-k> <esc>`>a]()<esc>`<i[<esc>/()<cr>:nohlsearch<cr>a
" common typos
command W w
command Q q
command WQ wq
command Wq wq
command WA wa
command Wa wa
" Prefer // over /*...*/. Used by vim-commentary.
" See https://stackoverflow.com/a/68813146/823869 for why we need to do
" 'filetype plugin indent on' first.
filetype plugin indent on
autocmd FileType c,cpp,cs,java setlocal commentstring=//\ %s
" Use whole words when opening URLs with `gx`. https://vi.stackexchange.com/a/2980/1949
let g:netrw_gx="<cWORD>"
" Telescope bindings
" most important shortcuts
nnoremap <c-t> <cmd>Telescope find_files<cr>
nnoremap g<c-t> <cmd>Telescope resume<cr>
nnoremap <c-p> <cmd>Telescope oldfiles<cr>
" general finders
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fof <cmd>Telescope oldfiles<cr>
nnoremap <leader>faf <cmd>lua require('telescope.builtin').find_files({hidden=1, no_ignore=1})<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fs <cmd>Telescope lsp_dynamic_workspace_symbols<cr>
nnoremap <leader>fd <cmd>lua require('telescope.builtin').diagnostics({severity_limit="warn"})<cr>
nnoremap <leader>fg <cmd>Telescope git_status<cr>
nnoremap <leader>fc <cmd>Telescope command_history<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" finders based on the symbol under the cursor
nnoremap <leader>gr <cmd>Telescope lsp_references<cr>
nnoremap <leader>gi <cmd>Telescope lsp_implementations<cr>
nnoremap <leader>gw <cmd>Telescope grep_string<cr>
nnoremap <leader>gaw <cmd>lua require('telescope.builtin').grep_string({additional_args={"--hidden", "--no-ignore"}})<cr>
" live ripgrep
nnoremap <leader>rg <cmd>Telescope live_grep<cr>
nnoremap <leader>ra <cmd>lua require('telescope.builtin').live_grep({additional_args={"--hidden", "--no-ignore"}})<cr>
" key bindings within Telescope
lua << END
require('telescope').setup{
defaults = {
path_display = {"truncate"},
mappings = {
i = {
["<c-j>"] = "move_selection_next",
["<c-k>"] = "move_selection_previous",
-- default mappings
-- ["<c-c>"] = "close",
-- ["<c-n>"] = "move_selection_next",
-- ["<c-p>"] = "move_selection_previous",
},
n = {
["<c-c>"] = "close",
["<c-j>"] = "move_selection_next",
["<c-k>"] = "move_selection_previous",
["<c-n>"] = "move_selection_next",
["<c-p>"] = "move_selection_previous",
["k"] = "cycle_history_prev",
["j"] = "cycle_history_next",
},
},
},
}
END
" Bindings for opening new tmux windows in the current file's parent directory.
map <leader>t :let $VIM_DIR=expand('%:p:h')<cr>:silent exec "!tmux new-window -c $VIM_DIR"<cr>
" Note that tmux's notion of vertical/horizontal is opposite Vim's, and I prefer Vim's.
map <leader>ht :let $VIM_DIR=expand('%:p:h')<cr>:silent exec "!tmux split-window -v -c $VIM_DIR"<cr>
map <leader>vt :let $VIM_DIR=expand('%:p:h')<cr>:silent exec "!tmux split-window -h -c $VIM_DIR"<cr>
" Hop bindings
lua require'hop'.setup()
nnoremap <leader>w :HopWord<cr>
nnoremap <leader>/ :HopChar1<cr>
" gitgutter configs
set updatetime=100 " reduces lag
let g:gitgutter_sign_added = '┃'
let g:gitgutter_sign_modified = '│'
let g:gitgutter_sign_removed = '▁'
let g:gitgutter_sign_removed_first_line = '▔'
let g:gitgutter_sign_removed_above_and_below = '▁▔'
let g:gitgutter_sign_modified_removed = '│▁'
" TreeSitter configs
lua <<END
require'nvim-treesitter.configs'.setup {
ensure_installed = { "c", "cpp", "rust", "python", "go", "vim", "lua" },
auto_install = true,
highlight = {
enable = true,
},
}
END
" LSP configs
lua <<END
local lspconfig = require('lspconfig')
lspconfig.rust_analyzer.setup{}
lspconfig.clangd.setup{}
lspconfig.gopls.setup{}
lspconfig.pyright.setup{}
-- Global mappings.
vim.keymap.set('n', ']d', function()
vim.diagnostic.goto_next({
severity = { min = vim.diagnostic.severity.WARN },
})
end)
vim.keymap.set('n', '[d', function()
vim.diagnostic.goto_prev({
severity = { min = vim.diagnostic.severity.WARN },
})
end)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, opts)
end,
})
-- format on save
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = buffer,
callback = function()
vim.lsp.buf.format { async = false }
end
})
-- Show diagnostics in severity order (i.e. errors on top of warnings).
vim.diagnostic.config({ severity_sort = true })
-- Work around the colorscheme's lack of support for semantic highlighting.
-- https://gist.github.com/swarn/fb37d9eefe1bc616c2a7e476c0bc0316
-- https://old.reddit.com/r/neovim/comments/12gvms4/this_is_why_your_higlights_look_different_in_90/
local links = {
['@lsp.type.namespace'] = '@namespace',
['@lsp.type.type'] = '@type',
['@lsp.type.class'] = '@type',
['@lsp.type.enum'] = '@type',
['@lsp.type.interface'] = '@type',
['@lsp.type.struct'] = '@structure',
['@lsp.type.parameter'] = '@parameter',
['@lsp.type.variable'] = '@variable',
['@lsp.type.property'] = '@property',
['@lsp.type.enumMember'] = '@constant',
['@lsp.type.function'] = '@function',
['@lsp.type.method'] = '@method',
['@lsp.type.macro'] = '@macro',
['@lsp.type.decorator'] = '@function',
}
for newgroup, oldgroup in pairs(links) do
vim.api.nvim_set_hl(0, newgroup, { link = oldgroup, default = true })
end
END