-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
385 lines (330 loc) · 11.1 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
" -----------------------------------------------------------------------------
" This config is targeted for Vim 8.0+ and NO PLUGINS
" -----------------------------------------------------------------------------
set viminfo=
" -----------------------------------------------------------------------------
" Color settings
" -----------------------------------------------------------------------------
" Enable 24-bit true colors if your terminal supports it.
if (has("termguicolors"))
" https://github.com/vim/vim/issues/993#issuecomment-255651605
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
else
set t_Co=256
endif
" Set up the colors.
set background=dark
colorscheme torte
syntax on
filetype on
hi clear LineNr
hi clear SignColumn
hi EndOfBuffer guibg=NONE ctermbg=NONE
hi CursorLine guibg=#202020 cterm=bold ctermbg=Yellow
hi CursorColumn guibg=#202020 cterm=bold ctermbg=Yellow
hi ColorColumn guibg=#303030 cterm=bold ctermbg=Yellow
" -----------------------------------------------------------------------------
" Basic Settings
" Research any of these by running :help <setting>
" -----------------------------------------------------------------------------
let fancy_symbols_enabled=0
let mapleader="\<Space>"
let maplocalleader="\<Space>"
let g:netrw_banner=0
let g:netrw_winsize=25
set autoindent
set autoread
set backspace=indent,eol,start
set clipboard+=unnamedplus
set colorcolumn=80
set complete+=kspell
set completeopt=menuone,longest
set cryptmethod=blowfish2
set cursorcolumn
set cursorline
set directory=/tmp//,.
set encoding=utf-8
set expandtab smarttab
set formatoptions=tcqrn1
set hidden
set history=500
set hlsearch
set ignorecase
set incsearch
set laststatus=2
set matchpairs+=<:> " Use % to jump between pairs
set mmp=5000
set modelines=2
set mouse=a
set nobackup
set nocompatible
set noerrorbells visualbell t_vb=
set noshiftround
set nospell
set nostartofline
set number
set pastetoggle=<f2>
set path+=.,**
set regexpengine=1
set ruler
set scrolloff=3
set shell=/bin/bash
set shiftwidth=2
set showcmd
set showmatch
set shortmess+=c
set showmode
set smartcase
set softtabstop=4
set spelllang=en_us
set splitbelow
set splitright
set tabstop=4
set textwidth=0
set title
set ttimeout
set ttyfast
set ttymouse=sgr
set undodir=/tmp
set undofile
set virtualedit=block
set whichwrap=b,s,<,>
set wildmenu
set wildmode=full
set wrap
runtime! macros/matchit.vim
hi SpellBad cterm=underline ctermfg=9
hi SpellLocal cterm=underline ctermfg=9
hi SpellRare cterm=underline ctermfg=9
hi SpellCap cterm=underline
" -----------------------------------------------------------------------------
" Cursor
" -----------------------------------------------------------------------------
let &t_EI = "\<Esc>[2 q"
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
" reset the cursor on start (for older versions of vim, usually not required)
augroup myCmds
au!
autocmd VimEnter * silent !echo -ne "\e[2 q"
augroup END
" -----------------------------------------------------------------------------
" Basic mappings
" -----------------------------------------------------------------------------
" Seamlessly treat visual lines as actual lines when moving around.
noremap j gj
noremap k gk
noremap <Down> gj
noremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" Navigate around splits with a single key combo.
nnoremap <C-l> <C-w><C-l>
nnoremap <C-h> <C-w><C-h>
nnoremap <C-k> <C-w><C-k>
nnoremap <C-j> <C-w><C-j>
" Cycle through splits.
nnoremap <S-Tab> <C-w>
" Cycle through buffers.
nnoremap <Tab> :bnext<cr>
nnoremap <S-Tab> :bprevious<cr>
" Press * to search for the term under the cursor or a visual selection and
" then press a key below to replace all instances of it in the current file.
nnoremap <Leader>r :%s///g<Left><Left>
nnoremap <Leader>rc :%s///gc<Left><Left><Left>
" The same as above but instead of acting on the whole file it will be
" restricted to the previously visually selected range. You can do that by
" pressing *, visually selecting the range you want it to apply to and then
" press a key below to replace all instances of it in the current selection.
xnoremap <Leader>r :s///g<Left><Left>
xnoremap <Leader>rc :s///gc<Left><Left><Left>
" Type a replacement term and press . to repeat the replacement again. Useful
" for replacing a few instances of the term (comparable to multiple cursors).
nnoremap <silent> s* :let @/='\<'.expand('<cword>').'\>'<CR>cgn
xnoremap <silent> s* "sy:let @/=@s<CR>cgn
" Clear search highlights.
map <Leader><Space> :let @/=''<CR>
nnoremap <silent> // :noh<CR>
" Format paragraph (selected or not) to 80 character lines.
nnoremap <Leader>g gqap
xnoremap <Leader>g gqa
" Reselect visual selection after indenting.
vnoremap < <gv
vnoremap > >gv
" Prevent x from overriding what's in the clipboard.
noremap x "_x
noremap X "_x
" Prevent selecting and pasting from overwriting what you originally copied.
xnoremap p pgvy
" Keep cursor at the bottom of the visual selection after you yank it.
vmap y ygv<Esc>
" Edit Vim config file in a new tab.
map <Leader>ev :tabnew $MYVIMRC<CR>
" Source Vim config file.
map <Leader>sv :source $MYVIMRC<CR>
" Allow gf to ceate and open files
map gf :edit <cfile><CR>
" Open the current file in the default program
nmap <Leader>x :!xdg-open %<CR><CR>
" Toggle spell check.
map <F5> :setlocal spell!<CR>
" Toggle relative line numbers and regular line numbers.
nmap <F6> :set invrelativenumber<CR>
" Automatically fix the last misspelled word and jump back to where you were.
" Taken from this talk: https://www.youtube.com/watch?v=lwD8G1P52Sk
nnoremap <leader>sp :normal! mz[s1z=`z<CR>
" Toggle visually showing all whitespace characters.
noremap <F7> :set list!<CR>
inoremap <F7> <C-o>:set list!<CR>
cnoremap <F7> <C-c>:set list!<CR>
" Open a terminal
nnoremap <C-w>t :terminal<CR>
" -----------------------------------------------------------------------------
" Basic autocommands
" -----------------------------------------------------------------------------
" Auto-resize splits when Vim gets resized.
au VimResized * wincmd =
" Update a buffer's contents on focus if it changed outside of Vim.
au FocusGained,BufEnter * :checktime
" Unset paste on InsertLeave.
au InsertLeave * silent! set nopaste
" Make sure all types of requirements.txt files get syntax highlighting.
au BufNewFile,BufRead requirements*.txt set syntax=python
" Ensure tabs don't get converted to spaces in Makefiles.
au FileType make setlocal noexpandtab
" Only show the cursor line in the active buffer.
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
" Set filetype syntax and behavior
au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mdwn,*md set ft=markdown
au BufNewFile,BufRead conf,config,*.conf,*.strm,*.xspf set ft=config
au BufNewFile,BufRead *.wiki set ft=vimwiki
" Prevent rezize glitch on open
au VimEnter * :silent exec "!kill -s SIGWINCH $PPID"
" ----------------------------------------------------------------------------
" Basic commands
" ----------------------------------------------------------------------------
" Add all TODO items to the quickfix list relative to where you opened Vim.
function! s:todo() abort
let entries = []
for cmd in ['git grep -niIw -e TODO -e FIXME 2> /dev/null',
\ 'grep -rniIw -e TODO -e FIXME . 2> /dev/null']
let lines = split(system(cmd), '\n')
if v:shell_error != 0 | continue | endif
for line in lines
let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
endfor
break
endfor
if !empty(entries)
call setqflist(entries)
copen
endif
endfunction
command! Todo call s:todo()
" Profile Vim by running this command once to start it and again to stop it.
function! s:profile(bang)
if a:bang
profile pause
noau qall
else
profile start /tmp/profile.log
profile func *
profile file *
endif
endfunction
command! -bang Profile call s:profile(<bang>0)
" Save buffer as sudo
ca w!! w !sudo tee "%"
" Save with Ctrl-s
nnoremap <C-s> :w<CR>
inoremap <C-s> <ESC>:w<CR>
" Open a terminal
nnoremap <C-w>t :terminal<CR>
" Remove trailing whitespaces
au BufWritePre * %s/\s\+$//e
" Remove trailing newline
au BufWritePre * %s/\n\+\%$//e
" Highlight yanked text
augroup highlightYankedText
autocmd!
au TextYankPost * call FlashYankedText()
augroup END
function! FlashYankedText()
if (!exists('g:yankedTextMatches'))
let g:yankedTextMatches = []
endif
let matchId = matchadd('IncSearch', ".\\%>'\\[\\_.*\\%<']..")
let windowId = winnr()
call add(g:yankedTextMatches, [windowId, matchId])
call timer_start(500, 'DeleteTemporaryMatch')
endfunction
function! DeleteTemporaryMatch(timerId)
while !empty(g:yankedTextMatches)
let match = remove(g:yankedTextMatches, 0)
let windowID = match[0]
let matchID = match[1]
try
call matchdelete(matchID, windowID)
endtry
endwhile
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Status Line
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Status Line Custom
let g:currentmode={
\ 'n' : 'Normal',
\ 'no' : 'Normal·Operator Pending',
\ 'v' : 'Visual',
\ 'V' : 'V·Line',
\ '^V' : 'V·Block',
\ 's' : 'Select',
\ 'S' : 'S·Line',
\ '^S' : 'S·Block',
\ 'i' : 'Insert',
\ 'R' : 'Replace',
\ 'Rv' : 'V·Replace',
\ 'c' : 'Command',
\ 'cv' : 'Vim Ex',
\ 'ce' : 'Ex',
\ 'r' : 'Prompt',
\ 'rm' : 'More',
\ 'r?' : 'Confirm',
\ '!' : 'Shell',
\ 't' : 'Terminal'
\}
set statusline= " clear the statusline for when vimrc is reloaded
set statusline+=%0*\ %{toupper(g:currentmode[mode()])}\ " The current mode
set statusline+=%3n\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%m%r%w\ " flags
set statusline+=%= " right align
set statusline+=%{&fileformat}\ \| " file format
set statusline+=\ %{strlen(&fenc)?&fenc:&enc}\ \| " encoding
set statusline+=\ %{strlen(&ft)?&ft:'none'}\ " filetype
set statusline+=\ %<%p%%\ " position
set statusline+=\ %-4.(%l:%c%)\ " offset
" status bar colors
hi StatusLine guifg=Grey guibg=Black ctermfg=Grey ctermbg=Black
function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi statusline guifg=Blue guibg=Black ctermfg=Blue ctermbg=Black
elseif a:mode == 'r'
hi statusline guifg=Red guibg=Black ctermfg=Red ctermbg=Black
else
hi statusline guifg=Grey guibg=Black ctermfg=Grey ctermbg=Black
endif
endfunction
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline guifg=Grey guibg=Black ctermfg=Grey ctermbg=Black
" .............................................................................
" Fast editing and reloading of vimrc configs
" .............................................................................
autocmd! bufwritepost $MYVIMRC source $MYVIMRC