-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
369 lines (302 loc) · 9.82 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
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Init vim-plug
call plug#begin('~/.vim/plugged')
Plug 'mhinz/vim-signify'
Plug 'mileszs/ack.vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-dispatch'
Plug 'godlygeek/tabular'
Plug 'Rip-Rip/clang_complete'
Plug 'vim-scripts/UltiSnips'
Plug 'tpope/vim-markdown'
Plug 'nelstrom/vim-markdown-folding'
Plug 'benmills/vimux'
Plug 'xolox/vim-misc'
Plug 'xolox/vim-lua-ftplugin'
Plug 'alols/vim-love-efm'
Plug 'majutsushi/tagbar'
Plug 'alepez/vim-gtest'
Plug 'aklt/plantuml-syntax'
Plug 'kien/ctrlp.vim'
Plug 'tjennings/git-grep-vim'
" Add plugins to &runtimepath
call plug#end()
" Enable file type detection
filetype plugin indent on
" Make Y move like D and C
noremap Y y$
" Use Q to format a paragraph
noremap Q gwip
" Use space to toggle folds
nnoremap <Space> za
" Set undo break before deleting with C-U
inoremap <C-U> <C-G>u<C-U>
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Buffers can be hidden without complaints
set hidden
set shiftwidth=4 " Set indentation step to four spaces
set expandtab " Turn tab key presses into spaces in insert mode
set softtabstop=4 " Insert four spaces with every tab press
set tabstop=4 " Let an actual tab character be repesented by
" four spaces
set history=500 " Keep 500 lines of command line history.
set ruler " Show the cursor position all the time.
set showcmd " Display incomplete commands.
" Set all columns past textwidth as color column
execute "set colorcolumn=+".join(range(1,255),',+')
" Being oldfashioned here.
set noincsearch " Don't do incremental searching.
set nohlsearch " Don't highlight search results.
set nowrapscan " Don't wrap around file when searching.
" Don't use two spaces after a sentence when joining lines.
set nojoinspaces
" GUI options
" Must appear before syntax on.
" Autoselect, use icon, don't source menu.vim, left scrollbar.
set guioptions=aiML
" Use the '+' register as the unnamed register, to make cut and
" paste berween Vim and other applications easier
set clipboard=unnamedplus
" Put visually selected text in the '*' register
set clipboard+=autoselect
" Mice are nice
set mouse=a
" folding
set foldmethod=indent
set foldcolumn=2
set foldnestmax=1
set foldminlines=2
set foldtext=
if &term=~"xterm" || &term=~"screen"
set t_Co=16
colorscheme dark16
endif
" Switch syntax highlighting on.
syntax on
" Avoid delays in terminal
set ttm=50
" Use lots of undo.
set undolevels=1000
set cryptmethod=blowfish
" Use an undodir if persistant undo is available.
if has("persistent_undo")
set undodir=~/.vim/undodir
set undofile
set undoreload=10000
else
" Keep a backup file
set backup
endif
" Tab-completion on the command line.
set wildmenu
set wildmode=list:longest
" Insert mode completion
set completeopt=menuone
"use terminal title.
set title
set titleold=[terminal]
"Fix for xcape
inoremap <C-k> <Esc>k
" I prefer vertical splitting over horizontal
let s:verticalMode=0
fun! s:toggleVerticalMode()
if !s:verticalMode
set splitright
set winwidth=80
cabbrev h vert help
cabbrev sp vsp
cabbrev hsp sp
set diffopt+=vertical
let s:verticalMode=1
else
set nosplitright
set winwidth=20
unabbrev h
cabbrev h help
unabbrev sp
unabbrev hsp
set diffopt-=vertical
let s:verticalMode=0
endif
endfun
command! ToggleVerticalMode call s:toggleVerticalMode()
if &columns > 150
ToggleVerticalMode
endif
" R toggles relative number
set nu
fun! s:toggleRelativeNumber()
if &nu
set rnu
else
set nu
endif
endfun
command! ToggleRelativeNumber call s:toggleRelativeNumber()
noremap R :ToggleRelativeNumber<CR>
" F2 toggles paste
set pastetoggle=<F2>
" F4 toggles list
set list listchars=tab:→\ ,trail:\ ,extends:…,precedes:…
nnoremap <silent> <F4> :setlocal invlist<CR>
inoremap <silent> <F4> <C-o>:setlocal invlist<CR>
" F5 toggles using Swedish special characters when typing
" on an American keyboard (Affects insert mode only)
fun! s:svenska()
if &kmp=="swedish"
set kmp=
else
set kmp=swedish
endif
endfun
command! Svenska call s:svenska()
nnoremap <silent> <F5> :Svenska<CR>
inoremap <silent> <F5> <C-o>:Svenska<CR>
" F6 toggles light/dark colors
fun! s:toggleColors()
if &background=='light'
set background=dark
else
set background=light
endif
endfun
command! InvColors call s:toggleColors()
nnoremap <F6> :InvColors<CR>
" Statusline
set laststatus=2 " Allways show
set statusline=%3n\ " Buffer number
set statusline+=%{&ma?&ro?'=':'':'-'} " Nomodifiable: -, Readonly: =
set statusline+=%{&mod?'+':'\ '}\ " Modified: +
set statusline+=\"%f\"\ %L\ lines%<%= " Filename, nr lines
set statusline+=%{fugitive#statusline()}\ \|\ " Git branch
set statusline+=%{strlen(&ft)?&ft.'\ \|\ ':''} " Filetype
set statusline+=%{strlen(&fenc)?&fenc.'\ ':''} " Encoding
set statusline+=%{&ff=='unix'?'^n':&ff=='dos'?'^r^n':'^r'} "Lineendings
set statusline+=\ \|\ %4l,\ %2c\ " Row, Col
set fillchars=
" When writing prose, it is useful to put undo breaks after each sentence
command! Prose inoremap <buffer> . .<C-G>u|
\ inoremap <buffer> ! !<C-G>u|
\ inoremap <buffer> ? ?<C-G>u|
\ setlocal spell spelllang=sv,en
\ nolist nowrap tw=79 fo=t1 nonu|
\ augroup PROSE|
\ autocmd InsertEnter <buffer> set fo+=a|
\ autocmd InsertLeave <buffer> set fo-=a|
\ augroup END
command! Code silent! iunmap <buffer> .|
\ silent! iunmap <buffer> !|
\ silent! iunmap <buffer> ?|
\ setlocal nospell list nowrap
\ tw=79 fo=cqr1 showbreak=… nu|
\ silent! autocmd! PROSE * <buffer>
" Code is default mode
Code
" I use this to correct my spelling mistakes
nnoremap \s ea<C-X><C-S>
" Turn hard wrapped text into soft wrapped.
" This command will join all lines within a range that are not separated
" by empty lines. Automatic word wrap must be off (set fo-=a).
" Useful if you need to copy and paste into a word processor.
command! -range=% SoftWrap
\ <line2>put _ |
\ <line1>,<line2>g/.\+/ .;-/^$/ join |normal $x
"clang_complete settings
let g:clang_snippets=1
let g:clang_snippets_engine="ultisnips"
let g:clang_complete_macros=1
let g:clang_library_path="/usr/lib/llvm-3.4/lib"
"these two enables error checking
let g:clang_complete_copen=1
let g:clang_hl_errors=1
" m is really nice for custom mappings, who uses marks anyway?
noremap ml :<C-u>CtrlPMRU<CR>
let g:ctrlp_map = 'mf'
noremap mp :<C-u>call VimuxPromptCommand()<CR>
noremap mr :<C-u>call VimuxRunLastCommand()<CR>
noremap mc :<C-U>call g:ClangUpdateQuickFix()<CR>
noremap mt :<C-U>TagbarToggle<CR>
noremap mm :<C-U>Make<CR>
noremap ma :<C-U>Ack
noremap mg :<C-U>GitGrep
" Some GPG commands
" Sign range
command! -range=% Sig <line1>,<line2>!gpg -ats
" Encrypt and sign range
command! -range=% Enc <line1>,<line2>!gpg -atse
" Decryt/Verify range
command! -range=% Dec <line1>,<line2>!gpg -atd
" Strip range of leading ">"
command! -range=% Str <line1>,<line2>s/^> *//
" Found this online and modified it a bit.
" If jumping beyond last window try to jump to tmux split instead.
" Also see tmux.conf
if exists('$TMUX')
function! TmuxOrSplitSwitch(wincmd, tmuxdir)
let previous_winnr = winnr()
silent! execute "wincmd " . a:wincmd
if previous_winnr == winnr()
call system("tmux select-pane -" . a:tmuxdir)
redraw!
endif
endfunction
noremap <silent> <Left> :<C-u>call TmuxOrSplitSwitch('h', 'L')<cr>
noremap <silent> <Down> :<C-u>call TmuxOrSplitSwitch('j', 'D')<cr>
noremap <silent> <Up> :<C-u>call TmuxOrSplitSwitch('k', 'U')<cr>
noremap <silent> <Right> :<C-u>call TmuxOrSplitSwitch('l', 'R')<cr>
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
augroup vimrcEx
au!
" When editing a file, always jump to the last known cursor position.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" When starting a diff, jump to the top.
autocmd FilterWritePost *
\ if &diff |
\ exe "normal! gg" |
\ endif
" Lets be faithful to out line editor heritage
if &t_Co == 16
set cursorline
autocmd WinEnter * set cursorline
autocmd WinLeave * set nocursorline
endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
au BufNewFile,BufRead *.qml setf qml |
\ set tw=0 |
\ normal zi
let s:privdir = expand('~/Private')
if finddir(s:privdir) != ""
" Private directory exists
if 0 == match(getcwd(), s:privdir)
" Vim launched inside private directory
" Location of viminfo-file (must be last viminfo-setting)
set viminfo+=n~/Private/.viminfo
" Location of undo files
set undodir=~/Private/tmp/vimundo
" Location of swapfile, '.' = same dir as file
set directory=.,~/Private/tmp
else
" Vim launched outside of private directory
" Don't allow editing of files in private
augroup privateDirAu
au!
execute 'autocmd BufRead '.s:privdir.'/* bd |
\ echoerr "Tried to open file under '.s:privdir.' from outside of it"'
augroup END
endif
endif
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"