-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
344 lines (298 loc) · 11.5 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
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
" --------------------------------- General ------------------------------------
filetype plugin indent on
syntax on
set nocompatible " don't behave like vi
set history=1000 " longer history
set hidden " allow buffers to be bg'ed without saving and allows undo when fg'ed
set tabstop=2 " 2 space tabs by default
set softtabstop=2 " 2 space tabs by default
set shiftwidth=2 " 2 space tabs by default
set expandtab " insert spaces when tab is pressed
set smarttab " use shiftwidth when inserting tab
set wrap linebreak " wrap long lines
set backspace=indent,eol,start " make backspace work correctly
set incsearch " perform search as you type
set nojoinspaces " don't join sentences with two spaces
set scrolloff=5 " scroll when 5 lines away from edge of screen
set ignorecase " ignore case when searching...
set smartcase " ...unless a capital letter was typed
set autoread " reload changed files when focus returns
set showcmd " display commands in progress at the bottom
set laststatus=2 " always show statusline
set wildmenu " command tab completion menu
set wildmode=list:longest,full " command tab completion menu options
set completeopt=longest,menuone " popup menu completion options
set tags=tags;/ " Search all directories for tags file
set nobackup " don't save backup files
set nowritebackup " don't save backup files
set noswapfile " don't create .swp files
set foldlevel=99 " open all folds by default
set clipboard=unnamedplus
set encoding=utf-8
set fillchars=fold:-,vert:▏
helptags ALL
" ------------------------------- Statusline -----------------------------------
set statusline=
set statusline+=\ %f " path to file relative to cwd
set statusline+=\ %m " modified flag
set statusline+=%= " right-align
set statusline+=\%y " filetype
set statusline+=\ ·\ %p%% " file percent
set statusline+=\ ·\ %l/%L " line number
set statusline+=\ ·\ %-3c " column number
" ------------------------------ Colorscheme -----------------------------------
colorscheme dmac-snes-dark
set termguicolors " use gui colors in terminal
if exists("+colorcolumn")
set colorcolumn=81
endif
" ------------------------------- Mappings -------------------------------------
let mapleader=","
" treat moving vertically on a wrapped line as two different lines
nnoremap j gj
nnoremap k gk
" underlining
nnoremap <LEADER>= yyp<C-v>$r=
nnoremap <LEADER>- yyp<C-v>$r-
" global custom shortcuts
nnoremap <LEADER>ev :vsplit $MYVIMRC<CR>
nnoremap <LEADER>eg :vsplit $MYGVIMRC<CR>
nnoremap <LEADER>ec :vsplit $DOTFILES/.vim/colors/dmac-snes-dark.vim<CR>
nnoremap <LEADER>sv :source $MYVIMRC<CR>:e<CR>
nnoremap <LEADER>sg :source $MYGVIMRC<CR>:e<CR>
nnoremap <LEADER>f :Files<CR>
nnoremap <LEADER>F :Buffers<CR>
nnoremap <LEADER>tt :NERDTreeToggle<CR>
nnoremap <LEADER>tl :TagbarToggle<CR>
nnoremap <LEADER>TL :TagbarOpen fj<CR>
nnoremap <LEADER>h :set hlsearch!<CR>
nnoremap <LEADER>cd :cd %:p:h<CR>:pwd<CR>
nnoremap <LEADER>S :echo join(reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')),' ')<CR>
nnoremap <LEADER>gb :Git blame -w<CR>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
inoremap <C-a> <Home>
inoremap <C-e> <End>
inoremap <C-b> <Left>
inoremap <C-f> <Right>
" note taking
nnoremap <LEADER>ne :e ~/Dropbox/notes/
nnoremap <LEADER>ns :Ack ~/Dropbox/notes<S-Left><Left>
let g:ackprg = "rg --vimgrep"
" ------------------------------- Autocommands ---------------------------------
" Strip trailing whitespace on save
augroup trailing_whitespace
autocmd!
autocmd BufWritePre * :%s/\s\+$//e
augroup end
" Automatically save changes
augroup autosave
autocmd!
autocmd InsertLeave,TextChanged * if &l:buftype == '' | silent update | endif
augroup end
" Additional filetypes
augroup filetypes
autocmd!
autocmd BufNewFile,BufRead *.h set filetype=c
autocmd BufNewFile,BufRead *.ejs set filetype=html
autocmd BufNewFile,BufRead *.less set filetype=scss
autocmd BufNewFile,BufRead *.tpl set filetype=gotexttmpl
augroup end
" Restore cursor position
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup restore_cursor
autocmd!
autocmd BufReadPost * call ResCur()
augroup end
" Restore cursor position (from defaults.vim)
augroup restore_cursor
autocmd!
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup end
" -------------------------------- OS Config -----------------------------------
if has('win32')
let $PYTHONPATH = "C:\\Python27\\Lib;C:\\Python27\\DLLs;C:\\Python27\\Lib\\lib-tk"
let $CLANG_LIBRARY_PATH="C:\\Program Files (x86)\\LLVM\\bin"
endif
" ----------------------------- Language Options -------------------------------
" -- C/C++ --
let g:clang_library_path = $CLANG_LIBRARY_PATH
let g:clang_complete_macros = 1
let g:clang_complete_auto = 0
let g:clang_sort_algo = "alpha"
let g:clang_jumpto_declaration_key = "gd"
let g:clang_format#auto_format = 0
let g:clang_format#auto_filetypes = ["c", "cpp"]
augroup c
autocmd!
autocmd FileType c,cpp setlocal tabstop=4
autocmd FileType c,cpp setlocal softtabstop=4
autocmd FileType c,cpp setlocal shiftwidth=4
autocmd FileType c,cpp setlocal commentstring=//\ %s
autocmd FileType c,cpp nnoremap <buffer> <LEADER>m :make<CR><CR>:cwindow<CR>
autocmd FileType c,cpp nnoremap <buffer> <LEADER>M :make<CR>
autocmd FileType c,cpp nnoremap <buffer> <LEADER>r :make run<CR>
autocmd FileType c,cpp nnoremap <buffer> <LEADER>g :call SwapHeader()<CR>
autocmd FileType c,cpp nnoremap <buffer> <LEADER>F :ClangFormat<CR>
augroup END
function! SwapHeader()
let base = expand("%:r")
let ext = expand("%:e")
let fname = ""
if ext == "c" || ext == "cpp"
let fname = base.".h"
elseif ext == "h"
let list = glob(base.".c*", 0, 1)
if len(list) > 0
let fname = list[0]
endif
endif
if findfile(fname) != ""
execute "edit" fname
else
if ext == "h"
echom base.".c* not found"
else
echom fname." not found"
endif
endif
endfunction
" -- Go --
let g:go_fmt_autosave = 1
let g:go_fmt_command = "gopls"
let g:go_gopls_local = "liftoff/"
let g:go_gopls_gofumpt = 1
let g:go_search_bin_path_first = 0
let g:go_highlight_diagnostic_errors = 0
let g:go_highlight_diagnostic_warnings = 0
augroup go
autocmd!
autocmd FileType go setlocal tabstop=8
autocmd FileType go setlocal softtabstop=8
autocmd FileType go setlocal shiftwidth=8
autocmd FileType go nnoremap <buffer> <LEADER>m :GoInstall<CR>
autocmd FileType go nnoremap <buffer> <LEADER>v :GoVet<CR>
autocmd FileType go nnoremap <buffer> <LEADER>d :GoDoc<CR>
autocmd FileType go nnoremap <buffer> <LEADER>i :GoInfo<CR>
autocmd FileType go nnoremap <buffer> <LEADER>r :GoRun<CR>
autocmd FileType go nnoremap <buffer> <LEADER>t :GoTest<CR>
augroup END
" -- Clojure --
let g:cljfmt_on_save = 1
let g:clojure_align_multiline_strings = 0
let g:clojure_fuzzy_indent = 1
let g:clojure_fuzzy_indent_patterns = "with.*,def.*,let.*,send.*"
let g:clojure_fuzzy_indent_patterns .= ",GET,POST,PUT,PATCH,DELETE,context" " Compojure
let g:clojure_fuzzy_indent_patterns .= ",clone-for" " Enlive
let g:clojure_fuzzy_indent_patterns .= ",select,insert,update,delete,with.*" " Korma
let g:clojure_fuzzy_indent_patterns .= ",fact,facts" " Midje
let g:clojure_fuzzy_indent_patterns .= ",up,down,table" " Lobos
let g:clojure_fuzzy_indent_patterns .= ",entity" " Custom
augroup clojure
autocmd!
autocmd FileType clojure nnoremap <buffer> <LEADER>e :%Eval<CR>
autocmd FileType clojure nnoremap <buffer> <LEADER>E :Eval<CR>
autocmd FileType clojure setlocal omnifunc=fireplace#omnicomplete
augroup END
" -- Python --
augroup python
autocmd!
autocmd FileType python setlocal tabstop=4
autocmd FileType python setlocal softtabstop=4
autocmd FileType python setlocal shiftwidth=4
augroup END
" -- Markdown --
let g:vim_markdown_conceal = 1
augroup markdown
autocmd!
autocmd FileType markdown setlocal tabstop=4
autocmd FileType markdown setlocal softtabstop=4
autocmd FileType markdown setlocal shiftwidth=4
autocmd FileType markdown setlocal textwidth=80
autocmd FileType markdown nnoremap <buffer> <LEADER>m :%w ! markdownd -s<CR><CR>
augroup END
" -- Rust --
augroup rust
autocmd!
autocmd FileType rust nnoremap <buffer> <LEADER>r :!cargo run<CR>
augroup END
" -- ASM --
augroup asm
autocmd!
autocmd FileType asm setlocal commentstring=\;\ %s
augroup END
" -- Git --
augroup git
autocmd!
autocmd FileType gitcommit setlocal tabstop=8
autocmd FileType gitcommit setlocal softtabstop=8
autocmd FileType gitcommit setlocal shiftwidth=8
autocmd FileType gitcommit setlocal colorcolumn=73
augroup END
" -- Zig --
augroup zig
autocmd!
autocmd FileType zig nnoremap <buffer> <LEADER>m :compiler zig_build_exe<CR>:make<CR>
autocmd FileType zig nnoremap <buffer> <LEADER>r :!zig run %<CR>
augroup END
" ------------------------------ Plugin Options --------------------------------
" Disable standard plugin highlighting matching paren.
let g:loaded_matchparen=1
" hexokinase
let g:Hexokinase_highlighters = ['background']
let g:Hexokinase_ftEnabled = ['vim', 'css', 'html', 'javascript']
let g:Hexokinase_optInPatterns = ['full_hex', 'triple_hex', 'rgb', 'rgba', 'hsl', 'hsla', 'colour_names']
" tagbar
let g:tagbar_iconchars = ['▸', '▾']
" fzf
" Rerun ripgrep search for every query change.
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
" match colorscheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" vim-lsc
let g:lsc_server_commands = {'zig': 'zls'}
let g:lsc_enable_autocomplete = v:false
let g:lsc_auto_map = {
\ 'defaults': v:true,
\ 'GoToDefinition': 'gd',
\ 'Completion': 'omnifunc'
\}
" MacVim has a bug which causes it to have an incorrect $PATH when running commands like ctags or ruby gems.
" To fix it, run `sudo mv /etc/zshenv /etc/zprofile` and initialize rbenv and your PATH in ~/.zprofile.
" See https://github.com/b4winckler/macvim/wiki/Troubleshooting
" http://vim.1045645.n5.nabble.com/MacVim-and-PATH-td3388705.html
" https://gist.github.com/2193743