-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
295 lines (251 loc) · 10.8 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
" Vim configuration file. Set to be programmer friendly.
"
" This file does not include any configuration for the GUI since .gvimrc
" is sourced just for that reason.
"============================== Miscellaneous ==========================
set nocompatible " Turn off strict compatibility with vi.
set nobackup " Don't keep a backup file
set noswapfile " Don't keep swapfiles
set viminfo='20,<50,s100,h " 50 lines of registers
set history=50 " Keep 50 lines of command line history
set noerrorbells " Silence error bells/beeps
set ttyscroll=1 " Does something about screen redrawing...
set shell=/bin/bash
set wildmode=longest,list " Let me tab complete file names
set autowrite " Automatically save before commands like :next and :make
"set list " Show whitespace
set tabpagemax=20 " Allow up to 20 tabs simultaneously
set sessionoptions+=unix,slash " Make sessions compatible between Unix and MS-Windows.
if has("multi_byte")
set encoding=utf-8 " Display digraphs better. Default is latin1.
endif
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
" Turn on write backups to avoid the case where the disk has become full and
" to the file will truncate what we have. This option writes to a temporary
" file and when successful, moves the temporary into the original.
set writebackup
" Automatically update buffer contents if the file has not been modified
" inside of Vim and is updated on disk. Nothing is updated if the file
" is removed from disk.
set autoread
" Keep Vim from detaching from the terminal when spawning gvim. We place
" this option here since by the time the .gvimrc file has been read, it
" is too late.
set guioptions+=f
" Make pattern matching case insensitive unless explicitly requested. That is
" if the pattern consists of only lower case letters, be insensitive, otherwise
" be sensitive.
set smartcase
"================================ Formatting ===========================
set expandtab " Always convert tabs to spaces
set backspace=2 " Allow backspacing over everything in insert mode
set tabstop=2 " Set tab width to 2 spaces
" Make groups of 2 spaces behave like a single tab. That is, hitting
" backspace will delete all 2 spaces.
set softtabstop=2
" Default indentation level. How many columns to indent by when you use the
" >> command.
set shiftwidth=2
" Be smart about indenting things? Should make TAB indent things.
set smarttab
" Automatically indent things according to where the previous line started.
" This should cover files that don't have indentexprs associated with them.
set autoindent
"================================ Display ==============================
set showmode " Show what mode the editor is currently in (visual, insert, etc)
set noerrorbells " Disable the bell.
set showcmd " Show (partial) command in status line.
set incsearch " Incremental search
set scrolloff=3 " Always try to keep the cursor within 3 lines of the top/bottom
set laststatus=2 " Always show status bar
set wrap " Display long lines across multiple lines (instead of continuing off the window)
set linebreak " Wrap long lines at a space instead of in the middle of a word
set hls " Make sure search highlighting is active.
"set showmatch " Show matching brackets.
" Have text wrap at 80 characters. Newlines aren't inserted into the data
" stream. We specifically control when text wraps and when comments wrap.
set textwidth=80
" Text never wraps, comments do.
set formatoptions-=t
set formatoptions+=c
" Disable the introduction screen that is normally displayed when starting
" Vim.
set shortmess=I
" Display a status line indicating the current line and column number. This
" goes well with the mode display that we set later.
set ruler
if has('autocmd')
" Disable the bell's annoying friend; visual bell. Do it in a way that is
" compatible across all architectures that support gvim and not just
" Unix variants.
autocmd VimEnter * set vb t_vb=""
endif
"let g:molokai_original=1
"colorscheme molokai
"colorscheme wombat " Use more interesting colors
"colorscheme desert " Use more interesting colors
colorscheme jellybeans " Use more interesting colors
"if &diff
"" colorscheme evening " Better colors for vimdiff
" colorscheme jellybeans " Better colors for vimdiff
"endif
"========================== File Type Specifics ========================
if has('autocmd')
" Makefiles must have tabs in them or make will complain very loudly.
autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab
" Indent intelligently when editing C source code.
autocmd FileType c,cpp,fortran set cindent
" Specify how C source code should be indented. This can be interpreted as:
"
" :0 indent case statement labels to the same column as the opening switch
" l1 align statements in a case offset from where the case label opened
" g0 place C++ scope declarations (public/private/protected) on the first
" column of the block that encloses them.
" (0 line up columns after opening a parenthesis but before it is closed.
" +2s this might help with continuing lines, probably mostly unnecessary
" for now.
autocmd FileType c,cpp set cinoptions=:0l1g0(0+2s
" Remove trailing whitespace when saving certain file types.
autocmd FileType c,cpp,fortran,matlab,python autocmd BufWritePre * :%s/\s\+$//e
" Use improved matching logic for Matlab.
autocmd FileType matlab source $VIMRUNTIME/macros/matchit.vim
autocmd FileType asciidoc,markdown,text set textwidth=0
autocmd FileType python set textwidth=79
autocmd FileType javascript,typescript set textwidth=120 tabstop=2 softtabstop=2 shiftwidth=2
augroup cpp_mode
if executable('clang-format')
autocmd FileType c,cpp setl formatprg=clang-format
endif
augroup end
endif
let fortran_do_enddo=1
let fortran_more_precise=1
let fortran_have_tabs=1
filetype plugin indent on
if has('syntax') && (&t_Co > 2)
syntax enable
endif
"============================== Shortcuts ==============================
" Use ,/ or ,# or ," or ,; or ,! or ,% to comment out a line (depending on what
" does the job) and use ,c to uncomment.
" The // and ! versions are built to respect leading whitespace and to ignore empty lines.
" All of these commands clear the search highlighting afterwards for cleanliness.
nnoremap ,/ :s/^\(\s*\)\(.\)/\1\/\/ \2/<CR>:noh<CR>
nnoremap ,# :s/^\(\s*\)\(.\)/\1#\2/<CR>:noh<CR>
nnoremap ," :s/^/"/<CR>:noh<CR>
nnoremap ,; :s/^/;/<CR>:noh<CR>
nnoremap ,! :s/^\(\s*\)\(.\)/\1!\2/<CR>:noh<CR>
nnoremap ,% :s/^/% /<CR>:noh<CR>
nnoremap ,c :s/^\(\s*\)\(\(\/\/\) \?\\|\(\#\)\\|\(\"\)\\|\(\;\)\\|\(\!\)\\|\(% \)\)/\1/<CR>:noh<CR>
" If using the above shortcuts and searching for multiple items to comment/
" uncomment, use this to search for the next desired item.
nnoremap ,n q/kk<CR>n
" Pasting from the web or an external source will use all my autoindent
" and the code will come up garbled. By pressing F2, I can enter <paste>
" mode, and all those will be ignored, and Ctrl+Shift+V will paste my
" buffer respecting its original form.
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
" Clear search highlighting.
nmap <F3> :noh<CR>
imap <F3> :noh<CR>i
" Switch on/off line numbering.
nmap <F4> :set number!<CR>
imap <F4> :set number!<CR>i
" Remove trailing whitespace.
nmap <F5> :%s/\s\+$//e<CR>
imap <F5> :%s/\s\+$//e<CR>i
" Spellchecking
" https://vim.fandom.com/wiki/Toggle_spellcheck_with_function_keys
let g:myLang=0
let g:myLangList=["nospell","en_us","de"]
function! ToggleSpell()
let g:myLang=g:myLang+1
if g:myLang>=len(g:myLangList) | let g:myLang=0 | endif
if g:myLang==0
setlocal nospell
else
execute "setlocal spell spelllang=".get(g:myLangList, g:myLang)
endif
echo "spell checking language:" g:myLangList[g:myLang]
endfunction
nmap <F6> :call ToggleSpell()<CR>
imap <F6> :call ToggleSpell()<CR>a
" Toggle tab width
let g:myTab = 0
function ToggleTag()
if g:myTab
set tabstop=4
set softtabstop=4
set shiftwidth=4
let g:myTab = 0
else
set tabstop=2
set softtabstop=2
set shiftwidth=2
let g:myTab = 1
endif
endfunction
nmap <F7> mz:execute ToggleTag()<CR>'z
imap <F7> mz:execute ToggleTag()<CR>'za
" Shortcut to make an if block in C. A more complicated/robust solution for
" Fortran allowing for more block types exists in
" ~/.vim/ftplugin/fortran_codecomplete.vim.
if has('autocmd')
autocmd FileType c,cpp nmap <F8> a<space>{<CR>}<ESC>O
autocmd FileType c,cpp imap <F8> <space>{<CR>}<ESC>O
autocmd FileType tex nmap <F8> o\begin{quotation}<CR>\end{quotation}<ESC>O
autocmd FileType tex imap <F8> <CR>\begin{quotation}<CR>\end{quotation}<ESC>O
endif
" Create nice brackets for a new scope and place the cursor in the middle.
nnoremap ,{ o{<ESC>o}<ESC>O
" If a line has been broken past where you want and you want to instead break
" at an earlier point, go to that point and try this.
nnoremap ,<CR> i<CR><ESC>$a<DEL><ESC>ldwi <ESC>
" Command line movement.
" https://statico.github.io/vim.html
cnoremap <C-a> <Home>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-d> <Delete>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
cnoremap <M-d> <S-right><Delete>
cnoremap <Esc>b <S-Left>
cnoremap <Esc>f <S-Right>
cnoremap <Esc>d <S-right><Delete>
" Alt-PageUp/Down to move between tabs.
nmap <M-PageUp> gT
imap <M-PageUp> <Esc>gT
nmap <M-PageDown> gt
imap <M-PageDown> <Esc>gt
"============================== Plugins ================================
" Pathogen easy plugin installer.
runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect()
" Syntastic syntax checker.
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list = 1
""let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 0
"let g:syntastic_check_on_wq = 0
"let g:syntastic_cpp_checkers = ['clang_check']
""let g:syntastic_clang_check_config_file = 1
"============================== Inactive ===============================
" Maintain 'persist' data, but keep my workspace clean
"set backup
"set backupdir=~/.vim/backup " previous versions of files are placed here
"set directory=~/.vim/tmp " .swp files, etc. are stored here
" Adjust title to include filename. Doesn't blend well with tabs.
"let &titlestring = "[vim(" . expand("%:t") . ")]"
"if &term == "screen"
" set t_ts=^[k
" set t_fs=^[\
"endif
"if &term == "screen" || &term == "xterm"
" set title
"endif