-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
298 lines (237 loc) · 7.94 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
295
296
297
298
" Necessary for listchars to work in all environments.
scriptencoding utf-8
set encoding=utf-8
" Fix webpack watch.
set backupcopy=yes
" OSX you so silly
set backspace=2
" Try to stop saving backup files and swap files in the current folder.
set backupdir=~/.vim/backups,.
set directory=~/.vim/backups,.
" Enable modeline.
set modeline
set modelines=1
" Show (partial) command in the last line of the screen. Helps to see if you
" accidentally pressed any key.
set showcmd
let mapleader=","
" Number of lines to keep visible at the top/bottom.
set scrolloff=2
" Enable mouse interaction.
set mouse=a
" Enable line numbers.
set nu
" Increment numbers in decimal format, as you'd expect.
" Without this, Ctrl-A-ing on 07 would change to 10 because
" of the leading 0 that tells vim to increment in octal.
" From http://stackoverflow.com/questions/13273741/why-does-incrementing-with-ctrl-a-in-vim-take-me-from-07-to-10
set nrformats-=octal
" Enable Vundle.
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
syntax enable
" Tab length.
set tabstop=2
set sw=2
set sts=2
" Expand tab to spaces.
set expandtab
" Line length.
set tw=80
set wrap
" Highlight the line length limit.
if version >= 703
set cc=+1
endif
" Copy the indentation of the previous line when creating a new one.
set ai
" An indent is automatically inserted:
" - After a line ending in '{'.
" - After a line starting with a keyword from 'cinwords'.
" - Before a line starting with '}' (only with the "O" command).
" When typing '}' as the first character in a new line, that line is
" given the same indent as the matching '{'.
set cindent
set cinkeys-=0#
set indentkeys-=0#
" Syntax highlighting.
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'elzr/vim-json'
Plugin 'groenewege/vim-less'
Plugin 'ekalinin/Dockerfile.vim'
" Git.
Plugin 'tpope/vim-fugitive'
Plugin 'airblade/vim-gitgutter'
" File exploring.
Plugin 'junegunn/fzf.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'altercation/vim-colors-solarized'
Plugin 'vim-airline'
Plugin 'vim-airline/vim-airline-themes'
" All of the Vundle plugins must be added before this.
call vundle#end()
let g:solarized_termcolors=256
try
colorscheme solarized
catch
endtry
set background=dark
" Airline.
try
let g:airline_theme='solarized'
let g:airline_powerline_fonts = 1
let g:airline_extensions=[] " Disable the whitespace extension.
" Remove some of the noise.
let g:airline_section_b=airline#section#create(['branch'])
let g:airline_section_x=airline#section#create([])
let g:airline_section_y=airline#section#create([])
let g:airline_section_y=airline#section#create([])
catch
endtry
" Always show the status line.
set laststatus=2
" Enable auto completion in the command line.
set wildmenu
" Load indentation rules and plugins according to detected filetype.
" Also required by vundle.
filetype plugin indent on
" Per filetype-settings
" c/cpp modified by Deedee to match LLVM coding style
autocmd FileType c,cpp setlocal tw=80 sw=2 sts=2 tabstop=2
autocmd FileType java setlocal foldmethod=marker
autocmd FileType python setlocal expandtab
autocmd FileType php setlocal tw=80 sw=4 sts=4 tabstop=4
autocmd FileType html setlocal tw=0 cc=101 nowrap
autocmd FileType javascript setlocal sw=2 sts=2
autocmd FileType coffee setlocal sw=4 sts=4 tabstop=4
" +1: Try to break a line before the last one letter word.
autocmd FileType * set fo+=1
" Enable JSDoc syntax highlighting
let g:javascript_plugin_jsdoc = 1
" Remove trailing whitespaces
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
" Productivity shortcuts.
imap jk <Esc>
imap jj <Esc><Down>
imap kk <Esc><Up>
imap ggg <Esc>gg
nnoremap J <C-D>
nnoremap K <C-U>
" Select last pasted/modified text in the same visual mode
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" Highlight search results.
set hlsearch
" Incremental search: jumps to the first match while typing.
set incsearch
" Toggle search pattern highlighting.
nnoremap <leader>h :noh<CR>
" Fuzzy file find.
set rtp+=~/.fzf
" Make the fzf layout consistent with the one in the shell.
let g:fzf_layout = { 'down': '~40%' }
let $FZF_DEFAULT_OPTS = '--reverse --multi'
nnoremap <C-p> :Files<CR>
" Default options are --nogroup --column --color and they will be merged with
" the new options. Unfortunately there is no --nocolumn option so we're stuck
" with that.
" source: https://github.com/junegunn/fzf.vim/issues/273#issuecomment-267641703
let s:ag_options = '--smart-case --hidden --ignore .git'
" Enable quick preview for search results and use the options above.
command! -bang -nargs=* Ag
\ call fzf#vim#ag(
\ <q-args>,
\ s:ag_options,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0
\ )
" Search the entire project for the visual selection.
vnoremap <C-f> y:Ag<space><C-R>"<CR>
" When there's no visual selection you have to type your search pattern, or you
" can press enter and then type it to get fuzzy matches.
nnoremap <C-f> :Ag<space>
" Fuzzy search in all the open buffers.
nnoremap <C-g> :Lines<CR>
" Search and replace the current word under the cursor.
:nnoremap <leader>s :%s/\<<C-r><C-w>\>//g<Left><Left>
" Search and replace the current visual selection.
:vnoremap <leader>s y:%s/\<<C-R>"\>//g<Left><Left>
nnoremap <C-b> :Buffers<CR>
" Toggle git diff in the signs column.
nnoremap <leader>g :GitGutterToggle<CR>
" NERDTree
nnoremap <leader>n :NERDTreeFind<CR>
let NERDTreeQuitOnOpen = 1
let NERDTreeMapOpenSplit = "<C-x>"
let NERDTreeMapOpenVSplit = "<C-v>"
" Mark tabs and spaces
set list listchars=tab:»\ ,trail:·,extends:»,precedes:«
" Easy split navigation, source=vimbits.com
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Change default location for new splits
set splitbelow
set splitright
" Improve up/down movement on wrapped lines, source=vimbits.com
nnoremap j gj
nnoremap k gk
" Force saving files that require root, source=vimbits.com
cmap w!! %!sudo tee > /dev/null %
" Open a new vsplit and switch to it, source=stevelosh.com
nnoremap <leader>w <C-w>v<C-w>l
" Undo works after restarting vim, source=vimbits.com
if exists("+undofile")
" undofile - This allows you to use undos after exiting and restarting
" This, like swap and backups, uses .vim-undo first, then ~/.vim/undo
" :help undo-persistence
" This is only present in 7.3+
if isdirectory($HOME . '/.vim/undo') == 0
:silent !mkdir -p ~/.vim/undo > /dev/null 2>&1
endif
set undodir=./.vim-undo//
set undodir+=~/.vim/undo//
set undofile
endif
" Jump to last position when reopening file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Paste toggle so that pasted code isn't auto indented, source=vim.wikia.com
nnoremap <leader>p :set invpaste paste?<CR>
set pastetoggle=<leader>p
set showmode
" Rewrap a block of text
map <S-Q> gq
" Search for selected text, forwards or backwards.
" Ripped off from vim.wikia.com
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
" Paste from the clipboard the easy way
set clipboard=unnamed
" Apply macros to the visual selection. Doesn't stop on lines that don't match.
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction