-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
271 lines (221 loc) · 7.82 KB
/
Copy pathvimrc
File metadata and controls
271 lines (221 loc) · 7.82 KB
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
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
" Avoid side effects when it was already reset.
if &compatible
set nocompatible
endif
" When the +eval feature is missing, the set command above will be skipped.
" Use a trick to reset compatible only when the +eval feature is missing.
silent! while 0
set nocompatible
silent! endwhile
" Allow backspacing over everything in insert mode.
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
set undofile " keep an undo file (undo changes after closing)
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set wildmenu " display completion matches in a status line
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Do incremental searching when it's possible to timeout.
if has('reltime')
set incsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
" 1724126 - do not open new file with .spec suffix with spec file template
" apparently there are other file types with .spec suffix, so disable the
" template
" autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
" Revert with ":syntax off".
syntax on
"syntax sync minlines=200 "to correct errors
" I like highlighting strings inside C comments.
" Revert with ":unlet c_comment_strings".
let c_comment_strings=1
" Also switch on highlighting the last used search pattern.
set hlsearch
endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
" Revert with: ":delcommand DiffOrig".
delcommand DiffOrig
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis | exe 'wincmd p | set ft=' . &filetype | wincmd p
endif
if has('langmap') && exists('+langremap')
" Prevent that the langmap option applies to characters that result from a
" mapping. If set (default), this may break plugins (but it's backward
" compatible).
set nolangremap
endif
" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
packadd matchit
" The editorconfig plugin reads the .editorconfig file in your project to
" apply the specified settings.
packadd! editorconfig
" All maintenance files together, leave in cwd if the folder is not there
set backupdir=~/.vim/tmp/bak//,.
set undodir=~/.vim/tmp/un//,.
set directory=~/.vim/tmp/swp//,.
" Show hidden characters
set listchars+=tab:..\|,trail:#,extends:>,precedes:<,space:·
" Personal tab indentation
set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
" Command completion
set wildmode=longest,full
" Insert mode completion up to longest common match
"FIXME quite weird, try to find something better
"set completeopt+=longest
" Better vertical split
set splitright
"set splitbelow
" Spell check language
set spelllang=en
" May give some troubles
set nomodeline
" Better consistency for yank
map Y y$
" Keep edited files as hidden buffers (can change without saving)
set hidden
" Statusbar also with one window open
set laststatus=2
"set showtabline=2
" Highlight trailing spaces
" http://vim.wikia.com/wiki/Highlight_unwanted_spaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
function! RunCurr()
let $nproc = system("nproc") * 5/4
if findfile("Makefile") != ""
if (&filetype == "rst" || &filetype == "txt")
make! -j $nproc htmldocs
else
make! -j $nproc
endif
elseif (&filetype == "tex" || &filetype == "plaintex")
execute("!latexmk *.tex")
elseif (&filetype == "go")
execute("!go run " . bufname("%"))
elseif (&filetype == "xml")
" assume beaker job
execute("!bkr job-submit " . bufname("%"))
elseif (&filetype == "groovy")
"cannot execute this, restore the syntax sync behaviour
syntax sync fromstart
else
"perl reads the shebang, no need to execute
execute("!perl " . bufname("%"))
endif
endfunction
"ignore files for vimgrep
set wildignore+=cscope.*,tags,GTAGS,*.o,*.ko
" avoid additional space after punctuation with J
set nojoinspaces
" Shortcuts
nnoremap <F9> :set spell! spell?<CR>
nnoremap <F8> :set list! list?<CR>
nnoremap <F7> :copen<CR>
nnoremap <F6> :set nu! nu?<CR>
"nnoremap <F5> :syntax sync fromstart<CR>
nnoremap <F5> :call RunCurr()<CR>
nnoremap <F4> :noh<CR>
nnoremap <F3> :Lex<CR>
nnoremap <Leader>] :call system('ctags -R')<CR>
nnoremap <Leader>[ :call system('cscope -Rbkq')<CR>
vnoremap <Leader>c "cy :call system('xclip -sel clip', @c)<CR>
nnoremap <Leader>' :buffers<CR>:buffer<Space>
cabbrev w!! w !sudo tee > /dev/null %
command RestoreSession execute "source Session.vim | silent exec \"!rm -f Session.vim\""
if filereadable($HOME.'/.vim/packs.vim')
source $HOME/.vim/packs.vim
endif
" defined in bashrc
if filereadable($FZFPATH.'/fzf.vim')
source $FZFPATH/fzf.vim
endif
" binary read
nmap <Leader>br :%!xxd<CR> :set filetype=xxd<CR>
" binary write
nmap <Leader>bw :%!xxd -r<CR> :set binary<CR> :set filetype=<CR>
" restore vim90 highlight patterns
function! FixTheme(_)
if &background ==# 'light'
hi Visual term=reverse ctermbg=7 ctermfg=NONE guibg=LightGrey guifg=NONE
else
hi Visual term=reverse ctermbg=242 ctermfg=NONE guibg=DarkGrey guifg=NONE
endif
endfunction
autocmd VimEnter * call timer_start(500, 'FixTheme')
function! ToggleIgnoreWhitespace()
if !&diff
return
endif
if index(split(&diffopt, ','), 'iwhiteall') >= 0
set diffopt-=iwhiteall
else
set diffopt+=iwhiteall
endif
endfunction
nnoremap <leader>w :call ToggleIgnoreWhitespace()<CR>
" Open tags in vertical splits (cannot remap existing one?!)
nnoremap <C-W><C-V>[ :vert winc ]<CR>