-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimrc
More file actions
442 lines (379 loc) · 12.4 KB
/
vimrc
File metadata and controls
442 lines (379 loc) · 12.4 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
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
set nocompatible
set history=10000 " Lines of command history to remember
set tabstop=4 " Show tabs as n spaces
set softtabstop=4 " Number of spaces to insert with TAB or delete with BS
set expandtab " Insert n spaces instead tab
set shiftwidth=4 " Indent size for normal mode commands
set autoindent " Copy indent from current line to new line
set smartindent
set clipboard+=unnamedplus
set termguicolors " For colorschemes
filetype on
filetype plugin on
filetype indent on " Load file-specific indent files
" Makes plugins more snappy
set updatetime=750
" Dirs to store .swp files and backups
" Double slash protects from filename conflicts
set directory=~/.vim/tmp//,/var/tmp//,/tmp//
set backupdir=~/.vim/tmp//,/var/tmp//,/tmp//
" Persistent undo
let s:undoDir = "/tmp/.undodir_" . $USER
if !isdirectory(s:undoDir)
call mkdir(s:undoDir, "", 0700)
endif
let &undodir=s:undoDir
set undofile
" Indent 'case' and 'default' statements according to the PHP style guide
" Commented due to https://github.com/2072/PHP-Indenting-for-VIm/issues/58
" let g:PHP_vintage_case_default_indent = 1
"====
" UI
"====
syntax on " Syntax highlighting
set ruler " Show cursor position in bottom right corner
set wrap " Wrap lines
set scrolloff=3 " Number of context lines visible above or below cursor
set sidescrolloff=3 " Number of context rows visible to the left of right of the cursor
set showcmd " Show command in bottom bar
set showtabline=2 " Always show tab bar at the top
set laststatus=2 " Always show status line at the bottom
set showmatch " Highlight matching parenthesis
set wildmenu " Visual autocomplete for commands
set wildmode=longest:full,full
set lazyredraw " Redraw only when we need to
set shortmess+=I " Don't display intro message
set mouse=a " Enables mouse interaction in all modes
set breakindent " Preserve indentation for wrapped lines
" Fix slow O inserts
set timeout timeoutlen=1000 ttimeoutlen=100
" Absolute line numbers for insert mode and unfocused buffers
" Relative line numbers for normal mode
" Do not enable line numbers inside utility buffers
set number relativenumber
function! CheckBufferType()
if !exists("b:NERDTree") && !exists("b:tagbar_mapped_keys") && &filetype != "help"
return 1
else
return 0
endif
endfunction
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * if CheckBufferType() | set relativenumber | endif
autocmd BufLeave,FocusLost,InsertEnter * if CheckBufferType() | set norelativenumber | endif
augroup END
" Draw crosshair on the cursor position in the current window
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline cursorcolumn
au WinLeave * setlocal nocursorline nocursorcolumn
augroup END
" Remember last cursor position when opening a file
" Don't do it for commit messages
if has("autocmd")
au BufReadPost * if &ft != 'gitcommit' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
"========
" SPLITS
"========
"Open new split panels to right and bottom
set splitbelow
set splitright
" Navigating between splits with Ctrl+hjkl
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Resize splits with Shift+arrows
" Up increases current buffer height
" Down decreases current buffer height
nnoremap <silent> <S-Up> :resize +3<CR>
nnoremap <silent> <S-Down> :resize -3<CR>
" Right increases current buffer width
" Left decreases current buffer width
nnoremap <silent> <S-Right> :vertical resize +5<CR>
nnoremap <silent> <S-Left> :vertical resize -5<CR>
"===========
" SHORTCUTS
"===========
" Space inserts default leader
" Useful because if shows leader symbol in command line
map <Space> <Leader>
" Disable Ex mode
nmap Q <silent>
" Disable command history window
nmap q: <silent>
" Faster scrolling
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" Exit from terminal mode with ESC
" Check for fzf search window
tnoremap <expr> <Esc> (&filetype == "fzf") ? "<Esc>" : "<c-\><c-n>"
" fzf - open files tracked by git
nnoremap <C-p> :GFiles<CR>
" Open files
nnoremap <M-p> :Files<CR>
" Grepper - search word under cursor
nnoremap <leader>* :Grepper -tool ag -cword -noprompt<cr>
" Start search with ag
nnoremap <leader>/ :Grepper -tool ag<cr>
" pdv document
autocmd FileType php nnoremap <leader>d :call pdv#DocumentCurrentLine()<CR>
" Toggle gitgutter
nnoremap <leader>g :GitGutterToggle<CR>
" Toggle auto-indenting for code paste in normal mode
nnoremap <F2> :set invpaste paste?<CR>
" and in insert mode
set pastetoggle=<F3>
" Stop highlighting searches
nmap <leader>h :nohl<CR>
" Open same file in new tab
nmap <leader>t :tab split<CR>
" Open same file in new tab in last position
nmap <leader>T :tab split<CR>:tabm<CR>
" Use plus and minus to increment/decrement numbers
noremap + <C-a>
noremap - <C-x>
" Preserve visual selection when indenting with < and >
vnoremap < <gv
vnoremap > >gv
" Moving line up and down with Ctrl+up/down, autoindent both swapped lines
nmap <C-Up> ddkP==j==k==
nmap <C-Down> ddp==k==j==
" Up and Down navigate inside long lines
" Left and Right scroll window, keeping cursor
" in the same line on screen
" No arrow keys in insert and visual
noremap <Up> gk
noremap <Down> gj
noremap <Left> 3<C-y>3gk
noremap <Right> 3<C-e>3gj
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
vnoremap <Up> <NOP>
vnoremap <Down> <NOP>
vnoremap <Left> <NOP>
vnoremap <Right> <NOP>
" Repeat last command in the last tmux pane.
nnoremap <Leader>r :call <SID>TmuxRepeat()<CR>
function! s:TmuxRepeat()
silent! write
silent! exec "!tmux select-pane -l && tmux send up enter && tmux select-pane -l"
redraw!
endfunction
" Mapping cyrillic layout for normal mode
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯЖ;ABCDEFGHIJKLMNOPQRSTUVWXYZ:,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
"========
" SEARCH
"========
set incsearch " Start searching as you type
set hlsearch " Highlight search patterns
" Automatically ignore case for lowercase searches,
" case-sensitive for searches with uppercase letters
set ignorecase
set smartcase
" Stops ignorecase from affecting completion
" Makes completion case-sensitive again
set infercase
"===================
" SPELLING MISTAKES
"===================
abbr feild field
abbr docuemnt document
abbr arrya array
abbr flase false
"============
" STATUSLINE
"============
" TODO: add read-only marker
set statusline=
set statusline+=\ %<%f\ (%{&ft}) " filename, filetype
set statusline+=\ %-4(%m%) " modified flag
set statusline+=%=%-19(%3l,%02c%03V%)%P " ruler
"======================
" INVISIBLE CHARACTERS
"======================
" Toggle invisible characters
nmap <silent> <leader>l :set list!<CR>
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" Invisible character colors
highlight NonText cterm=none ctermfg=0 guifg=#cb4b16
" highlight CursorLineNr cterm=none ctermfg=0 guifg=#b58900
" highlight SpecialKey cterm=none ctermfg=0 guifg=#b58900 ctermbg=8 guibg=#b58900
" Highlight trailing whitespaces, but not while
" typing in insert mode
highlight ExtraWhitespace ctermbg=red guibg=red
au ColorScheme * highlight ExtraWhitespace guibg=red
au BufEnter * match ExtraWhitespace /\s\+$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhiteSpace /\s\+$/
"=========
" PLUGINS
"=========
" VimPlug
call plug#begin('~/.local/share/nvim/plugged')
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-sleuth'
Plug 'w0rp/ale'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'mhinz/vim-grepper'
Plug 'jiangmiao/auto-pairs'
Plug 'kovisoft/slimv', { 'for': 'lisp' }
Plug 'docunext/closetag.vim'
Plug 'vimwiki/vimwiki'
Plug 'vim-vdebug/vdebug', { 'on': 'VdebugStart' }
Plug 'chrisbra/Colorizer'
Plug 'christoomey/vim-tmux-navigator'
" JS, web
Plug 'pangloss/vim-javascript'
Plug 'mattn/emmet-vim', { 'for': ['php', 'html'] }
" Git
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'airblade/vim-gitgutter'
" Clojure
Plug 'tpope/vim-fireplace'
Plug 'vim-scripts/paredit.vim', { 'for': ['clojure', 'scheme'] }
" PHP
Plug 'tobyS/vmustache'
Plug 'tobyS/pdv', { 'for': 'php' }
" Solidity
" Plug 'tomlion/vim-solidity'
" Colorschemes
Plug 'lifepillar/vim-solarized8'
Plug 'ajh17/Spacegray.vim'
Plug 'morhetz/gruvbox'
call plug#end()
" Disable ALE for now
autocmd VimEnter * if exists('g:loaded_ale') | ALEDisable | endif
" Toggle ALE
nmap <leader>al :ALEToggle<CR>
" Emmet
let g:user_emmet_leader_key='<C-x>'
let g:user_emmet_settings = {
\ 'javascript.jsx' : {
\ 'extends' : 'jsx',
\ },
\}
" Grepper - search in hidden files
runtime plugin/grepper.vim
let g:grepper.ag.grepprg .= ' --hidden --ignore .git'
" Enable deoplete
let g:deoplete#enable_at_startup = 1
" Open REPL in vertical right split
let g:slimv_repl_split=4
" Speeding up the SWANK server
let g:swank_block_size=65536
" Rainbow parens
let g:lisp_rainbow=1
" Run clojure tests from any buffer with cpt
function! RunBufferTests()
" save current file
silent! write
let ns = fireplace#ns()
if ns !~ '-test$'
let ns = ns . "-test"
endif
silent :Require
exe "RunTests " . ns
endfunction
autocmd FileType clojure nmap <buffer> cpt :call RunBufferTests()<cr>
" Skips autopairs init for lisp files
" since paredit already does that
au FileType lisp,clojure,scheme let b:autopairs_loaded=1
" Disable toggle shortcut
let g:AutoPairsShortcutToggle = ''
" Eval outermost form for clojure
autocmd FileType clojure nmap <buffer> cpP :Eval<cr>
" Don't center screen on the current line
" when auto-pairs inserts indented lines
let g:AutoPairsCenterLine=0
" Don't insert padding spaces inside pairs { | }
let g:AutoPairsMapSpace=0
" Custom comment style
autocmd FileType php,c setlocal commentstring=//\ %s
" Open NERDTree
nmap <leader>nt :NERDTreeToggle<CR>
" Close vim when NERDTree is the only window
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Open file and folders with l, ranger-style
let NERDTreeMapActivateNode='l'
" Show hidden files (toggled with I)
let NERDTreeShowHidden=1
" Open Tagbar
nmap <leader>tb :TagbarToggle<CR>
" Hide line numbers
let g:tagbar_show_linenumbers=0
" Smaller fzf window
let g:fzf_layout = { 'down': '~20%' }
" Hide fzf buffer statusline
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" pdv templates
let g:pdv_template_dir = $HOME . "/.local/share/nvim/plugged/pdv/templates"
" Stop gitgutter from injecting shortcuts
let g:gitgutter_map_keys = 0
" gitgutter colors
highlight link GitGutterAdd String
highlight link GitGutterChange Type
highlight link GitGutterDelete Function
highlight link GitGutterChangeDelete Function
" Css colors
let g:colorizer_auto_filetype='css,html'
" Use markdown in vimwiki
let g:vimwiki_list = [{'path': '~/vimwiki/', 'syntax': 'markdown', 'ext': '.md'}]
" Turn off creation of temporary wikis for all .md files
let g:vimwiki_global_ext = 0
" javascript plugin keeps adding $ to the keyword list in php files
augroup phpjsfix
autocmd!
autocmd FileType javascript setlocal iskeyword+=$
autocmd FileType php setlocal iskeyword-=$
augroup END
"==================================================================
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
" by garybernhardt
"==================================================================
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-n>"
endif
endfunction
inoremap <expr> <tab> InsertTabWrapper()
inoremap <s-tab> <c-p>
"=============
" Colorscheme
"=============
try
set background=dark
let g:gruvbox_bold=1
let g:gruvbox_italic=1
let g:gruvbox_underline=1
let g:gruvbox_undercurl=1
let g:gruvbox_italicize_comments=1
let g:gruvbox_invert_selection=0
colorscheme gruvbox
catch
colorscheme desert
endtry
"=====================
" Local configuration
"=====================
if filereadable($HOME . "/.vimrc.local")
source ~/.vimrc.local
endif