-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
250 lines (201 loc) · 7.68 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
" Omar Sandoval's .vimrc
"""""""""" Settings
" Miscellaneous settings for the 21st century
set nocompatible " no Vi-compatibility
set backspace=indent,eol,start " more powerful backspace
set history=1000 " keep 1000 lines of command line history
set showcmd " display incomplete commands
set tabpagemax=50 " we can afford more than 10 tabs
set ttimeoutlen=50 " avoid annoying delay in terminal
if has('mouse')
set mouse=a
set ttymouse=sgr
endif
" Avoid clutter
set nobackup " don't keep backup files
set directory=~/.vim/tmp " put swap files somewhere else
if !isdirectory(&directory)
call mkdir(&directory, "p")
endif
" Behavior
set completeopt+=longest " only insert the longest common text when completing
set completeopt+=popup " show info in a popup instead of a preview window
set incsearch " do incremental searching
set nojoinspaces " one space after periods when joining
set scrolloff=0 " let me scroll all the way to the top and bottom
set splitbelow " personal preference
set splitright
set wildmenu " zsh-ish command-line tab completion
set wildmode=list:longest,list:full
" Appearance
set cursorline " indicate current line
set hlsearch " highlight search matches
set number " number lines
set relativenumber " relative line numbering
set ruler " show the cursor position all the time
if !has("gui_running")
" Change cursor in insert mode and replace mode like a GVim weenie
let &t_SI .= "\<Esc>[6 q"
let &t_EI .= "\<Esc>[2 q"
if exists("&t_SR")
let &t_SR .= "\<Esc>[4 q"
endif
" 0 or 1 -> blinking block
" 2 -> solid block
" 3 -> blinking underscore
" 4 -> solid underscore
" Recent versions of xterm (282 or above) and urxvt also support
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
" Undercurl escape sequences: https://sw.kovidgoyal.net/kitty/underlines/
let &t_Cs .= "\e[4:3m"
let &t_Ce .= "\e[4:0m"
let &t_AU = "\e[58;5;%dm"
let s:xtermMatch = matchlist($XTERM_VERSION, 'XTerm(\(\d\+\))')
if len(s:xtermMatch) > 0
" Ugh, Meta-Alt-Escape crap
exec "set <M-b>=\eb"
exec "set <M-f>=\ef"
endif
endif
syntax on
set background=light
colorscheme minimal
" Autocmds and filetype-specific stuff
augroup vimrc
au!
" 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).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Resize splits when the terminal is resized
autocmd VimResized * wincmd =
" I don't write Modula
autocmd BufRead,BufNewFile *.md set filetype=markdown
" I do write AsciiDoc, though
autocmd BufRead,BufNewFile *.adoc set filetype=asciidoc
" Close enough for Coccinelle
autocmd BufRead,BufNewFile *.cocci set filetype=diff
" Python type hint stub files
autocmd BufRead,BufNewFile *.pyi set filetype=python
augroup END
" Use LaTeX instead of plain TeX for .tex files
let g:tex_flavor = 'latex'
" Use C syntax for *.h files, not C++
let g:c_syntax_for_h = 1
" Highlight bad spacing
let g:c_space_errors = 1
let g:python_space_error_highlight=1
"""""""""" Mappings
" Map Command-Line mode navigation to arrows keys so we can have filtering
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
" Move quickly between tabs
nnoremap <C-N> gt
nnoremap <C-P> gT
" Clear search highlighting
nnoremap <Space> :nohl<CR>
vnoremap <Space> :nohl<CR>
" 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>
" Open tag in a new tab
nnoremap <silent><C-\><C-]> <C-w><C-]><C-w>T
" Leader mappings
nnoremap \ ,
let mapleader = ","
let maplocalleader = ","
" Convenient save
noremap <Leader>m :up<CR>
" Move between windows
noremap <Leader>w <C-W>w
" Splits
noremap <Leader>s <C-W>s
noremap <Leader>v <C-W>v
noremap <Leader>t <C-W>s<C-W>T
" Start a search for a whole word
noremap <Leader>/ /\<\><Left><Left>
" Manual autochdir
noremap <Leader>cd :cd %:p:h<CR>
" Quick and dirty sessions
noremap <Leader>km :mksession! ~/.vim/tmp/session<CR>
noremap <Leader>ks :source ~/.vim/tmp/session<CR>
" Toggle relative and absolute numbering
noremap <Leader>ln :set rnu!<CR>
cnoremap w!! SudoWrite
"""""""""" Plugins
filetype off
if isdirectory($HOME . "/.vim/bundle/Vundle.vim")
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'chrisbra/SudoEdit.vim'
Plugin 'ervandew/supertab'
Plugin 'mileszs/ack.vim'
Plugin 'ojroques/vim-oscyank'
Plugin 'osandov/fugitive-cgit'
Plugin 'scrooloose/nerdcommenter'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-rhubarb'
Plugin 'tpope/vim-rsi'
Plugin 'tpope/vim-vinegar'
Plugin 'Vimjas/vim-python-pep8-indent'
call vundle#end()
endif
filetype plugin indent on
" Delimit comments with spaces
let g:NERDSpaceDelims = 1
" Workaround stupid extra space hardcoded for Python
let g:NERDCustomDelimiters = {'python': {'left': '#'}, 'pyrex': {'left': '#'}}
" Also autocomplete C preprocessor macros
let g:clang_complete_macros = 1
let g:fugitive_cgit_domains = ['https://git.kernel.org']
" Disable message on OSCYank
let g:oscyank_silent = 1
" Make completeopt longest more useful
let g:SuperTabLongestEnhanced = 1
let g:SuperTabLongestHighlight = 1
if executable("goimports")
let g:gofmt_command="goimports"
endif
" Make ack.vim use rg.
let g:ackprg = 'rg --vimgrep'
" Add Rg aliases for all of the Ack commands.
command! -bang -nargs=* -complete=file Rg call ack#Ack('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=file RgAdd call ack#Ack('grepadd<bang>', <q-args>)
command! -bang -nargs=* -complete=file RgFromSearch call ack#AckFromSearch('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=file LRg call ack#Ack('lgrep<bang>', <q-args>)
command! -bang -nargs=* -complete=file LRgAdd call ack#Ack('lgrepadd<bang>', <q-args>)
command! -bang -nargs=* -complete=file RgFile call ack#Ack('grep<bang> -g', <q-args>)
command! -bang -nargs=* -complete=help RgHelp call ack#AckHelp('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=help LRgHelp call ack#AckHelp('lgrep<bang>', <q-args>)
command! -bang -nargs=* RgWindow call ack#AckWindow('grep<bang>', <q-args>)
command! -bang -nargs=* LRgWindow call ack#AckWindow('lgrep<bang>', <q-args>)
" Plugin autocmds
augroup vimrcPlugin
au!
" Use omnicomplete and keyword completion for supertab
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<C-P>") |
\ endif
" Override the vim-vinegar settings for the following
autocmd FileType * let g:netrw_sort_sequence=''
" Ignore
" - ".*" but not "./" or "../"
" - "*.o" and "*.dwo"
" - "*.pyc" and "__pycache__"
autocmd FileType * let g:netrw_list_hide='^\.\([^./]\|\.[^/]\),\.o$,\.dwo$,\.pyc$,^__pycache__$'
" Copy to the clipboard using OSC52 when yanking to the " register
" explicitly (regname is an empty for the unnamed register).
autocmd TextYankPost * if v:event.regname == '"' | call OSCYank(v:event.regcontents->join("\n") . "\n") | endif
augroup END
if filereadable(expand('~/.vimrc.local'))
source ~/.vimrc.local
endif