-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_vimrc
370 lines (297 loc) · 13 KB
/
dot_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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
" John F. Mercer's VIMRC file
set nocompatible " Disable vi compatibility
" ================ Setup vim-plug ===================================
" Taken from: https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation-of-missing-plugins
" Install vim-plug if not found
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
" ================ Load vim plugins ===================================
call plug#begin('~/.vim/plugged')
Plug 'majutsushi/tagbar'
Plug 'Lokaltog/vim-easymotion'
Plug 'luochen1990/rainbow'
Plug 'Raimondi/delimitMate'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
" Plug 'scrooloose/syntastic'
Plug 'sickill/vim-monokai'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
" ================ End vim-plug Setup ===============================
" ================ General Config =================================
filetype plugin on " Enable filetype-specific plugins (required)
filetype indent on " Enable filetype-specific indenting (required)
syntax on " Enable syntax highlighting
set visualbell " Turn off bell
set number " Adds line numbers.
set hidden " Allows unwritten buffers to be hidden
set ruler " Show the cursor position all the time
set showmode " Show which mode are we in
set showmatch " Show matching brackets.
set cursorline " Highlight current line
set laststatus=2 " Always show the status line
set linespace=3 " Prefer a slightly higher line height
set noerrorbells " Disables the annoying beep
set lazyredraw " Don't update the display while executing macros
set history=1000 " Store lots of :cmdline history
set showcmd " Show incomplete cmds down the bottom
set showmode " Show current mode down the bottom
set gcr=a:blinkon0 " Disable cursor blink
set backspace=indent,eol,start "Allow backspace in insert mode
set encoding=utf-8
setglobal fileencoding=utf-8
set nrformats= " Treats all numbers as decimal, e.g., octal 06 is treated as decimal 6
set regexpengine=1 " For some reason, this boosts speed
" ================ Indentation and Whitespace ====================================
set autoindent " Always set autoindenting on
set smartindent
set smarttab
set tabstop=4 " Specifies the number of spaces that a tab equals
set shiftwidth=4 " Specifies the number of spaces to insert when using Normal Mode's indent function
set softtabstop=4 " Sets the number of spaces Backspace uses in Insert Mode
set expandtab " When enabled, specifies the uses of spaces instead of tab characters
set list " Show invisible characters
set listchars=tab:▸\ ,trail:· ",eol:¬ " Set appearance of invisible characters
set wrap " Wrap lines
set linebreak " Wrap lines at convenient points
" creates :Wrap: command, which quickly softwraps text
command! -nargs=* Wrap set wrap linebreak nolist
" The following specifies tab/whitespace settings for specific filetypes. autocmd & "filetype on" must be set
autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType html setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType css setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType javascript setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType java setlocal ts=3 sts=3 sw=3 expandtab
autocmd FileType php setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType c setlocal ts=3 sts=3 sw=3 expandtab
autocmd FileType lisp,scheme setlocal equalprg=scmindent
" Automatically strip trailing whitespaces on save
" This will really mess up git diffs unless the purpose of the commit
" is to fix whitespace
" autocmd BufWritePre *.py,*.js :call <SID>StripTrailingWhitespaces()
" ================ Folds ==========================================
set foldmethod=syntax "fold based on X
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
" ================ Search Settings ===============================
set incsearch "Find as you type the search
set hlsearch "highlight search results
set ignorecase "Case insensitive search
set smartcase "Case insensitive search (again)
" ================ Completion =====================================
set wildmode=list:longest
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*DS_Store*
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*.png,*.jpg,*.gif,*.pdf
" ================ rainbow parentheses ==========================
let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle
" ================ gvim font =====================================
set guifont=Menlo\ for\ Powerline:h18
" ================ Solarized Colorscheme Settings =================
" set t_Co=256 " Forces 256 colors, unneeded when TERM is already set to 256
" set background=dark
" `silent!` will keep vim from stalling on the colorscheme line during headless installs
" silent! colorscheme solarized
" ================ Monokai Colorscheme Settings =================
" set termguicolors
" `silent!` will keep vim from stalling on the colorscheme line during headless installs
silent! colorscheme monokai
" ================ Key Mappings ==================================
" *noremap prevents recursion in mappings
" ALWAYS use *noremap
" COMMANDS MODES
" noremap = Normal, Visual, Select, and Operator-pending
" nnoremap = Normal
" vnoremap = Visual and Select
" snoremap = Select
" xnoremap = Visual
" onoremap = Operator-Pending
" noremap! = Insert and Command-line
" inoremap = Insert
" lnoremap = Insert, Command-line, Lang-Arg
" cnoremap = Command-line
" Changes leader key from "\" to ","
let mapleader = ","
" Map Local Leader to \\
" This is used to prefix mappings specific to certain filetypes, such .js, .py, etc.
let maplocalleader = "\\"
" Examples of local mappings
" <localleader>c comments out a line in JavaScript
" :autocmd FileType javascript nnoremap <buffer> <localleader>c I//<esc>
" <localleader>c comments out a line in Python
" :autocmd FileType python nnoremap <buffer> <localleader>c I#<esc>
" This maps <ESC> to 'jk'
inoremap jk <esc>
" Toggle :set list!
nnoremap <leader>l :set list!<CR> " Shortcut to rapidly toggle `set list` with '<leader>l'
" Toggle highlighting :noh -> <leader><h>
noremap <silent> <leader>h :nohlsearch<CR><C-n>
" Toggle line numbers :set nu -> <leader><n>
noremap <silent> <leader>n :set nu!<CR><C-n>
" Fast vimrc editing
nnoremap <silent> <leader>ev :e $MYVIMRC<cr> " 'e'dit 'v'imrc
nnoremap <silent> <leader>sv :so $MYVIMRC<cr> " 's'ource 'v'imrc
" Fast path expansion of active buffer in command mode
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" Function Keys
set pastetoggle=<F2> " Toggle paste function for clipboard pasting
nnoremap <F3> :NERDTreeToggle<CR> " Toggle NERDTree
nnoremap <F4> :TagbarToggle<CR> " Toggle tagbar
" Disable Arrow Keys
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" This sets the movement keys to move by DISPLAY LINE rather than by
" PHYSICAL LINE. In other words, the keys won't be all screwy.
" Note that to move by PHYSICAL LINE I must use gj, gk, etc.
" Basically, this changes vim's original gj to j, gk to k, & vice-versa.
nnoremap k gk
nnoremap j gj
nnoremap gk k
nnoremap gj j
" WINDOW CYCLING
" These make cycling between windows easier & faster.
" Instead of Control-w h, you just hit Control-h
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" ================ Window Settings ==============================
set splitright " This sets vertical split windows to open on the right rather than the left.
set splitbelow " This sets horizontal split windows to open below rather than above.
" ================ Turn Off Swap Files ===========================
set noswapfile
set nobackup
set nowb
" ================ Persistent Undo ===============================
" Keep undo history across sessions, by storing in file.
" Only works all the time.
" silent !mkdir ~/.vim/backups > /dev/null 2>&1
" set undodir=~/.vim/backups
" set undofile
" ================ Scrolling =====================================
set scrolloff=8 "Start scrolling when we're 8 lines away from margins
set sidescrolloff=15
set sidescroll=1
" ================ Omnicomplete ==================================
" This is mostly syntax highlighting. See :help ft-syntax-omni
set omnifunc=syntaxcomplete#Complete " Turn on omnicomplete
" Use CTRL-X CTRL-O in Insert mode to start the completion.
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
" Adds HTML and JS highlighting to PHP files
let g:omni_syntax_group_include_php = 'php\w\+,javaScript\w\+,html\w\+'
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType java set omnifunc=javacomplete#Complete
autocmd Filetype java setlocal completefunc=javacomplete#CompleteParamsInfo
" ================ NERDTree Settings ======================================
" Open NERDTree on startup
" autocmd vimenter * NERDTree
" Open NERDTree on startup EVEN IF no files were specified
" autocmd StdinReadPre * let s:std_in=1
" autocmd vimenter * if !argc() | NERDTree | endif
" Close vim even if the only window left open is NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" ================ vim-airline Settings ======================================
let g:airline#extensions#tabline#enabled=1 " Automatically displays all buffers when there's only one tab open.
let g:airline_powerline_fonts = 1 " Use powerline fonts
if !exists('g:airline_symbols') " Helps with powerline font rendering
let g:airline_symbols = {}
endif
let g:airline_symbols.space = "\ua0"
" ================ Syntastic Settings =========================================
" 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 = 1
" let g:syntastic_check_on_wq = 0
" Custom file checker configurations
" Cf. https://github.com/scrooloose/syntastic/wiki/Syntax-Checkers
" let g:syntastic_php_checkers = [] " Disables checking of php files
" let g:syntastic_php_checkers = ["php", "phpcs", "phpmd"] " Activate php, phpcs, & phpmd
" Get information about current buffer
" :SyntasticInfo
" ================ vimscript functions =========================================
" :Stab
" Set tabstop, softtabstop and shiftwidth to the same value
command! -nargs=* Stab call Stab()
function! Stab()
let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
if l:tabstop > 0
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
endif
call SummarizeTabs()
endfunction
" :SummarizeTabs
" Display tab and space settings
command! -nargs=* SummarizeTabs call SummarizeTabs()
function! SummarizeTabs()
try
echohl ModeMsg
echon 'tabstop='.&l:ts
echon ' shiftwidth='.&l:sw
echon ' softtabstop='.&l:sts
if &l:et
echon ' expandtab'
else
echon ' noexpandtab'
endif
finally
echohl None
endtry
endfunction
" :Strip
" Strip Trailing Whitespace
command! -nargs=* Strip call <SID>StripTrailingWhitespaces()
function! <SID>StripTrailingWhitespaces()
" 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
" ================ Notes =========================================
" Old Status Line setting
" set stl=%f\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\ [%b][0x%B]
" Use the same symbols as TextMate for tabstops and EOLs
" set listchars=tab:▸\ ,eol:¬
" vim -o file.one file.two on the commandline will open a series
" of files in horizontal windows
" NEW WINDOWS
" :new opens a horizontal window
" :vnew opens a vertical window