-
Notifications
You must be signed in to change notification settings - Fork 64
/
.vimrc
332 lines (283 loc) · 8.55 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
set encoding=utf-8
set tabstop=2
set shiftwidth=2
set expandtab
set smarttab
set autoindent
set nowrap
set smartcase
set showmatch
set title
set ruler
set et
set number relativenumber
set scrolloff=4
set incsearch
set hlsearch
set autoread
set autowrite
set nobackup
set nowritebackup
set noswapfile
set nocompatible
" title required for i3 status checking, modified indicator at end
"set titlestring=%t%(\ \(%F\)%)%a\ -\ VIM%(\ %M%)
set titlestring=%(%F%)%a\ -\ VIM%(\ %M%)
set t_Co=16
" undo cursorlinenr underline (was introduced Aug '19)
hi CursorLineNr cterm=bold
" allows buffers to be hidden if you modified a buffer
set hidden
filetype off
syntax on
" removes possibility to define function keys that start with <Esc>
" see if has implications
set noesckeys
" configure netrw explorer
let g:netrw_banner = 0
let g:netrw_liststyle = 3
" Vundle
"<<<<<<<<<<<<<<<<<<<<
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
Plugin 'mbbill/undotree'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
Plugin 'wellle/context.vim'
" UltiSnips for completion / templating
Plugin 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plugin 'sdaschner/vim-snippets'
Plugin 'ervandew/supertab'
let g:SuperTabDefaultCompletionType = '<C-n>'
let g:SuperTabCrMapping = 0
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
" All of your Plugins must be added before the following line
call vundle#end()
filetype plugin indent on
" something messes up this setting in the plugins
set expandtab
" fixes context ident for Markdown (context.vim)
function MyIndent(line)
if &ft == 'markdown'
" some custom implementation for markdown
let indent = indent(a:line)
if indent < 0
return [indent, indent]
endif
let line = getline(a:line)
let headings = match(line, '^*\+\zs\s')+1
if headings <= 0
let headings = match(line, '^#\+\zs\s')+1
if headings <= 0
let headings = 5
endif
endif
return [indent+headings, indent]
else
" fall back to default implementation
let indent = indent(a:line)
return [indent, indent]
endif
endfunction
let g:Context_indent = funcref('MyIndent')
let g:context_skip_regex = '^\s*$'
let mapleader = "\<Space>"
nmap <S-Enter> O<Esc>
nmap <CR> o<Esc>
inoremap <Up> <c-y>
inoremap <Down> <c-e>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <c-y>
noremap <Down> <c-e>
" presentation mode
noremap <Left> :silent bp<CR> :redraw!<CR>
noremap <Right> :silent bn<CR> :redraw!<CR>
nmap <F5> :set relativenumber! number! showmode! showcmd! hidden! ruler!<CR>
nmap <F2> :call DisplayPresentationBoundaries()<CR>
nmap <F3> :call FindExecuteCommand()<CR>
" jump to slides
nmap <F9> :call JumpFirstBuffer()<CR> :redraw!<CR>
nmap <F10> :call JumpSecondToLastBuffer()<CR> :redraw!<CR>
nmap <F11> :call JumpLastBuffer()<CR> :redraw!<CR>
" move lines with Ctrl + (Shift) +J/K
nnoremap <C-j> :m +1<CR>
nnoremap <C-k> :m -2<CR>
inoremap <C-j> <Esc>:m +1<CR>gi
inoremap <C-k> <Esc>:m -2<CR>gi
vnoremap <C-j> :m '>+1<CR>gvgv
vnoremap <C-k> :m '<-2<CR>gvgv
" opens a new empty buffer
nmap <leader>t :enew<CR>
" moves to the next buffer
nmap <leader>l :bnext<CR>
" moves to the previous buffer
nmap <leader>h :bprevious<CR>
" closes the current buffer, moves to the previous one
nmap <leader>bd :bd<CR>
" forces buffer close
nmap <leader>BD :bd!<CR>
" shows all open buffers and their status
nmap <leader>bl :ls<CR>
" toggles the paste mode
nmap <C-p> :set paste!<CR>
" toggles word wrap
nmap <leader>w :set wrap! linebreak<CR>
" toggles spell checking
nmap <C-]> :set spell! spelllang=en_us<CR>
" opens the last buffer
nnoremap <leader><leader> <C-^>
" adds a line of <
nmap <leader>a :normal 20i<<CR>
" makes Ascii art font
nmap <leader>2 :.!toilet -w 200 -f standard<CR>
nmap <leader>3 :.!toilet -w 200 -f small<CR>
" makes Ascii border
nmap <leader>1 :.!toilet -w 200 -f term -F border<CR>
" capitalize titles
nmap <leader>c :.!capitalize-title -<CR>
vnoremap <leader>c :.!capitalize-title -<CR>
" open netrw/fzf/search
nmap <leader>x :Explore<CR>
nmap <leader>n :Files<CR>
nmap <leader>f :Rg<CR>
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
" system clipboard
vmap <leader>y "+y
vmap <leader>d "+d
nmap <leader>y "+yy
nmap <leader>p "+p
nmap <leader>P "+P
vmap <leader>p "+p
vmap <leader>P "+P
nmap <leader>d <C-d>
nmap <leader>u <C-u>
vmap <leader>d <C-d>
vmap <leader>u <C-u>
" file operations
nmap <C-s> :w<CR>
nmap <C-q> :q<CR>
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
" search highlighting color
highlight Search ctermfg=grey ctermbg=red
highlight Macro ctermfg=cyan
highlight Special ctermfg=red
" removes search highlighting
nnoremap <silent> <C-l> :nohl<CR><C-l>
" execute command
nmap <leader><Enter> !!zsh<CR>
" AsciiDoc preview
nmap <leader>v :w !asciidoc-view -<CR><CR>
" Transparent editing of gpg encrypted files.
" By Wouter Hanegraaff
augroup encrypted
au!
" First make sure nothing is written to ~/.viminfo while editing
" an encrypted file.
autocmd BufReadPre,FileReadPre *.gpg set viminfo=
" We don't want a swap file, as it writes unencrypted data to disk
autocmd BufReadPre,FileReadPre *.gpg set noswapfile
" Switch to binary mode to read the encrypted file
autocmd BufReadPre,FileReadPre *.gpg set bin
autocmd BufReadPre,FileReadPre *.gpg let ch_save = &ch|set ch=2
" (If you use tcsh, you may need to alter this line.)
autocmd BufReadPost,FileReadPost *.gpg '[,']!gpg --decrypt 2> /dev/null
" Switch to normal mode for editing
autocmd BufReadPost,FileReadPost *.gpg set nobin
autocmd BufReadPost,FileReadPost *.gpg let &ch = ch_save|unlet ch_save
autocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost " . expand("%:r")
" Convert all text to encrypted text before writing
" (If you use tcsh, you may need to alter this line.)
autocmd BufWritePre,FileWritePre *.gpg '[,']!gpg --default-recipient-self -ae 2>/dev/null
" Undo the encryption so we are back in the normal text, directly
" after the file has been written.
autocmd BufWritePost,FileWritePost *.gpg u
augroup END
function! JumpFirstBuffer()
execute "buffer 1"
endfunction
function! JumpSecondToLastBuffer()
execute "buffer " . (len(Buffers()) - 1)
endfunction
function! JumpLastBuffer()
execute "buffer " . len(Buffers())
endfunction
function! Buffers()
let l:buffers = filter(range(1, bufnr('$')), 'bufexists(v:val)')
return l:buffers
endfunction
" Automatically source an eponymous <file>.vim or <file>.<ext>.vim if it exists, as a bulked-up
" modeline and to provide file-specific customizations.
function! s:AutoSource()
let l:testedScripts = ['syntax.vim']
if expand('<afile>:e') !=# 'vim'
" Don't source the edited Vimscript file itself.
call add(l:testedScripts, 'syntax.vim')
endif
for l:filespec in l:testedScripts
if filereadable(l:filespec)
execute 'source' fnameescape(l:filespec)
endif
endfor
call FindExecuteCommand()
endfunction
augroup AutoSource
autocmd! BufNewFile,BufRead * call <SID>AutoSource()
augroup END
set foldtext=SimpleFoldText()
set fillchars=fold:\
function SimpleFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
return sub . ' >>>>>>'
endfunction
set foldlevelstart=20
set foldmethod=expr
set foldexpr=ListFolds()
function! ListFolds()
let thisline = getline(v:lnum)
if match(thisline, '^- ') >= 0
return ">1"
elseif match(thisline, '^ - ') >= 0
return ">2"
elseif match(thisline, '^ - ') >= 0
return ">3"
elseif match(thisline, '^ - ') >= 0
return ">4"
elseif match(thisline, '^ - ') >= 0
return ">5"
endif
return "0"
endfunction
let g:presentationBoundsDisplayed = 0
function! DisplayPresentationBoundaries()
if g:presentationBoundsDisplayed
match
set colorcolumn=0
let g:presentationBoundsDisplayed = 0
else
highlight lastoflines ctermbg=darkred guibg=darkred
match lastoflines /\%23l/
set colorcolumn=80
let g:presentationBoundsDisplayed = 1
endif
endfunction
function! FindExecuteCommand()
let line = search('\S*!'.'!:.*')
if line > 0
let command = substitute(getline(line), "\S*!"."!:*", "", "")
execute "silent !". command
execute "normal gg0"
redraw
endif
endfunction