-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim.vim
350 lines (304 loc) · 8.3 KB
/
nvim.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
" A VimRC
" Todd Hainsworth
" {{{ Setup
if has("unix")
let s:uname = system("uname -s")
if s:uname == "Darwin"
set rtp+=/opt/homebrew/opt/fzf
endif
endif
let mapleader = "\\"
autocmd!
set nocompatible
filetype off
" No plans to use Vim anywhere where this'd cause issues
set t_Co=256
" }}}
" {{{ Plugin
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fireplace'
Plug 'scrooloose/NERDTree'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'dikiaap/minimalist'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'dense-analysis/ale'
Plug 'rust-lang/rust.vim'
Plug 'machakann/vim-highlightedyank'
Plug 'airblade/vim-rooter'
Plug 'mileszs/ack.vim'
Plug 'tpope/vim-repeat'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'jparise/vim-graphql'
Plug 'xolox/vim-misc'
Plug 'ervandew/supertab'
Plug 'vim-vdebug/vdebug'
Plug 'vim-scripts/utl.vim'
Plug 'tpope/vim-speeddating'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'jreybert/vimagit'
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
Plug 'jparise/vim-graphql'
Plug 'lervag/vimtex'
if has("unix")
let g:uname = system("uname")
if g:uname == "Darwin\n"
Plug 'neovim/nvim-lspconfig'
Plug 'simrat39/rust-tools.nvim'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
endif
endif
call plug#end()
" }}}
" {{{ Settings
filetype plugin indent on
syntax enable
syntax sync fromstart
set mouse=a
set nowrap " I hardly ever want to wrap code
set cursorline " Hilight the current line
set undofile " Keep track of undoable changes even after buffer closes
set undodir=~/.vim/undo " Sane undo location
set vb " That annoying bell is no more!
set showcmd " Show incomplete command
set number
set relativenumber
set exrc
" Remove gui elements
set guioptions-=mTrL
" Whitespace
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
set shiftround
set colorcolumn=140
set tags=.tags
set completeopt=menuone,noinsert,noselect
set shortmess+=c
colorscheme minimalist
" Help syntax highlighting keep up with large JS or TS files
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
" }}}
" {{{ Folding
set foldmethod=marker
nnoremap <space> za
" }}}
" {{{ Keymap
" Move sanely
map j gj
map k gk
" Avoid typos
nmap ; :
" I prefer `B` and `E` to go to the beginning and end of lines
map B ^
map E $
" Disable search hilighting
nnoremap <leader>hl :noh<cr>
" Centered search results
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" Slightly more magic searching
nnoremap ? ?\v
nnoremap / /\v
cnoremap %s/ %sm/
" Please stop...
map <F1> <Esc>
imap <F1> <Esc>
" No arrow keys --- force yourself to use the home row
nmap <up> <nop>
nmap <down> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
" Switch buffers with arrows instead
nnoremap <left> :bp<cr>
nnoremap <right> :bn<cr>
" Toggle between buffers with "\\"
nnoremap <leader><leader> <c-^>
" Switching between splits
nnoremap <leader>we <C-w>l
nnoremap <leader>wq <C-w>h
nnoremap <leader>ww <C-w>k
nnoremap <leader>ws <C-w>j
nnoremap <leader>vs :vsplit<cr>
nnoremap <leader>ss :split<cr>
" Easily get back here
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" Easier exit
inoremap jj <esc>
" Show current file path
nnoremap <leader>ff 1<C-G>
" Misc. Autocomplete stuff
" inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
" inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" LanguageClient
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
" Vimagit
nnoremap <leader>mm :Magit<cr>
" }}}
" {{{ Plugin related
" FZF and misc file finding
set wildignore+=*/doc/*
nnoremap <c-p> :Files<cr>
nnoremap <c-b> :Buffers<cr>
nnoremap <c-t> :Tags<cr>
nnoremap <c-f> :Ag<cr>
nnoremap <c-c> :Commits<cr>
nnoremap <c-C> :BCommits<cr>
if filereadable("vendor/")
if executable('ag')
let $FZF_DEFAULT_COMMAND = 'ag -g "" -U vendor/ ./'
else
let $FZF_DEFAULT_COMMAND = 'ack -g "" vendor ./'
end
else
if executable('ag')
let $FZF_DEFAULT_COMMAND = 'ag -g "" -U ./'
else
let $FZF_DEFAULT_COMMAND = 'ack -g "" ./'
end
endif
" Fugitive
nnoremap <leader>gb :Gblame<cr>
nnoremap <leader>gd :Gdiff<cr>
" Commentary
nnoremap <leader>c<space> :Commentary<cr>
vnoremap <leader>c<space> :Commentary<cr>
" NERDTree
nnoremap <leader>nt :NERDTreeToggle<CR>
nnoremap <leader>nf :NERDTreeFind<cr>
" Ack.vim
nnoremap <leader>/ :Ack!<space>
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
" Airline + Minimalist VimTheme
let g:airline_theme='minimalist'
let g:airline_powerline_fonts=1
let g:airline#extensions#tabline#enabled=0
" Supertab
let g:SuperTabDefaultCompletionType="<c-n>"
" Format JSON
nnoremap <leader>js %!python -m json.tool<cr>
" Rust
let g:rustfmt_autosave = 1
" Language Server/Client
let g:LanguageClient_autoStart=1
let g:LanguageClient_signColumnAlwaysOn = 1
let g:LanguageClient_settingsPath = "/home/todd/.vim/settings.json"
let g:LanguageClient_serverCommands = {
\ 'rust': ['env', 'CARGO_TARGET_DIR=/Users/todd/.cargo/bin/rls', 'rls'],
\ 'python': ['pyls'],
\ }
nnoremap <silent> K :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
" ALE
let g:ale_pattern_options = {'\.php$': {'ale_enabled': 0}}
let g:ale_linters = {'rust': ['analyzer']}
" Neovim language client stuff
" LSP Setup
if has("unix")
let s:uname = system("uname")
if s:uname == "Darwin\n"
set updatetime=300
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()
lua << EOF
local nvim_lsp = require'lspconfig'
local opts = {
tools = { -- rust-tools options
autoSetHints = true,
hover_with_actions = true,
inlay_hints = {
show_parameter_hints = false,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {
-- on_attach is a callback called when the language server attachs to the buffer
-- on_attach = on_attach,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy on save
checkOnSave = {
command = "clippy"
},
}
}
},
}
require('rust-tools').setup(opts)
EOF
" LSP Completion Setup
lua <<EOF
local cmp = require'cmp'
cmp.setup({
-- Enable LSP snippets
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
},
})
EOF
endif
endif
" Fireplace
autocmd BufEnter *.clj nnoremap <leader>EE :%Eval<cr>
autocmd BufEnter *.clj nnoremap <leader>EP vap:Eval<cr>
autocmd BufEnter *.clj vnoremap <leader>EE :Eval<cr>
" LaTeX
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
set conceallevel=1
let g:tex_conceal='abdmg'
" }}}
" see exrc above
set secure