forked from kyau/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
432 lines (377 loc) · 14.4 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
" $KYAULabs: vimrc,v 1.1.2 2021/11/06 23:52:54 kyau Exp $
" General {{{
" ------------------------------------------------------------------------------
set nocompatible " be iMproved, required
filetype off " temporarily disable for Vundle startup
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim' " let Vundle manage itself
Plugin 'gorodinskiy/vim-coloresque' " css/less/sass/html color preview
Plugin 'preservim/nerdtree' " tree explorer
Plugin 'tpope/vim-surround' " quoting/parenthesizing made simple
Plugin 'mattn/emmet-vim' " emmet for vim
call vundle#end()
" Enable Emmet only for html/css
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just
" :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to
" auto-approve removal
filetype indent plugin on " Enable filetype-specific indenting/plugins
set autoread " Auto read when changed from the outside
" }}}
" Colors & Fonts {{{
syntax enable " Enable syntax highlighting
try " Load theme if exists
colorscheme euphrasia
catch
endtry
set background=dark " Set background to dark color scheme
set encoding=utf8 " Set utf-8 as standard encoding
set termencoding=utf8
set fileformats=unix,dos,mac " Use Unix as the standard file type
set formatoptions+=qrn1 " When wrapping paragraphs, don't end lines
" with 1-letter words
set t_Co=256 " Always use 256-color mode
" }}}
" Status Line {{{
" ------------------------------------------------------------------------------
set cmdheight=2 " Use a status bar taht is 2 rows high
set laststatus=2 " Always show the status line
hi User1 ctermfg=3 ctermbg=236
hi User2 ctermfg=1 ctermbg=236
hi User3 ctermfg=14 ctermbg=236
hi User4 ctermfg=10 ctermbg=236
hi User5 ctermfg=1 ctermbg=236 cterm=bold
hi User6 ctermfg=15 ctermbg=236
hi User7 ctermfg=12 ctermbg=236
hi User8 ctermfg=8 ctermbg=236
hi User9 ctermfg=7 ctermbg=236
set statusline=
set statusline+=\ %1*\[%n\] " Buffernumber
set statusline+=\ %3*■%*\ " Symbol
set statusline+=%4*%<%F%* " Full filename & path
set statusline+=%2*%m%* " Modified flag
"set statusline+=%6*\ %{GitBranch()}%*
" Show git branch if applicable
set statusline+=%=%8* " Separation point between aligned items
set statusline+=%9*%{&ff}%* " File format (dos/unix/mac)
set statusline+=%7*/%*%9*%{''.(&fenc!=''?&fenc:&enc).''}
set statusline+=%{(&bomb?\",BOM\":\"\")}
" File encoding
set statusline+=\ %*%3*%y%* " Filetype
set statusline+=%1*\ \ %l%* " Current line
set statusline+=%2*,%1*%c%* " Column number
set statusline+=%2*\ 0x%04B%*\ " Character under cursor
" }}}
" Vim User Interface {{{
" ------------------------------------------------------------------------------
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set clipboard=unnamed " normal OS clipboard interaction
set colorcolumn=81 " Highlight the column after the 80th
set cursorline " Highlight the current line in all windows
" and update on cursor movement
set fillchars+=vert:│
set hidden " Hide buffers when they are abandoned
set hlsearch " Highlight search results
set incsearch " show search matches as you type
set ignorecase " Case-insensitive search
set showbreak=↑\
set listchars=tab:→\ ,eol:¶,nbsp:·,trail:•,extends:≡,precedes:⟨
" Characters to display as invisible chars
" when :list is enabled
set lazyredraw " Don't redraw while executing macros
set magic " For regular expressions, turn magic on
set matchtime=2 " x/10 seconds to show the matching brackets
set number " Turn on line numbering
set ruler " Always show current position
set scrolloff=4 " Keep cursor line at center screen
set showcmd " Show keypresses on right of command line
set showmatch " Show matching bracket when highlighting one
set showmode " Always show current editing mode
set smartcase " When searching be smart about cases
set noerrorbells " Do not ring the bell for error messages
set novisualbell " Do not use visual bells
set formatoptions-=t " don't wrap text when typing
set pastetoggle=<F2> " when in insert mode, press <F2> to go to
" paste mode, where you can paste mass data
" that won't be autoindented
set t_vb= " Null the bell
set timeoutlen=500 " Mapped key sequences timeout after (ms)
"set virtualedit=all " allow the cursor to go in to 'invalid' places
set whichwrap+=<,>,h,l,[,] " Allow horizontal directional keys to wrap
set wildmenu " Turn on the WiLd menu
set wildignore=*.o,*~,*.pyc,*.class,*.bak,*.swp
" Ignore compiled and revision control stuff
" when using WiLd menu
if has("win16") || has("win32")
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
" }}}
" Folding Rules {{{
" ------------------------------------------------------------------------------
set foldenable " enable folding
set foldcolumn=1 " add a fold column
set foldmethod=marker " detect triple-{ style fold markers
set foldlevelstart=0 " start out with everything folded
"set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
function! MyFoldText()
let nblines = v:foldend - v:foldstart + 1
"let nblines = '(lines: ' . nblines. ')'
let nblines = '(' . nblines . ')'
let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0)
let comment = substitute(getline(v:foldstart),"^ *","",1)
let comment = substitute(comment,"^[\"|\#|\;|!] ", "", "")
let comment = substitute(comment," \{\{\{","","")
let expansionString = repeat(" ", w - strwidth(nblines.comment.'"'))
let txt = ' ◇ ' . comment . expansionString . nblines . ' '
return txt
endfunction
set foldtext=MyFoldText()
" }}}
" Backups, History & Undo {{{
" ------------------------------------------------------------------------------
set nobackup " Turn off file backup
set nowritebackup " Turn off backup on overwrite
set history=1000 " Keep 1000 lines of command/search history
set noswapfile " Do not use a swapfile for buffers
set undolevels=1000 " Keep 1000 levels of undo
if v:version > 730
set undofile " Keep a persistent undo backup file
set undodir=~/.vim/.undo,~/tmp/vim,/tmp/vim
endif
" }}}
" Text, Tab & Indent Related {{{
" ------------------------------------------------------------------------------
set autoindent " Auto indent
set copyindent " copy the previous indentation on autoindenting
set expandtab " Use spaces instead of tabs
au FileType Makefile set noexpandtab
au FileType asm set noexpandtab
au FileType crontab set noexpandtab
au FileType bindzone set noexpandtab
au FileType named set noexpandtab
augroup markdown
au!
au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown
augroup END
set smarttab " Be smart when using tabs
set shiftwidth=4 " Number of spaces to use for auto indenting
set softtabstop=4 " Hitting <bs> removes spaces as if tabs
set tabstop=4 " One tab is equal to four spaces
set linebreak " Wrap long lines
set textwidth=79 " Maximum width of text being inserted
set smartindent " Smart indenting when starting a newline
set nowrap " don't wrap lines
" }}}
" Switch to a more POSIX-compatible shell for vim {{{
if &shell =~# 'fish$'
set shell=bash
endif
" }}}
" Common abbreviations / misspellings {{{
source ~/.vim/autocorrect.vim
" }}}
" Keybindings {{{
" ------------------------------------------------------------------------------
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" Map <space> to / (search) and Ctrl+<space> to ? (backwards search)
map <space> /\v
map <c-space> ?\v
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Make the tab key match bracket pairs
nnoremap <tab> %
vnoremap <tab> %
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! %!sudo tee > /dev/null %
" Move a line of text using (ALT/Command)+[jk]
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
if has("mac") || has("macunix")
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif
" Visual mode pressing * or # searches for the current selection
vnoremap <silent> * :call VisualSelection('f', '')<cr>
vnoremap <silent> # :call VisualSelection('b', '')<cr>
" }}}
" Leader Keybindings {{{
" ------------------------------------------------------------------------------
let mapleader = "," " Map <leader> key to ,
let g:mapleader = "," " Allow functions to access <leader> key
" Quick edit ~/.vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" Reload ~/.vimrc
nnoremap <leader>sv :source $MYVIMRC<cr>
" Fast saving
map <leader>w :w!<cr>
" Fast quit
map <leader>q :q!<cr>
" Fast save and quit
map <leader>wq :wq!<cr>
" Reselect the text that was just pasted
map <leader>v V`]
" Toggles paste mode
map <leader>p :setlocal paste!<cr>
" Quickly open a buffer for scribble
map <leader>e :e ~/buffer<cr>
" Insert timestamp
map <leader>dt :r !date +"\%Y-\%m-\%dT\%H:\%M:\%S\%z"<cr>i<bs><esc>
" Insert document header
map <leader>tt i $KYAULabs: <esc>:put =expand('%:t')<cr>i<bs><esc>A,v 1.0.0 <esc>:r !date +"\%Y/\%m/\%d \%H:\%M:\%S "<cr>i<bs><esc>A<esc>:r !echo $USER<cr>i<bs><esc>A Exp $<esc><home>i
" Remove the Windows ^M (for when encodings get messed up)
map <leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Toggle show/hide invisible chars
map <leader>i :set list!<cr>
" Toggle line numbers
map <leader>n :setlocal number!<cr>
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
" Close the current buffer
map <leader>bd :Bclose<cr>
" Close all the buffers
map <leader>ba :1,1000 bd!<cr>
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Toggle spell checking with ,ss
map <leader>ss :setlocal spell!<cr>
" Move to next misspelled word after cursor
map <leader>sn ]s
" Move to previous misspelled word before the cursor
map <leader>sp [s
" Add word under cursor as a good word to spelling file
map <leader>sa zg
map <leader>s? z=
" Useful mappings for managing tabs
map <leader>= :tabnew<cr>
map <leader>- :tabclose<cr>
map <leader>\ :tabonly<cr>
map <leader>1 1gt
map <leader>2 2gt
map <leader>3 3gt
map <leader>4 4gt
map <leader>5 5gt
map <leader>6 6gt
map <leader>7 7gt
map <leader>8 8gt
map <leader>9 9gt
map <leader>0 10gt
" Opens the error console
map <leader>cc :botright cope<cr>
" Move to the next error
map <leader>] :cn<cr>
" Move to the previous error
map <leader>[ :cp<cr>
"
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
" Replace the current word in all open buffers
vnoremap <silent> <leader>r :call VisualSelection('replace', '')<cr>
" Vimgrep after the selected text
vnoremap <silent> gv :call VisualSelection('gv', '')<cr>
" Open vimgrep and put the cursor in the right position
map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>
" Vimgreps in the current file
map <leader><space> :vimgrep // <C-R>%<C-A><right><right><right><right><right><right><right><right><right>
" Convert file to unix unicode utf-8
map <leader>u :set ff=unix<cr>:set fileencoding=utf8<cr>
" Convert ANSI from dos to unix (Just use <C-v><Esc> to input the ^[ character)
map <leader>ansi :set ff=unix<cr>:set fileencoding=utf8<cr>:%s/Ü/▄/g<cr>:%s/²/▓/g<cr>:%s/±/▒/g<cr>:%s/°/░/g<cr>:%s/ß/▀/g<cr>:%s/Û/█/g<cr>:v/./d<cr>,<cr>
" }}}
" Buffers & Tabs {{{
" ------------------------------------------------------------------------------
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" Delete trailing whitespace on save (Python/CoffeeScript)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
autocmd BufWrite *.coffee :call DeleteTrailingWS()
" Fish Syntax Highlighting
autocmd BufNewFile,BufRead *.fish set filetype=fish
autocmd BufNewFile,BufRead,StdinReadPost *
\ if getline(1) =~ '^#!.*\Wfish\s*$' |
\ set ft=fish |
\ endif
au FileType fish setl ts=2 sw=2 noet
" PostgreSQL
let g:sql_type_default = 'pgsql'
" Functions {{{
" ------------------------------------------------------------------------------
func! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunc
func! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
exe "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
exe "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.' . a:extra_filter)
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
exe "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endf
" Don't close window, when deleting a buffer
command! Bclose call <sid>BufcloseCloseIt()
func! <sid>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
exe("bdelete! ".l:currentBufNum)
endif
endfunc
" Git branch on status line
func! GitBranch()
let branch = system("git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* //'")
if branch != ''
return '[git:' . substitute(branch, '\n', '', 'g') . ']'
endif
return ''
endfunc
" }}}