-
Notifications
You must be signed in to change notification settings - Fork 3
/
.vimrc
203 lines (164 loc) · 7.04 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
set nocompatible
filetype plugin indent on
syntax on
set mouse=a
source ~/.vim/colors/neodark.vim
hi Comment cterm=none
inoremap kj <Esc>
set number " enable line numbers
set list " display hidden characters
set listchars=tab:>\ ,trail:-
set shortmess+=I " disable splash screen message
set noshowcmd
set noruler
set laststatus=2
set backspace=indent,eol,start
set expandtab " expand tabs to spaces
set shiftwidth=4 " spaces to shift when re-indenting
set tabstop=4 " number of spaces to insert when tab is pressed
set softtabstop=4 " backspace deletes indent
set smartindent " indent based on filetype
set hlsearch
set incsearch
set showmatch
set ignorecase " for search patterns
set smartcase " don't ignore case if capital is used
set path+=** " recursive filepath completion
set wildignorecase " ignore case in commandline filename completion
set undofile " undo persists after closing file
set undodir=~/.vim/undo//,/tmp
set backup " backup files
set backupdir=~/.vim/backup//,/tmp
set noswapfile
set dir=~/.vim/swap//,/tmp
set splitright " puts new vsplit windows to the right of the current
set splitbelow " puts new split windows to the bottom of the current
set fcs=fold:- " verticle split is just bg color
set foldcolumn=0 " visual representation of folds
set foldmethod=syntax
set foldnestmax=1
set nofoldenable
" disable foldcolumn for diffs
autocmd FilterWritePre * if &diff | set fdc=0 | endif
" disable automatic comment insertion
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" set title for tmux
autocmd WinEnter,BufWinEnter,FocusGained * call system('tmux rename-window ' . expand('%:t'))
set title
set t_ts=]6;
set t_fs=
set titlestring=%{bufname('%')==''?'':'file://'.hostname().expand('%:p:gs/\ /%20/')}
set titlelen=0
" check for and load file changes
autocmd WinEnter,BufWinEnter,FocusGained * checktime
" wrapped line movement mappings (adds larger jumps to jumplist)
nnoremap <expr> j v:count > 5 ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
nnoremap <expr> k v:count > 5 ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
" prevent jump after searching word under cursor with # and *, clear with Escape
nnoremap <silent> # :let @/ = '\<'.expand('<cword>').'\>'\|set hlsearch<CR>w?<CR>
nnoremap <silent> * :let @/ = '\<'.expand('<cword>').'\>'\|set hlsearch<CR>
nnoremap <silent> g# :let @/ = expand('<cword>')\|set hlsearch<CR>w?<CR>
nnoremap <silent> g* :let @/ = expand('<cword>')\|set hlsearch<CR>
autocmd CursorHold * nnoremap <silent> <Esc> :noh<CR><Esc>
" unimpaired quickfix mappings
nnoremap <silent> <leader>q :cw<CR>
nnoremap <silent> [q :cprevious<CR>
nnoremap <silent> ]q :cnext<CR>
nnoremap <silent> [Q :cfirst<CR>
nnoremap <silent> ]Q :clast<CR>
" unimpaired location list mappings
nnoremap <silent> <leader>l :cw<CR> :lw<CR>
nnoremap <silent> [l :lprevious<CR>zmzv
nnoremap <silent> ]l :lnext<CR>zmzv
nnoremap <silent> [L :lfirst<CR>
nnoremap <silent> ]L :llast<CR>
" unimpaired buffer mappings
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :blast<CR>
" accordion expand traversal of folds
nnoremap <silent> z] :<C-u>silent! normal! zc<CR>zjzozz
nnoremap <silent> z[ :<C-u>silent! normal! zc<CR>zkzo[zzz
" insert closing curly brace
"inoremap {<CR> {<CR>}<Esc>O
inoremap <expr> {<Enter> <SID>CloseBracket()
" substitution mappings
nnoremap <leader>; :%s/;$/ {}
xnoremap <leader>; :s/;$/ {}
nnoremap <leader><Space> :%s/\s\+$//e<CR>
nnoremap <leader>s :%s///g<Left><Left>
xnoremap <leader>s :s///g<Left><Left>
" dot command works on ranges
xnoremap . :normal .<CR>
" relative number configuration
autocmd FocusLost,InsertEnter,WinLeave * if &ma && &ft !~ 'markdown\|text' && &bt != 'nofile' | :setl nornu | endif
autocmd FocusGained,InsertLeave,WinEnter,BufRead * if &ma && &ft !~ 'markdown\|text' && &bt != 'nofile' | :setl nu rnu | endif
" cursorline configuration
autocmd FocusLost,InsertEnter,WinLeave,BufWinLeave,CmdwinLeave * setl nocul
autocmd FocusGained,InsertLeave,WinEnter,BufWinEnter,CmdwinEnter * setl cul
" netrw filebrowser config
let g:netrw_winsize = -28 " absolute width of netrw window
let g:netrw_banner = 0 " do not display info on the top of window
let g:netrw_liststyle = 3 " tree-view
let g:netrw_sort_sequence = '[\/]$,*' " sort so directories on the top, files below
let g:netrw_browse_split = 4 " use the previous window to open file
let g:netrw_hide = 1 " don't show hidden files (use gh to toggle)
let g:netrw_list_hide='^\.,\.dSYM/'
nnoremap <silent> <Leader>\ :call ToggleNetrw()<CR>
cabbrev cd. <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'lcd %:p:h\|pwd' : 'cd.')<CR>
let g:netrw_is_open=0
function! ToggleNetrw()
if g:netrw_is_open
let i = bufnr("$")
while (i >= 1)
if (getbufvar(i, "&filetype") == "netrw")
silent exe "bwipeout " . i
endif
let i-=1
endwhile
let g:netrw_is_open=0
else
let g:netrw_is_open=1
silent Lexplore
endif
endfunction
" jump to the previous cursor position in the file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
if executable('rg') | set gp=rg\ -S\ --vimgrep\ --no-heading gfm=%f:%l:%c:%m,%f:%l%m,%f\ \ %l%m|
elseif executable('ag') | set gp=ag\ --nogroup\ --nocolor | endif
com! -nargs=+ -complete=file -bar Rg sil! gr! <args>|cw|redr!|let @/="<args>"|set hls
com! -nargs=+ -complete=file -bar Ag sil! gr! <args>|cw|redr!|let @/="<args>"|set hls
" grep for word under cursor
nmap <Leader># #:sil! gr! "\b<C-R><C-W>\b"<CR>:cw<CR>:redr!<CR>
nmap <Leader>* #:sil! gr! "\b<C-R><C-W>\b"<CR>:cw<CR>:redr!<CR>
" MRU command-line completion
function! s:MRUComplete(ArgLead, CmdLine, CursorPos)
return filter(map(copy(v:oldfiles), 'fnamemodify(v:val, ":~:.")'), 'v:val =~ a:ArgLead')
endfunction
" browse most recently opened files with :O or :o
command! -nargs=? -complete=customlist,<sid>MRUComplete O if empty("<args>") | :browse oldfiles | else | :e <args> | endif
cabbrev o <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'O' : 'o')<CR>
" fuzzy command mappings
cabbrev vf <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'vert sf' : 'vf')<CR>
cabbrev vsf <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'vert sf' : 'vsf')<CR>
cabbrev ef <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'fin' : 'ef')<CR>
" enable omnicompletion
set tags+=~/.config/nvim/systags
autocmd Filetype * if &omnifunc == '' | setlocal omnifunc=syntaxcomplete#Complete | endif
autocmd Filetype java setlocal omnifunc=javacomplete#Complete
function! s:CloseBracket()
let line = getline('.')
if line =~# '^\s*\(struct\|class\|enum\) '
return "{\<Enter>};\<Esc>O"
elseif searchpair('(', '', ')', 'bmn', '', line('.'))
" Probably inside a function call. Close it off.
return "{\<Enter>});\<Esc>O"
else
return "{\<Enter>}\<Esc>O"
endif
endfunction
" diff config
"set diffopt+=iwhite "ignore whitespace