-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinit.vim
More file actions
411 lines (328 loc) · 14.7 KB
/
init.vim
File metadata and controls
411 lines (328 loc) · 14.7 KB
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
" Author: Matt Wozniski ([email protected])
"
" Feel free to do whatever you would like with this file.
""" Settings
"""" Locations searched for scripts
call pathogen#infect('runtimes')
"""" Mouse, Keyboard, Terminal
set mouse=nv " Allow mouse use in normal and visual mode.
set timeoutlen=2000 " Wait 2 seconds before timing out a mapping
set lazyredraw " Avoid redrawing the screen mid-command.
""""" Titlebar
set title " Turn on titlebar support
" Titlebar string: hostname> ${PWD:s/^$HOME/~} || (view|vim) filename ([+]|)
let &titlestring = hostname() . '> ' . '%{expand("%:p:~:h")}'
\ . ' || %{&ft=~"^man"?"man":&ro?"view":"vim"} %f %m'
"""" Moving Around/Editing
set whichwrap=b,s,h,l,<,> " <BS> <Space> h l <Left> <Right> can change lines
set virtualedit=block " Let cursor move past the last char in <C-v> mode
set scrolloff=3 " Keep 3 context lines above and below the cursor
set showmatch " Briefly jump to a paren once it's balanced
set matchtime=2 " (for only .2 seconds).
"""" Searching and Patterns
set ignorecase " Default to using case insensitive searches,
set smartcase " unless uppercase letters are used in the regex.
"""" Windows, Buffers
set noequalalways " Don't keep resizing all windows to the same size
set hidden " Hide modified buffers when they are abandoned
set swb=useopen,usetab " Allow changing tabs/windows for quickfix/:sb/etc
set splitright " New windows open to the right of the current one
"""" Insert completion
set completeopt=menuone " Show the completion menu even if only one choice
"""" Text Formatting
set formatoptions=q " Format text with gq, but don't format as I type.
set formatoptions+=j " When joining lines, remove comment leaders.
set formatoptions+=n " gq recognizes numbered lists, and will try to
set formatoptions+=1 " break before, not after, a 1 letter word
"""" Display
set number " Display line numbers
set numberwidth=1 " using only 1 column (and 1 space) while possible
set signcolumn=number " and drawing signs in the number column
set display+=uhex " Use <03> rather than ^C for non-printing chars
set inccommand=nosplit " Preview :s commands incrementally as you type
" In visual mode, make the cursor an underbar 15% of the cell high,
" and make it blink off for 100ms every 300ms.
set guicursor+=v:hor15-blinkon300-blinkoff100-blinkwait300
set list " visually represent certain invisible characters:
set listchars= " Don't use the default markers; instead:
set listchars+=nbsp:⋅ " Use U+22C5 DOT OPERATOR for non-breaking spaces
set listchars+=trail:⋅ " and for trailing spaces at EOL,
set listchars+=tab:▷⋅ " and U+25B7 WHITE RIGHT-POINTING TRIANGLE plus
" zero or more DOT OPERATOR for a tab character.
"""" Messages, Info, Status
set confirm " Y-N-C prompt if closing with unsaved changes.
set report=0 " : commands always print changed line count.
set shortmess+=a " Use [+]/[RO]/[w] for modified/readonly/written.
let &statusline = '%<%f%{&mod?"[+]":""}%r%'
\ . '{&fenc !~ "^$\\|utf-8" || &bomb ? "[".&fenc.(&bomb?"-bom":"")."]" : ""}'
\ . '%='
\ . '%15.(%l,%c%V %P%)'
"""" Tabs/Indent Levels
set tabstop=8 " Real tab characters are 8 spaces wide,
set shiftwidth=4 " but an indent level is 4 spaces wide.
set softtabstop=4 " <BS> over an autoindent deletes all 4 spaces.
set expandtab " Use spaces, not tabs, for autoindent/tab key.
"""" Tags
set showfulltag " Show more information while completing tags.
if has('cscope')
set cscopetag " When using :tag, <C-]>, or "vim -t", try cscope:
set cscopetagorder=0 " try ":cscope find g foo" and then ":tselect foo"
endif
"""" Reading/Writing
set noautowrite " Never write a file unless I request it.
set noautowriteall " NEVER.
set noautoread " Don't automatically re-read changed files.
"""" Backups/Swap Files
set writebackup " Make a backup of the original file when writing
set backup " and don't delete it after a succesful write.
set backupskip= " There are no files that shouldn't be backed up.
set updatetime=2000 " Write swap files after 2 seconds of inactivity.
set backupext=~ " Backup for "file" is "file~"
set backupdir^=~/.backup " Backups are written to ~/.backup/ if possible.
"""" Command Line
set wildmenu " Menu completion in command mode on <Tab>
"""" Per-Filetype Scripts
" NOTE: These define autocmds, so they should come before any other autocmds.
" That way, a later autocmd can override the result of one defined here.
filetype on " Enable filetype detection,
filetype indent on " use filetype-specific indenting where available,
filetype plugin on " also allow for filetype-specific plugins,
syntax on " and turn on per-filetype syntax highlighting.
""" Plugin Settings
let lisp_rainbow=1 " Color parentheses by depth in LISP files.
let is_posix=1 " Assume /bin/sh is POSIX compliant by default.
let vim_indent_cont=4 " Spaces to add for vimscript continuation lines
let no_buffers_menu=1 " Disable 'Buffers' menu
let surround_indent=1 " Automatically reindent text surround.vim affects
let fastfold_minlines=0 " Don't update syntax folds in insert mode
" When using a gvim-only colorscheme in terminal vim with CSApprox
" - Disable the bold and italic attributes completely
" - Use the color specified by 'guisp' as the foreground color.
let g:CSApprox_attr_map = { 'bold' : '', 'italic' : '', 'sp' : 'fg' }
""" Autocommands
augroup vimrcEx
au!
" In plain-text files and svn commit buffers, wrap automatically at 78 chars
au FileType text,svn setlocal tw=78 fo+=t
" Try to jump to the last spot the cursor was at in a file when reading it.
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Use :make to compile C, even without a makefile
au FileType c if glob('[Mm]akefile') == "" | let &mp="gcc -o %< %" | endif
" Use :make to compile C++, too
au FileType cpp if glob('[Mm]akefile') == "" | let &mp="g++ -o %< %" | endif
" When reading a file, :cd to its parent directory unless it's a help file.
au BufEnter * if &ft != 'help' | silent! cd %:p:h | endif
" Use syntaxcomplete as a default omnifunc for languages without one
au Filetype * let &l:ofu = (len(&ofu) ? &ofu : 'syntaxcomplete#Complete')
" zfunctions are in the zsh language
au BufRead,BufNewFile ~/.zsh/.zfunctions/[^.]* setf zsh
" Update the system clipboard after yanking in visual mode.
autocmd TextYankPost *
\ if v:event.visual && v:operator == 'y' |
\ let @+ = getreg(v:event.regname) |
\ endif
" Flash anything that was just yanked, except in visual mode.
autocmd TextYankPost *
\ lua vim.highlight.on_yank {on_visual = false, higroup = Search}
augroup END
""" Colorscheme
colorscheme autumnleaf " 256 color light scheme
"colorscheme brookstream " 256 color dark scheme
""" Key Mappings
" Make [[ and ]] work even if the { is not in the first column
nnoremap <silent> [[ :call search('^\S\@=.*{\s*$', 'besW')<CR>
nnoremap <silent> ]] :call search('^\S\@=.*{\s*$', 'esW')<CR>
onoremap <expr> [[ (search('^\S\@=.*{\s*$', 'ebsW') && (setpos("''", getpos('.'))
\ <bar><bar> 1) ? "''" : "\<ESC>")
onoremap <expr> ]] (search('^\S\@=.*{\s*$', 'esW') && (setpos("''", getpos('.'))
\ <bar><bar> 1) ? "''" : "\<ESC>")
" Some Emacs bindings for the command window
cnoremap <C-A> <Home>
cnoremap <ESC>b <S-Left>
cnoremap <ESC>f <S-Right>
cnoremap <ESC><BS> <C-W>
" Extra functionality for some existing commands:
" <C-6> switches back to the alternate file and the correct column in the line.
nnoremap <C-6> <C-6>`"
" Swap ` and ' in normal mode - I normally want ``, but '' is easier to hit
nnoremap ` '
nnoremap ' `
" CTRL-g shows filename and buffer number, too.
nnoremap <C-g> 2<C-g>
" <C-l> redraws the screen and removes search highlighting and LSP diagnostics.
nnoremap <silent> <C-l> <cmd>nohl\|lua vim.diagnostic.hide(nil, 0)<CR><C-l>
" In normal/insert mode, ar inserts spaces to right align to &tw or 80 chars
nnoremap <leader>ar :AlignRight<CR>
" In normal/insert mode, ac center aligns the text after it to &tw or 80 chars
nnoremap <leader>ac :center<CR>
" Zoom in on the current window with <leader>z
nmap <leader>z <Plug>ZoomWin
" F10 toggles highlighting lines that are too long
nnoremap <F10> :call <SID>ToggleTooLongHL()<CR>
" F11 toggles line numbering
nnoremap <silent> <F11> :set number! <bar> set number?<CR>
" F12 toggles search term highlighting
nnoremap <silent> <F12> :set hlsearch! <bar> set hlsearch?<CR>
" <space> toggles folds opened and closed
nmap <space> za
" <space> in visual mode creates a fold over the marked range
vmap <space> zf
" Pressing an 'enter visual mode' key while in visual mode changes mode.
vmap <C-V> <ESC>`<<C-v>`>
vmap V <ESC>`<V`>
vmap v <ESC>`<v`>
" Make { and } in visual mode stay in the current column unless 'sol' is set.
vnoremap <expr> { line("'{") . 'G'
vnoremap <expr> } line("'}") . 'G'
" <leader>bsd inserts BSD copyright notice
nnoremap <leader>bsd :BSD<CR>
" <leader>sk inserts skeleton for the current filetype
nnoremap <leader>sk :Skel<CR>
" Insert a modeline on the last line with <leader>ml
nmap <leader>ml :$put =<SID>ModelineStub()<CR>
" Tapping C-W twice brings me to previous window, not next.
nnoremap <C-w><C-w> :winc p<CR>
" Get old behavior with <C-w><C-e>
nnoremap <C-w><C-e> :winc w<CR>
" Y behaves like D rather than like dd
nnoremap Y y$
" ctrl-backspace deletes the last word when inserting
imap <C-_> <C-w>
""" Abbreviations
function! s:InsertCloseBraceAfterCR(open, close)
let c = nr2char(getchar(0))
if c == "\r"
return a:open . c . a:close . "\<C-o>O"
endif
return a:open . c
endfunction
function! s:EatChar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
iabbr _me Matt Wozniski <[email protected]>
iabbr _dt <C-R>=strftime("%a, %d %b %Y %H:%M:%S %z")<CR>
iabbr #i< #include <><left><C-R>=<SID>EatChar('\s')<CR>
iabbr #i" #include ""<left><C-R>=<SID>EatChar('\s')<CR>
iabbr { <C-r>=<SID>InsertCloseBraceAfterCR("{", "}")<CR>
""" Cute functions
function! s:ToggleTooLongHL()
if exists('*matchadd')
if ! exists("w:TooLongMatchNr")
let last = (&tw <= 0 ? 80 : &tw)
let w:TooLongMatchNr = matchadd('ErrorMsg', '.\%>' . (last+1) . 'v', 0)
echo " Long Line Highlight"
else
call matchdelete(w:TooLongMatchNr)
unlet w:TooLongMatchNr
echo "No Long Line Highlight"
endif
endif
endfunction
function! s:ModelineStub()
let fmt = ' vim: set ts=%d sts=%d sw=%d %set: '
let x = printf(&cms, printf(fmt, &ts, &sts, &sw, (&et?"":"no")))
return substitute(substitute(x, '\ \+', ' ', 'g'), ' $', '', '')
endfunction
" Replace tabs with spaces in a string, preserving alignment.
function! s:Retab(string)
let rv = ''
let i = 0
for char in split(a:string, '\zs')
if char == "\t"
let rv .= repeat(' ', &ts - i)
let i = 0
else
let rv .= char
let i = (i + 1) % &ts
endif
endfor
return rv
endfunction
" Right align the portion of the current line to the right of the cursor.
" If an optional argument is given, it is used as the width to align to,
" otherwise textwidth is used if set, otherwise 80 is used.
function! s:AlignRight(...)
if getline('.') =~ '^\s*$'
call setline('.', '')
else
let line = s:Retab(getline('.'))
let prefix = matchstr(line, '.*\%' . virtcol('.') . 'v')
let suffix = matchstr(line, '\%' . virtcol('.') . 'v.*')
let prefix = substitute(prefix, '\s*$', '', '')
let suffix = substitute(suffix, '^\s*', '', '')
let len = len(substitute(prefix, '.', 'x', 'g'))
let len += len(substitute(suffix, '.', 'x', 'g'))
let width = (a:0 == 1 ? a:1 : (&tw <= 0 ? 80 : &tw))
let spaces = width - len
call setline('.', prefix . repeat(' ', spaces) . suffix)
endif
endfunction
com! -nargs=? AlignRight :call <SID>AlignRight(<f-args>)
command! -nargs=1 -complete=dir Rename saveas <args> | call delete(expand("#"))
lua <<EOF
vim.cmd('packadd nvim-lspconfig')
require 'lspconfig'.clangd.setup{}
require 'lspconfig'.pyright.setup{}
require 'lspconfig'.efm.setup {
init_options = {documentFormatting = true},
settings = {
rootMarkers = {".git/"},
languages = {
python = {
{formatCommand = "black --quiet -", formatStdin = true},
{formatCommand = "isort -", formatStdin = true},
{lintCommand = "flake8 --max-line-length 88 -", lintStdin = true},
}
}
},
filetypes = {"python"},
}
-- require 'lspconfig'.pyls.setup{
-- settings = {
-- pyls = {
-- configurationSources = {"flake8"};
-- }
-- }
-- }
EOF
nnoremap <C-up> <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <C-down> <cmd>lua vim.diagnostic.goto_next()<CR>
nnoremap <Leader>k <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <Leader>j <cmd>lua vim.diagnostic.goto_next()<CR>
nnoremap <Leader>x <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <Leader>d <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <Leader>f <cmd>lua vim.lsp.buf.format()<CR>
nnoremap <Leader>h <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <Leader>n <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <Leader>r <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <Leader>o <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <Leader>l <cmd>lua vim.diagnostic.set_loclist()<CR>
hi link LspDiagnosticsVirtualTextError Comment
hi link LspDiagnosticsVirtualTextWarning Comment
hi link LspDiagnosticsVirtualTextInformation Comment
hi link LspDiagnosticsVirtualTextHint Comment
lua <<EOF
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
-- Enable virtual text, override spacing to 4
virtual_text = {
prefix = 'ᐊ',
},
}
)
EOF
" In vim the wildmenu is displayed horizontally, with left and right choosing
" files and up and down descending or ascending the directory hierarchy. In
" neovim it's displayed vertically instead, but the keybindings aren't changed
" accordingly. Fix them.
cnoremap <expr> <Down> wildmenumode() ? "\<Right>" : "\<Down>"
cnoremap <expr> <Right> wildmenumode() ? "\<Down>" : "\<Right>"
cnoremap <expr> <Up> wildmenumode() ? "\<Left>" : "\<Up>"
cnoremap <expr> <Left> wildmenumode() ? "\<Up>" : "\<Left>"
" Make each <C-u> and <C-w> undoable.
inoremap <C-u> <C-g>u<C-u>
inoremap <C-w> <C-g>u<C-w>