-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
416 lines (335 loc) · 12.6 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
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
" Needed so fish doesn't break vim - https://github.com/dag/vim-fish
if &shell =~# 'fish$'
set shell=sh
endif
" Needed because of this bug: https://github.com/vim/vim/issues/3117
" Can probably be removed later
if has('python3')
silent! python3 1
endif
" runtime bundle/vim-pathogen/autoload/pathogen.vim
" call pathogen#infect()
" vim-plug https://github.com/junegunn/vim-plug
so ~/.vim/plugs.vim
syntax on
" colorscheme desert
" colorscheme solarized
" colorscheme monokai
set background=dark
colorscheme space-vim-dark
filetype on
filetype plugin on
filetype indent on
filetype plugin indent on
" Tabs
set expandtab " Turn tabs into spaces
set tabstop=4 " number of visual spaces per tab
set shiftwidth=4
set softtabstop=4 " number of spaces in a tab when editing
set number
" Some settings from http://stevelosh.com/blog/2010/09/coming-home-to-vim/#using-the-leader
set encoding=utf-8
set wildmenu
set wildmode=full
" Some stuff from http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim
" Scroll 2 lines above/below cursor
set scrolloff=2
set showmode " Show mode in status bar
set ruler " show cursor position in status bar
set laststatus=2 " use 2 lines for the status bar
set matchtime=2 " show matching bracket for 0.2 seconds
set matchpairs+=<:> " specially for html
set esckeys " map missed escape sequences (enables keypad keys)
set viminfo='20,\"500 " remember copy registers after quitting in the .viminfo
" Some stuff from http://www.terminally-incoherent.com/blog/2012/03/26/how-to-configure-vim/
" break compatibility with vi
set nocompatible
" enable inline spellcheck
" set spell
set spelllang=en
" show line and column markers
set cursorline
" set cursorcolumn
set autoindent
" copy previous indent on enter
set copyindent
" set smartindent - disabling per comments in
" http://www.reddit.com/r/vim/comments/26z00g/going_to_start_learning_vim_pretty_overwhelmed/
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set incsearch " incremental search
set hlsearch " highlights searches
" Re-map the leader key from \ to ,
let mapleader = ","
" pressing ,<space> clears the search highlights
nmap <silent> <leader><space> :nohlsearch<CR>
" for when you mess up and hold shift too long
command W w
command WQ wq
command Wq wq
command Q q
" run a shell command and put the output in a scratch buffer
command! -nargs=* -complete=shellcmd R new | setlocal buftype=nofile bufhidden=hide noswapfile | r !<args>
" save undo/swap/backup files in a central location instead of cluttering up
" the current directory. Unless the tmp dirs aren't writable, then it still
" goes to the current directory.
set backupdir=$HOME/.vim/tmp//,$HOME/tmp//,.
set directory=$HOME/.vim/tmp//,$HOME/tmp//,.
set undodir=$HOME/.vim/tmp//,$HOME/tmp//,.
" save more in undo history
set history=1000
set undolevels=1000
if v:version >= 730
set undofile " keep a persistent backup file
endif
" Load indentation rules according to the detected filetype.
if has("autocmd")
filetype indent on
endif
"http://irssi.org/documentation/tips
"Auto update changed date to todates date
autocmd BufWrite *.pl %s/changed => '.*/\="changed => '" . strftime("%c") . "',"/e
map <C-B> :w !php -l <CR>
" Turn on rainbow parantheses by default
" https://github.com/kien/rainbow_parentheses.vim
if exists('au')
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
endif
" Tagbar
let g:tagbar_usearrows = 1
nnoremap <leader>l :TagbarToggle<CR><C-w><C-w>
" ctrlp for tags
nnoremap <leader>. :CtrlPTag<CR>
" disable arrow keys to learn to use hjkl
" nnoremap <up> <nop>
" nnoremap <down> <nop>
" nnoremap <left> <nop>
" nnoremap <right> <nop>
" inoremap <up> <nop>
" inoremap <down> <nop>
" inoremap <left> <nop>
" inoremap <right> <nop>
" Allowe hidden buffers
set hidden
" Fix backspace when using auto indent and stuff
set backspace=indent,eol,start
" Auto encrypt/decrypt files with .gpg extension. From http://vim.wikia.com/wiki/Encryption
" Transparent editing of gpg encrypted files.
" By Wouter Hanegraaff
augroup encrypted
au!
" First make sure nothing is written to ~/.viminfo while editing
" an encrypted file.
autocmd BufReadPre,FileReadPre *.gpg set viminfo=
" We don't want a various options which write unencrypted data to disk
autocmd BufReadPre,FileReadPre *.gpg set noswapfile noundofile nobackup
" Switch to binary mode to read the encrypted file
autocmd BufReadPre,FileReadPre *.gpg set bin
autocmd BufReadPre,FileReadPre *.gpg let ch_save = &ch|set ch=2
" (If you use tcsh, you may need to alter this line.)
autocmd BufReadPost,FileReadPost *.gpg '[,']!gpg --decrypt 2> /dev/null
" Switch to normal mode for editing
autocmd BufReadPost,FileReadPost *.gpg set nobin
autocmd BufReadPost,FileReadPost *.gpg let &ch = ch_save|unlet ch_save
autocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost " . expand("%:r")
" Convert all text to encrypted text before writing
" (If you use tcsh, you may need to alter this line.)
autocmd BufWritePre,FileWritePre *.gpg '[,']!gpg --default-recipient-self -ae 2>/dev/null
" Undo the encryption so we are back in the normal text, directly
" after the file has been written.
autocmd BufWritePost,FileWritePost *.gpg u
augroup END
" Statusline / airline settings
let g:airline#extensions#tabline#enabled = 1
" Easier split navigations -
" http://robots.thoughtbot.com/vim-splits-move-faster-and-more-naturally
" We can use different key mappings for easy navigation between splits to save
" a keystroke. So instead of ctrl-w then j, it’s just ctrl-j:
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Open new split panes to right and bottom, which feels more natural than
" Vim’s default
set splitbelow
set splitright
" Create vertical split using <leader>w and then switch to it
nnoremap <leader>w <C-w>v<C-w>l
" map jj to ESC to make it easier to leave insert mode
inoremap jj <ESC>
" http://stevelosh.com/blog/2010/09/coming-home-to-vim/#using-the-leader
" Yank one line, paste it below, move to it and replace every character with =
" ie: Create MarkDown headings
nnoremap <leader>= yypVr=
" Use normal regex instead of vim's regex
nnoremap / /\v
vnoremap / /\v
" Use the tab key to move between brackets and paranthesis instead of %
nnoremap <tab> %
vnoremap <tab> %
" Add a color column at 85
" set colorcolumn=85
"set wrap
"set textwidth=79
"set formatoptions=qrn1
" Re-map ; to : in normal-mode
nnoremap ; :
" strip all trailing whitespace in the current file
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Use ack by pressing ,g
nnoremap <leader>g :Ack
" Select text that was just pasted
nnoremap <leader>v V`]
" Toggle paste mode with F2
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
" Open ~/.vimrc in a split window
" ,ev - edit vimrc
" ,sv - reload vimrc
nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
nnoremap <leader>sv :so $MYVIMRC<cr>
" Use <leader>a and n to switch between buffers (similar to my tmux/screen
" config)
map <Leader>a :bprev<Return>
map <Leader>p :bprev<Return>
map <Leader>n :bnext<Return>
map <Leader>d :bd<Return>
map <Leader>D :bw<Return>
map <Leader>f :b
nmap <Leader>bb :ls<CR>:buffer<Space>
" Use <leader>t to toggle nerdtree
map <Leader>t :NERDTreeToggle<Return>
" Format javascript
nmap =j :%!python -m json.tool<CR>
" Format python using yapf (from
" https://github.com/mindriot101/vim-yapf#why-you-may-not-need-this-plugin)
nmap =y :%!yapf<CR>
" From http://www.vimbits.com/bits/153 - TODO: Move to its own file
" Motions to Ack for things. Works with pretty much everything, including: w,
" W, e, E, b, B, t*, f*, i*, a*, and custom text objects.
"
" For example: \aiw will Ack for the word under the cursor. \aib will Ack for
" the contents of the parentheses the cursor is inside.
nnoremap <silent> \a :set opfunc=<SID>AckMotion<CR>g@
xnoremap <silent> \a :<C-U>call <SID>AckMotion(visualmode())<CR>
function! s:CopyMotionForType(type)
if a:type ==# 'v'
silent execute "normal! `<" . a:type . "`>y"
elseif a:type ==# 'char'
silent execute "normal! `[v`]y"
endif
endfunction
function! s:AckMotion(type) abort
let reg_save = @@
call s:CopyMotionForType(a:type)
execute "normal! :Ack! --literal " . shellescape(@@) . "\<cr>"
let @@ = reg_save
endfunction
" Folding stuff
set foldmethod=syntax
set foldnestmax=2
set nofoldenable
nnoremap <Space> za " Toggle current fold open/closed
" Flake8 stuff
let g:flake8_show_in_gutter=1
" https://github.com/othree/javascript-libraries-syntax.vim
let g:used_javascript_libs = 'jquery,angularjs,react'
" Set default font for MacVim
if has('win32')
set guifont=Consolas:h12 " Win32.
elseif has('gui_macvim')
" set guifont=Monaco:h14 " OSX.
" downloaded from https://github.com/ryanoasis/nerd-fonts#option-4-homebrew-fonts
" see also: https://app.programmingfonts.org/#input
set guifont=HackNerdFontComplete-Regular:h14
" set guifont="SauceCodeProNerdFontCompleteM-Regular:h14"
else
set guifont=Monospace\ 12 " Linux.
endif
set wildignore=*.swp,*.bak,*.pyc,*.class,tags
set title " Change the title in the terminal
" From http://nvie.com/posts/how-i-boosted-my-vim/ - use w!! to write
" something as root
cmap w!! w !sudo tee % >/dev/null
let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp' " Persist ctrlp cache to disk
" Check if ag (the_silver_searcher) is installed
if executable('ag')
" If ag is installed, use it for ctrlp instead of the built in search
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" Also use it for ack.vim due to https://github.com/rking/ag.vim/issues/124#issuecomment-227038003
let g:ackprg = 'ag --vimgrep --smart-case'
cnoreabbrev ag Ack
cnoreabbrev Ag Ack
endif
" For chef berkshelf
autocmd BufNewFile,BufRead Gemfile set filetype=ruby
autocmd BufNewFile,BufRead Berksfile set filetype=ruby
" Syntastic settings
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_ruby_checkers = [ 'rubocop' ]
" Hide Info window after completions
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" For ledger
au BufNewFile,BufRead *.ldg,*.ledger setf ledger | comp ledger
let g:ledger_maxwidth = 120
let g:ledger_fold_blanks = 1
function LedgerSort()
:%! ledger -f - print --sort 'date, amount'
:%LedgerAlign
endfunction
command LedgerSort call LedgerSort()
" Ultisnips
let g:UltiSnipsExpandTrigger="<NUL>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<S-tab>"
let g:UltiSnipsListSnippets="<c-k>" "List possible snippets based on current file
" https://github.com/SirVer/ultisnips/issues/376 - get YCM and Ultisnips to work together
let g:ulti_expand_or_jump_res = 0
function! <SID>ExpandSnippetOrReturn()
let snippet = UltiSnips#ExpandSnippetOrJump()
if g:ulti_expand_or_jump_res > 0
return snippet
else
return "\<CR>"
endif
endfunction
inoremap <expr> <CR> pumvisible() ? "<C-R>=<SID>ExpandSnippetOrReturn()<CR>" : "\<CR>"
" YouCompleteMe YCM
let g:ycm_key_list_select_completion=["<tab>"]
let g:ycm_key_list_previous_completion=["<S-tab>"]
let g:ycm_collect_identifiers_from_tags_files = 1 " Let YCM read tags from Ctags file
let g:ycm_use_ultisnips_completer = 1 " Default 1, just ensure
let g:ycm_seed_identifiers_with_syntax = 1 " Completion for programming language's keyword
let g:ycm_complete_in_comments = 1 " Completion in comments
let g:ycm_complete_in_strings = 1 " Completion in string
" EditorConfig - https://github.com/editorconfig/editorconfig-vim#readme
let g:EditorConfig_exclude_patterns = ['fugitive://.*', 'scp://.*']
" https://github.com/neoclide/coc.nvim
" set shortmess+=c
" set signcolumn=yes
" let g:airline_section_error = '%{airline#util#wrap(airline#extensions#coc#get_error(),0)}'
" let g:airline_section_warning = '%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}'
" let g:terraform_completion_keys = 1
"
" let g:deoplete#omni_patterns = {}
" call deoplete#custom#option('omni_patterns', {
" \ 'complete_method': 'omnifunc',
" \ 'terraform': '[^ *\t"{=$]\w*',
" \})
" call deoplete#initialize()
let g:vim_json_syntax_conceal = 0
if v:version >= 740
set completeopt=menuone,preview,noinsert
endif