-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
275 lines (227 loc) · 7.96 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
source ~/.vim/vundle_setup.vim
" tabs and such
set number " number lines
set autoindent " autoindent
set softtabstop=4 " soft tabstop
set cindent " c-indenting
set shiftwidth=4 " ai indent width
set tabstop=4 " normal tabstop
set expandtab " convert tabs to spaces
if has("gui_running")
" window size
set lines=50
set columns=150
endif
" pathogen plugin loading for all plugins in ~/.vim/bundle
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
" autoindent thing (meant to be used with autoclose v1.2 with line 88 commented out)
inoremap {<CR> {<CR>}<Esc>O
nnoremap \) i)<Esc>
nnoremap \( i(<Esc>
noremap \_ xi()<Esc>[p
nnoremap \] i]<Esc>
nnoremap \[ i[<Esc>
noremap \- xi[]<Esc>[p
nnoremap \} i}<Esc>
nnoremap \{ i{<Esc>
noremap \0 xi{}<Esc>[p
noremap \" xi""<Esc>[p
noremap \' xi''<Esc>[p
inoremap ,( (
inoremap ,{ {
inoremap ,[ [
inoremap ,) )
inoremap ,} }
inoremap ,] ]
" remap arrow keys to buffer stuff - arrows will switch between windows, shift+arrow keys switch between buffers/tabs
noremap <silent> <up> :wincmd k<CR>
noremap <silent> <down> :wincmd j<CR>
noremap <silent> \j :wincmd j<CR>
noremap <silent> <right> :wincmd l<CR>
noremap <silent> <left> :wincmd h<CR>
noremap <silent> <S-right> :bnext<CR>
noremap <silent> <S-left> :bprevious<CR>
noremap <silent> <S-down> :tabprevious<CR>
noremap <silent> <S-up> :tabnext<CR>
" Alt (option) + arrow keys = toggle minibufexplorer and nerdtree
noremap <silent> <M-up> :CMiniBufExplorer<CR>
noremap <silent> <M-down> :MiniBufExplorer<CR>
noremap <silent> <M-left> :NERDTreeClose<CR>
noremap <silent> <M-right> :NERDTree<CR>
" Backups
set backup " keep a backup file
set writebackup " more of the same
set bdir=./.undobak,. " set the backup-directory
set bex=~ " set the backup-extension
" misc
"set ruler " status line below handles this now " show the cursor position, alt:noruler
set history=100 " set history size to 100
set autoread " check file is changed externally and auto-reload
set title " show filename in terminal titlebar
set ttyfast " make responsive
set scrolloff=3 " Always keep three lines above or below the cursor
set nocompatible " Keep vim from trying to be 100% vi compatible
" Use j and k to move down and up _logical_ lines instead of line-break lines
nnoremap j gj
nnoremap k gk
" Enable filetype plugin
filetype plugin on
filetype indent on
" wildmenu and tabcompletion stuff
set wildmenu " Pretty command-line option matching
set wildmode=list:longest " Shell-style matching
set wildignore=*.bak,*.o,*.e,*~,*.pyc,*.exe
" 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,.class,.pyc
" Colors and Highlighting
set t_Co=256 " turn on 256 color mode
set showmatch " highlight matching brace
set cursorline " turn on the cursor line
colorscheme myNewDesertEx " use this color scheme
syntax on " syntax highlighing
" Search
set hlsearch " highlight search result
set ignorecase " case insensitive
set smartcase " smart case sensitivity in search
set incsearch " incremental searching
set infercase " more clever case search stuff
set backspace=indent,eol,start " not really sure
" map shortcut to open vimrc
noremap <silent> ,v :e $MYVIMRC<cr>
" Status line
set ls=2
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] "\ \ \ \ \ \ \ \ %{VimBuddy()}
" vim-latex/grep stuff
set grepprg=grep\ =nH\ $* " show file and line number apparently
let g:tex_flavor='latex'
" bind noh to C-h
noremap <silent> <C-h> :nohlsearch<CR>
" set up spellcheck
set spl=en_ca
noremap <silent> \ss :setlocal spell!<CR>
" exhuberant ctags
command! Ctags Gentags
command! Gentags !/usr/local/bin/ctags -R .
" use already-open window for buffer if possible
set switchbuf=useopen
" :W remaps to :w because I sometimes do :W by accident. also Q, WQ, QA, and WQA
command! W w
command! Q q
command! WQ wq
command! Wq wq
command! WQA wqa
command! WQa wqa
command! QA qa
command! Qa qa
" :reconf reloads vimrc because i do that sometimes
command! Reconf :source $MYVIMRC
" \ma opens makefile in current directory
noremap <silent> \ma :e Makefile<CR>
" ,sa runs current file as script
noremap <silent> ,sa :source %<CR>
" ,tl toggles taglist
noremap <silent> ,tl :Tlist<CR>
" NERDCommenter prefs
let NERDCompactSexyComs=1
let NERDSpaceDelims=1
let NERD_c_alt_style=1
" let NERD_cpp_alt_style=1
" let NERD_java_alt_style=1
map ,cc \cc
map ,ci \ci
map ,cs \cs
map ,cu \cu
map ,cm \cm
" automatically write file when switching buffers
set autowrite
" persistent undo
if v:version >= 703 && has("persistent_undo")
set undofile
set undodir=./.undobak
endif
" make undobak directory
command! Makeundobak !mkdir .undobak
" load abbreviations
if filereadable("~/.vim/abbr.vim")
so ~/.vim/abbr.vim
endif
" open abbrevations file
command! Abbr e ~/.vim/abbr.vim
" swap files
set directory=./.undobak,.
" delete backup files in current directory
command! Delback !rm *~
" disable auto eol for last line
function! NOEOL()
setlocal noeol
setlocal binary
endfunction
command! NoEOL call NOEOL()
" local tags files
if isdirectory('./.undobak')
let g:easytags_file = './.undobak/easytags'
else
let g:easytags_file = '~/.vimtags'
endif
set tags=~/.vimtags,~/vimtags,./tags,./.tags,./.undobak/tags,./.undobak/.tags,./.undobak/easytags
" highlight end of line whitespace and use <leader><space> to delete it all
augroup EOLWS
autocmd!
autocmd InsertEnter * syn clear EOLWS | syn match EOLWS excludenl /\s\+\%#\@!$/
autocmd InsertLeave * syn clear EOLWS | syn match EOLWS excludenl /\s\+$/
highlight EOLWS ctermbg=red guibg=red
augroup end
function! <SID>StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nnoremap <silent> <Leader><space> :call <SID>StripTrailingWhitespace()<CR>
" map tab and shift-tab to go to next and previous function, respectively
nnoremap <silent> <Tab> ]]
nnoremap <silent> <S-Tab> [[
set virtualedit+=block " allow selecing after line end in visual block mode
" show quickfix window for current search with <leader>g:
nnoremap <silent> <leader>g :execute 'vimgrep /'.@/.'/g %'<CR>:copen<CR>
" easier quickfix navigation
nnoremap <silent> Q :copen<CR>
nnoremap <silent> ]q :cnext<CR>
nnoremap <silent> [q :cprevious<CR>
" ascii underlines
nnoremap ,u yypVr-
nnoremap ,U yypVr=
" highlight lines longer than 80 characters
let g:over_length_highlighting = 0
function! HighlightLongLines()
if g:over_length_highlighting
let g:over_length_highlighting = 0
highlight clear OverLength
return
endif
let g:over_length_highlighting = 1
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/
endfunction
nnoremap <silent> ,ll :call HighlightLongLines()<CR>
" Find next line longer than 80 characters
nnoremap ,nll /\%81v.\+/<CR>
" jk escape
inoremap <silent> jk <Esc>
" Use ,y and ,p to mirror y and p, but read/write to a file (~/.vimglobalregister) in order to enable cross-vim instance copy/pasting.
" map <silent> ,y y:call writefile([@0], expand("~/.vimglobalregister"))<CR>
" map <silent> ,p :let @0 = join(readfile(expand("~/.vimglobalregister")), "\n")<CR>p
" on systems with X (and xclip and xsel), use these instead of the above to integrate directly with the X clipboard.
map <silent> ,y y:call writefile([@0], expand("~/.vimglobalregister"))<CR>:call system("sed 's/\\x00/\\n/g' < ~/.vimglobalregister \| xclip")<CR>
map <silent> ,p :call system("xsel > ~/.vimglobalregister")<CR>:let @0 = join(readfile(expand("~/.vimglobalregister")), "\n")<CR>p
" better color scheme for diffing
if &diff
colorscheme greens
endif