-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
253 lines (188 loc) · 6.7 KB
/
.vimrc
File metadata and controls
253 lines (188 loc) · 6.7 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
set nocompatible
" The leader key must be set before any other mappings that reference it
nnoremap <SPACE> <Nop>
let mapleader=" "
let maplocalleader=" "
" PER-DIRECTORY .vimrc
set exrc
set secure
" But no per-file modelines.
set modelines=0
" AVOID DATA LOSS
" Keep undo information in *.un~ files
set undofile
" Enable undo of deletion actions in insert mode
inoremap <C-U> <C-G>u<C-U>
inoremap <C-W> <C-G>u<C-W>
" Remember more command-line history
set history=1000
if !has('nvim')
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "1000: will save up to 1000 lines for each register
" :1000: command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
set viminfo=!,'10,\"1000,:1000,%,n~/.viminfo
endif
" If file is changed outside of vim and not changed inside of vim,
" automatically update vim buffer contents to match new file contents.
" You can undo with 'u'.
" NOTE: This won't work in tmux unless you configure tmux to pass through focus events
set autoread
set tabpagemax=50
set sessionoptions-=options
set viewoptions-=options
" TEXT
set encoding=utf-8
" FORMATTING
set autoindent
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Use filetype detection and file-based automatic indenting.
filetype plugin indent on
" Set some filetypes to get better formatting and syntax highlighting
autocmd BufNewFile,BufRead SCons* set filetype=scons
" For working with git-revise (https://github.com/mystor/git-revise)
autocmd BufRead,BufNewFile COMMIT_EDITMSG set filetype=gitcommit
" I don't use Modula-2. Only needed for old versions of Vim. See:
" https://github.com/vim/vim/commit/7d76c804af900ba6dcc4b1e45373ccab3418c6b2#diff-c07c0771a9f5af08e375703487a8fe7bbddd71f98a7bbe06acd78365525a243eR1246
autocmd BufNewFile,BufRead *.md set filetype=markdown
" I don't use Smalltalk. Needed for (La)TeX .cls files that don't start
" with a comment. See:
" https://github.com/vim/vim/blob/50157ef1c2e36d8696e79fd688bdd08312196bc6/runtime/filetype.vim#L1624
autocmd BufNewFile,BufRead *.cls set filetype=tex
" Use actual tab chars in Makefiles.
autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab
" clang-format
if has('python')
autocmd FileType c,cpp map <C-I> :pyf ~/.vim/clang-format.py<CR>
elseif has('python3')
" NOTE: For Neovim, you might need to run:
" python3 -m pip install --user --upgrade pynvim
autocmd FileType c,cpp map <C-I> :py3f ~/.vim/clang-format.py<CR>
endif
" https://stackoverflow.com/q/28078407
autocmd Filetype c,cpp set comments^=:///
endif
" For everything else, use a tab width of 2 space chars.
set tabstop=8 " Display TAB as having width 8.
set shiftwidth=2 " Indent width.
set softtabstop=2 " Sets the number of columns for a TAB.
set expandtab " Expand TABs to spaces.
set smarttab
" Delete comment leaders when joining commented lines
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j
endif
" HIGHLIGHTING
" turn on syntax highlighting
if has('syntax') && !exists('g:syntax_on')
syntax enable
endif
colorscheme elflord
"set t_Co=16
if exists('+colorcolumn')
" highlight 80th column
set colorcolumn=80
else
" highlight columns after 80
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
" highlight trailing whitespace
" This is much louder than the use of 'trail' in 'listchars' below.
"match ErrorMsg '\s\+$'
" Turn on spell checking for some filetypes
autocmd FileType gitcommit setlocal spell
autocmd FileType tex,plaintex,context setlocal spell
autocmd FileType markdown setlocal spell
autocmd FileType text setlocal spell
set spellfile=~/.vim/spell/en.utf-8.add
" Reduce slowness with long lines
if &synmaxcol == 3000
set synmaxcol=500
endif
" DISPLAY & INFORMATION
set ttyfast
" Do *not* disable beeping. Attempting to flash screen depending on t_vb is
" unreliable. Instead, enforce the default that bells send \a to the
" terminal. I leave it to my terminal to decide whether to actually play an
" audible sound. In Windows Terminal, for example, I set `Settings > Profiles
" > Defaults > Advanced > Bell notification style` to "Flash window"
set novisualbell
" normal-mode errors that display error messages should also 'ring the bell'
set errorbells
" N.B. Nvim has 'belloff' which is enabled by default.
" Always show status bar
set laststatus=2
" leave last command visible
set showcmd
" show line numbers
set number
set relativenumber
" turn on line and column number in status bar
set ruler
" Show as much as possible of line that wraps past end of window
set display+=lastline
" Nvim also has msgsep, included by default
" Keep context lines visible around cursor
set scrolloff=3
" Smooth sideways scrolling (when nowrap is set)
set sidescroll=1
" Keep context columns visible around cursor
set sidescrolloff=5
" Show wrapped lines as indented blocks
set breakindent
" Show potentially unwanted whitespace and line wraps
set list listchars=tab:▸\ ,trail:·,nbsp:·,precedes:←,extends:→
" MOTION
" Unbind the arrow keys in insert, normal and visual modes.
for prefix in ['i', 'n', 'v']
for key in ['<Up>', '<Down>', '<Left>', '<Right>']
exe prefix . "noremap " . key . " <Nop>"
endfor
endfor
" Move in display lines, not physical lines
nnoremap j gj
nnoremap k gk
" Make '%' understand if/else etc. in many languages
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" SEARCHING
set incsearch
set hlsearch
nnoremap <C-n> :noh<cr>
" case insensitive, unless search pattern includes capital letter
set ignorecase
set smartcase
" invert meaning of 'g' flag: search for multiple matches in a line
set gdefault
" Semicolon means search upward in directory tree to find tags file
" See `:help file-searching`
set tags=./tags;
" EDITING
" make backspace work
set backspace=indent,eol,start
" Reduce noise from headers in insert-mode autocomplete
set complete-=i
" Sensible command autocomplete
set wildmenu
set wildmode=list:longest
set wildoptions+=tagfile
" Specific to Nvim? Nvim default:
"set wildoptions+=pug
" Increment/decrement decimal numbers with leading zero
set nrformats-=octal
" https://stackoverflow.com/a/18730056
xnoremap <expr> P '"_d"'.v:register.'P'
" CUSTOM KEYBINDINGS
inoremap jj <Esc>
" Timeout for above multi-keypress bindings
set timeoutlen=200
" Key codes should use a shorter timeout
if !has('nvim') && &ttimeoutlen == -1
set ttimeout
set ttimeoutlen=50
endif