-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
434 lines (353 loc) · 8.77 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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
"Basic settings
syntax enable
filetype plugin on
filetype indent on
" Let's save undo info!
if !isdirectory($HOME."/.vim")
call mkdir($HOME."/.vim", "", 0770)
endif
if !isdirectory($HOME."/.vim/undo-dir")
call mkdir($HOME."/.vim/undo-dir", "", 0700)
endif
set undodir=~/.vim/undo-dir
set undofile
set undolevels=1000
set autoread
set hidden
set encoding=utf-8
set ttyfast
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set fileencoding=utf-8
set iskeyword+=-
set mouse=a
set splitbelow
set splitright
set conceallevel=0
set nobackup
set nowritebackup
set noswapfile
set timeoutlen=500
set formatoptions-=cro
set clipboard=unnamedplus
set wildmenu
set history=1000
set ignorecase
set smartcase
set incsearch
set nohlsearch
set lazyredraw
set magic
set showmatch
set title
set mat=2
set foldcolumn=1
set showcmd
set noshowmode
set foldmethod=manual
" Text, tab and indent related
set smarttab
set expandtab
set smartindent
set autoindent
set nowrap
set tabstop=4
set shiftwidth=4
set lbr
set tw=500
" no annoying sound on errors
set noerrorbells
set visualbell
set t_vb=
set tm=500
" Interface
set so=5
set ruler
set cmdheight=2
set background=dark
set relativenumber
set t_Co=256
set number
set background=dark
" tabline
set showtabline=2
set tabline="%1T"
" Always show the status line
set laststatus=2
" Format the status line
set statusline=
set statusline+=%4*
set statusline+=\\|
set statusline+=%n
set statusline+=\\|
set statusline+=%3*
set statusline+=\\|
set statusline+=%{toupper(g:currentmode[mode()])}
set statusline+=\\|
set statusline+=%1*
set statusline+=\ %{b:gitbranch}
set statusline+=%7*
set statusline+=\ >>
set statusline+=%2*
set statusline+=\ %F\ %{ReadOnly()}
set statusline+=%1*
set statusline+=%m\ %w
set statusline+=%#warningmsg#
set statusline+=%=
set statusline+=%6*
set statusline+=%y
set statusline+=%9*
set statusline+=\\|
set statusline+=Line:
set statusline+=%l
set statusline+=/
set statusline+=%L
set statusline+=\ %P
set statusline+=\\|
set statusline+=%8*\ %-3(%{FileSize()}%)
set wildmode=longest,list,full
set wildoptions=pum
set wildmenu
set wildignore+=*.pyc
set wildignore+=*_build/*
set wildignore+=**/coverage/*
set wildignore+=**/node_modules/*
set wildignore+=**/android/*
set wildignore+=**/ios/*
set wildignore+=**/.git/*
cnoreabbrev W! w!
cnoreabbrev W1 w!
cnoreabbrev w1 w!
cnoreabbrev Q! q!
cnoreabbrev Q1 q!
cnoreabbrev q1 q!
cnoreabbrev Qa! qa!
cnoreabbrev Qall! qall!
cnoreabbrev Wa wa
cnoreabbrev Wq wq
cnoreabbrev wQ wq
cnoreabbrev WQ wq
cnoreabbrev wq1 wq!
cnoreabbrev Wq1 wq!
cnoreabbrev wQ1 wq!
cnoreabbrev WQ1 wq!
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev Qa qa
cnoreabbrev Qall qall
" Highlighing colors
hi User8 ctermbg=black ctermfg=magenta guibg=black guifg=magenta
hi User6 ctermbg=black ctermfg=darkblue guibg=magenta guifg=darkblue
hi User7 ctermbg=black ctermfg=blue guibg=black guifg=blue
hi User2 ctermbg=black ctermfg=red guibg=black guifg=red
hi User1 ctermbg=black ctermfg=yellow guibg=black guifg=yellow
hi User3 ctermbg=yellow ctermfg=red guibg=yellow guifg=red
hi User4 ctermbg=black ctermfg=white guibg=black guifg=white
hi User9 ctermbg=black ctermfg=green guibg=black guifg=green
" Functions for Statusline
let g:currentmode={
\ 'n' : 'N',
\ 'no' : 'N·Operator Pending',
\ 'v' : 'V',
\ 'V' : 'V·Line',
\ '' : 'V·Block',
\ 's' : 'Select',
\ 'S' : 'S·Line',
\ '' : 'S·Block',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'Rv' : 'V·Replace',
\ 'c' : 'Command',
\ 'cv' : 'Vim Ex',
\ 'ce' : 'Ex',
\ 'r' : 'Prompt',
\ 'rm' : 'More',
\ 'r?' : 'Confirm',
\ '!' : 'Shell',
\ 't' : 'Terminal'
\}
augroup GetGitBranch
autocmd!
autocmd VimEnter,WinEnter,BufEnter * call StatuslineGitBranch()
augroup END
"Key Mappings
"leader key
let g:mapleader = "\<Space>"
" Remap VIM 0 to first non-blank character
map 0 ^
" Alternate way to save
nnoremap <C-s> :w<CR>
" Alternate way to quit
nnoremap <C-q> :wq!<CR>
" Select all
nnoremap <C-a> ggVG
" Undo
inoremap <C-z> <C-O>u
" I hate escape more than anything else
inoremap jk <Esc>
inoremap kj <Esc>
inoremap jj <Esc>
" go to the beginning and end in insert mode
inoremap <A-b> <ESC>^i
inoremap <A-e> <End>
" navigate within insert mode
inoremap <C-h> <Left>
inoremap <C-l> <Right>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
" new file
nnoremap <leader>of <cmd>enew<cr>
" Insert empty line in insert mode
inoremap <A-o> <C-O>o
inoremap <A-O> <C-O>O
" Paste without yanking
vnoremap p "_dp
" Copy and Paste
nnoremap ]p o<esc>p
nnoremap [P o<esc>P
inoremap <C-v> <esc>po
" Move a line of text using ALT+[jk]
nnoremap <A-j> <cmd>m .+1<cr>==
nnoremap <A-k> <cmd>m .-2<cr>==
vnoremap <A-j> :m '>+1<cr>gv=gv
vnoremap <A-k> :m '<-2<cr>gv=gv
inoremap <A-j> <esc><cmd>m .+1<cr>==gi
inoremap <A-k> <esc><cmd>m .-2<cr>==gi
" Search word under cursor
nnoremap gw *N
" Better window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Move windows with shift-arrows
nnoremap <S-Left> <C-w><S-h>
nnoremap <S-Right> <C-w><S-j>
nnoremap <S-Up> <C-w><S-k>
nnoremap <S-Down> <C-w><S-l>
"Close the current buffer
nnoremap <leader>bd :bdelete<cr>
" Switch to other buffer
nnoremap <leader>bb :e #<cr>
" Switch buffer
nnoremap ]b :bnext<cr>
nnoremap [b :bprevious<cr>
nnoremap <Tab> :bprevious<cr>
nnoremap <A-Tab> :bnext<cr>
" Use ctrl + arrows to resize windows
nnoremap <C-Up> :resize -2<CR>
nnoremap <C-Down> :resize +2<CR>
nnoremap <C-Left> :vertical resize -2<CR>
nnoremap <C-Right> :vertical resize +2<CR>
" useful mappings for managing tabs
map <leader><tab><tab> :tabnew<cr>
map <leader><tab>f :tabfirst<cr>
map <leader><tab>c :tabclose<cr>
map <leader><tab>m :tabmove<cr>
map <leader><tab>p :tabprevious<cr>
map <leader><tab>n :tabnext<cr>
" Open a new tab with the current buffer path
map <leader>te :tabedit <C-r>=expand("%:p:h")<cr>/
"Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Nitpicky stuff
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap J mzJ'z"
nnoremap g, g,zvzz
nnoremap g; g;zvzz
" Scrolling
nnoremap <C-d> <C-d>zz
nnoremap <C-u> <C-u>zz
" add undo break-points
inoremap , ,<c-g>u
inoremap . .<c-g>u
inoremap ; ;<c-g>u
inoremap ? ?<c-g>u
" Better tabbing
vnoremap < <gv
vnoremap > >gv
" For moving quickly up and down,
" Goes to the first line above/below that isn't whitespace
" Thanks to: http://vi.stackexchange.com/a/213
nnoremap <silent> gj :let _=&lazyredraw<CR>:set lazyredraw<CR>/\%<C-R>=virtcol(".")<CR>v\S<CR>:nohl<CR>:let &lazyredraw=_<CR>
nnoremap <silent> gk :let _=&lazyredraw<CR>:set lazyredraw<CR>?\%<C-R>=virtcol(".")<CR>v\S<CR>:nohl<CR>:let &lazyredraw=_<CR>
" Helpful delete/change into blackhole buffer
nmap <leader>d "_d
nmap <leader>c "_c
nmap <leader>d "_d
nmap <leader>c "_c
nmap H _
nmap L $
" Auto Commands
au! BufWritePost $MYVIMRC source %
au Focusgained,BufEnter * checktime
au BufEnter * set fo-=c fo-=r fo-=o
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g`\"" | endif
" Wayland Support for copy paste
autocmd TextYankPost * if (v:event.operator == 'y' || v:event.operator == 'd') | silent! execute 'call system("wl-copy", @")' | endif
nnoremap p :let @"=substitute(system("wl-paste --no-newline"), '<C-v><C-m>', '', 'g')<cr>p
" Functions
" Find out current buffer's size and output it.
function! FileSize()
let bytes = getfsize(expand('%:p'))
if (bytes >= 1024)
let kbytes = bytes / 1024
endif
if (exists('kbytes') && kbytes >= 1000)
let mbytes = kbytes / 1000
endif
if bytes <= 0
return '0'
endif
if (exists('mbytes'))
return mbytes . 'MB '
elseif (exists('kbytes'))
return kbytes . 'KB '
else
return bytes . 'B '
endif
endfunction
function! ReadOnly()
if &readonly || !&modifiable
return ''
else
return ''
endfunction
function! StatuslineGitBranch()
let b:gitbranch=""
if &modifiable
try
let l:dir=expand('%:p:h')
let l:gitrevparse = system("git -C ".l:dir." rev-parse --abbrev-ref HEAD")
if !v:shell_error
let b:gitbranch="(".substitute(l:gitrevparse, '\n', '', 'g').") "
endif
catch
endtry
endif
endfunction
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Trimming and highlight search
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
autocmd FileType * autocmd BufWritePre <buffer> call TrimWhitespace()
nnoremap <expr> <CR> {-> v:hlsearch ? ":nohl\<CR>" : "\<CR>"}()
" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
endfunction