-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
490 lines (421 loc) · 13.5 KB
/
init.vim
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
call plug#begin('~/.local/share/nvim/plugged')
" Color scheme
Plug 'overcache/NeoSolarized'
" Status line
Plug 'nvim-lualine/lualine.nvim'
" Project Navigation
Plug 'nvim-tree/nvim-tree.lua'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-fugitive'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-repeat'
Plug 'qpkorr/vim-bufkill'
Plug 'tpope/vim-surround'
Plug 'windwp/nvim-autopairs'
Plug 'windwp/nvim-ts-autotag'
" - Telescope
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
" Requires font-hack-nerd-font
Plug 'kyazdani42/nvim-web-devicons'
" Language tooling
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/nvim-treesitter-context'
Plug 'simrat39/symbols-outline.nvim'
" Autocomplete
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
" Snippets
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
" Language Syntax
Plug 'dense-analysis/ale'
" Jsonnet
Plug 'google/vim-jsonnet'
" Nginx
Plug 'chr4/nginx.vim'
call plug#end()
" Color scheme
set background=dark
colorscheme NeoSolarized
set nowrap
" General
set mouse=a "use mouse everywhere
set relativenumber "turn on line numbers
set number
set ruler "Always show current positions along the bottom
set showcmd "show the command being typed
set encoding=utf-8
set autoindent
set smartindent
set nocindent
" Prevent python comments or other characters from breaking indent
:inoremap # X<BS>#
set indentkeys-=0#,<:>
set cinkeys-=0#,<:>
filetype indent off
" Searching
set ignorecase
set smartcase
set hlsearch
set incsearch
" Save and Quit maps
" Got tired of accidentally hitting :Q and vim yelling at me
:command! W w
:command! Q q
" Tab mappings
" Avoid remapping tab in normal mode, so that CTRL-I works for moving around
" jumplist (Ctrl-I === <Tab>)
vmap <tab> >
vmap <S-tab> <
" Make searching with asterisk keep cursor and screen in same position
nnoremap <silent> * :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
" Bane of my existence, stop those damn "This file is being edited" errors
set noswapfile
" Allow switching away from unsaved buffers
set hidden
" Persistent undo
set undofile
set undodir=$HOME/.config/nvim/undo
set undolevels=1000
set undoreload=10000
" Support local configs
set exrc
set secure
" Set correct paths for python binary
let g:python_host_prog = $HOME."/.pyenv/shims/python"
let g:python3_host_prog = $HOME."/.pyenv/shims/python"
" ==========================
" ---------MAPPINGS---------
" ==========================
" Let <ESC> enter normal mode in terminal mode
:tnoremap <Esc> <C-\><C-n>
" Use CTRL-hjkl to move around windows
nmap <silent> <C-h> :wincmd h<CR>
nmap <silent> <C-j> :wincmd j<CR>
nmap <silent> <C-k> :wincmd k<CR>
nmap <silent> <C-l> :wincmd l<CR>
" Jump between buffers
nnoremap <C-,> :bp<CR>
nnoremap <C-.> :bn<CR>
" Movement Mappings, allow j/k to move one visual line even if wrapped
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
" Break line at cursor, inverse of J
nnoremap K i<CR><Esc>
" Switch to last file
nmap <C-e> :e#<CR>
" Tabs
set tabstop=4
set shiftwidth=4
set expandtab
set list listchars=tab:»·,trail:·
" Paste Mappings
nnoremap <Leader>y "+y
nnoremap <Leader>p "+p
nnoremap <Leader>P "+P
vnoremap <Leader>y "+y
vnoremap <Leader>p "+p
vnoremap <Leader>P "+P
nnoremap <Leader>m :messages<CR>
" Change tab width depending on type (e.g. 4 for python, 2 for ruby)
autocmd FileType ruby,htmldjango.html,mustache.html,html.handlebars,html,yaml,jsonnet setlocal shiftwidth=2 tabstop=2
autocmd FileType python setlocal shiftwidth=4 tabstop=4
autocmd FileType json,proto setlocal shiftwidth=4 tabstop=4
autocmd FileType pug setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript.jsx setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript.tsx setlocal shiftwidth=2 tabstop=2
autocmd FileType typescriptreact setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript setlocal shiftwidth=2 tabstop=2
autocmd FileType css setlocal shiftwidth=2 tabstop=2
autocmd FileType sass,less setlocal shiftwidth=2 tabstop=2
autocmd FileType salt setlocal shiftwidth=2 tabstop=2
autocmd FileType tsv setlocal noexpandtab shiftwidth=20 tabstop=20 " Disable tab-to-spaces for tsv's
" typescriptreact type is no bueno with plugins (especially LanguageClient)
autocmd BufRead,BufNewFile *.tsx set filetype=typescript.tsx
autocmd BufRead,BufNewFile *.jsx set filetype=javascript.jsx
" Fold settings
set foldmethod=syntax
set foldlevelstart=99
autocmd FileType yml setlocal foldmethod=indent
autocmd FileType python setlocal foldmethod=indent
" Restore the current buffer
function! BufDo(command)
let currBuff=bufnr("%")
execute 'bufdo ' . a:command
execute 'buffer ' . currBuff
endfunction
com! -nargs=+ -complete=command Bufdo call BufDo(<q-args>)
" Shortcut for refreshing vim
nnoremap <Leader>R :Bufdo all<CR>
" Debugging shortcuts
autocmd FileType javascript.jsx,typescript,typescript.tsx nnoremap <buffer> <Leader>br Odebugger<ESC>
autocmd FileType python nnoremap <buffer> <Leader>br Oimport ipdb; ipdb.set_trace()<ESC>
" ==========================
" -----------LSP------------
" ==========================
lua << EOF
local lspconfig = require'lspconfig'
lspconfig.tsserver.setup{} -- Requires npm install -g typescript typescript-language-server
-- Uncomment to switch python language sever impls
-- lspconfig.pylsp.setup{} -- Requires pip install "python-lsp-server[all]"
lspconfig.pyright.setup{ -- Requires npm install -g pyright
settings = {
python = {
anaysis = {
autoSearchPaths = true,
diagnosticMode = 'openFilesOnly',
}
}
}
}
-- RLS 2.0
lspconfig.rust_analyzer.setup{} -- brew install rust-analyzer
-- Disable inline dianostics
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = false, -- Not useful since it always runs off the edge
signs = true,
underline = true
}
)
-- Show error in popup
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
-- Show all errors in the current file in location list
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
EOF
nnoremap <buffer> <M-CR> <cmd>lua vim.lsp.buf.code_action()<CR>
" ==========================
" -------TREE-SITTER--------
" ==========================
lua <<EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = {"python", "rust", "typescript", "javascript", "tsx", "vim", "yaml"}, -- one of "all", or a list of languages
autotag = {
enable = true,
filetypes = {"html", "tsx", "jsx" }
},
indent = {
enable = true
},
highlight = {
enable = true, -- false will disable the whole extension
},
}
EOF
" ==========================
" ------- LUALINE ----------
" ==========================
lua <<EOF
require('lualine').setup {
options = { theme = 'solarized_dark' },
sections = {
lualine_c = {
{
'filename',
path = 1 -- Relative path
}
}
}
}
EOF
" ==========================
" ------- NVIM-CMP----------
" ==========================
lua <<EOF
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<Tab>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
['<S-Tab>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Repeat for each configured lsp server
require('lspconfig')['tsserver'].setup {
capabilities = capabilities
}
require('lspconfig')['pyright'].setup {
capabilities = capabilities
}
require('lspconfig')['rust_analyzer'].setup {
capabilities = capabilities
}
EOF
" ==========================
" ---------PLUGINS----------
" ==========================
" ~~~LSP~~~
nnoremap <Leader>D <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <Leader>d <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <Leader>s <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <Leader>r <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap gk <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <Leader>S <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
" ~~~~~ TELESCOPE.VIM ~~~~~
nnoremap <Leader>ff <cmd>lua require('telescope.builtin').find_files()<CR>
nnoremap <Leader>fg <cmd>lua require('telescope.builtin').live_grep()<CR>
nnoremap <Leader>fb <cmd>lua require('telescope.builtin').buffers()<CR>
nnoremap <Leader>fh <cmd>lua require('telescope.builtin').help_tags()<CR>
" Keep my old Ack plugin bindings to make searching faster
nnoremap <Leader>a <cmd>lua require('telescope.builtin').live_grep()<CR>
xnoremap <Leader>a <cmd>lua require('telescope.builtin').grep_string()<CR>
" Keep my old ctrl-p plugin binding to make searching files faster
nnoremap <Leader>t <cmd>lua require('telescope.builtin').find_files()<CR>
lua <<EOF
require('telescope').setup {
pickers = {
find_files = {
hidden = true
},
live_grep = {
hidden = true
}
},
defaults = {
file_ignore_patterns = {
"node_modules",
".git",
".pickle",
".csv",
"data/.*.json",
"data/.*.txt",
"data/.*.csv",
"data/.*.CSV",
"frontend/package-lock.json",
}
}
}
EOF
" ~~~~~ SymbolsOutline ~~~~~
lua << EOF
require("symbols-outline").setup {
keymaps = { -- These keymaps can be a string or a table for multiple keys
close = {"<Esc>", "q"},
goto_location = "<CR>",
focus_location = "<S-CR>",
hover_symbol = "<Leader>s",
toggle_preview = "K",
rename_symbol = "r",
code_actions = "a",
fold = "x",
unfold = "o",
fold_all = "X",
unfold_all = "O",
fold_reset = "R",
}
}
EOF
nnoremap <Leader>o :SymbolsOutline<CR>
" ~~~~~ Vim-Fugitive ~~~~~
set diffopt+=vertical " make diffs open vertically instead of horizontally (ew)
" ~~~~~ nvim-tree ~~~~~~~
lua << EOF
require("nvim-tree").setup()
EOF
nnoremap <Leader>e :NvimTreeToggle<CR>
" ~~~~~ ALE ~~~~~
nnoremap <Leader>F :ALEFix<CR>
" Fixer for jsonnet files
autocmd FileType jsonnet nnoremap <buffer> <Leader>f :w<CR>:silent !jsonnetfmt --comment-style s --string-style d -i %<CR>
" Specify fixers for different filetypes
let g:ale_fixers = {
\ 'svg': ['xmllint'],
\ 'python': ['black', 'isort'],
\ 'javascript': ['prettier'],
\ 'typescript': ['prettier'],
\ 'rust': ['rustfmt'],
\ }
let g:ale_linters = {
\ 'python': ['pylint'],
\ }
let g:ale_javascript_prettier_executable = 'prettierd'
" Set MYPYPATH explicitly if we're in a virtualenv
if !empty($VIRTUAL_ENV)
let $MYPYPATH = $VIRTUAL_ENV.''
else
endif
" ~~~~~ Autopairs ~~~~~
lua << EOF
require("nvim-autopairs").setup {}
EOF
"~~~~~~ Autotag ~~~~~
lua << EOF
require('nvim-ts-autotag').setup({
opts = {
-- Defaults
enable_close = true, -- Auto close tags
enable_rename = true, -- Auto rename pairs of tags
enable_close_on_slash = false -- Auto close on trailing </
},
-- Also override individual filetype configs, these take priority.
-- Empty by default, useful if one of the "opts" global settings
-- doesn't work well in a specific filetype
per_filetype = {
["html"] = { }
}
})
EOF
" ~~~~~ jsonnet ~~~~~
let g:jsonnet_fmt_on_save = 0
" Load custom settings
source $HOME/.config/nvim/custom.vim