forked from tianchaijz/dot-vimrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
326 lines (267 loc) · 9.5 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
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
" Sections:
" => Bundles
" => General
" => Text, tab and indent related
" => Colors and Fonts
" => Helper functions
" => Mappings
" => Buffers
" => Conversion
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Bundles
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
let $VIMHOME = $HOME . "/.vim"
let $BUNDLES = $VIMHOME . "/bundles.vim"
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#rc()
if filereadable($BUNDLES)
source $BUNDLES
endif
" Required!
filetype off
" Enable filetype plugins
filetype plugin on
filetype indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Encoding dectection
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
" Use Unix as the standard file type
set ffs=unix,dos,mac
" Enable syntax highlight and completion
syntax on
" Search
set incsearch
set ignorecase
set smartcase
set hlsearch
" Editor settings
set history=1000
set tm=2000 " leader key timeout
set nofoldenable " disable folding
set confirm " prompt when existing from an unsaved file
set backspace=indent,eol,start " more powerful backspacing
set t_Co=256 " explicitly tell vim that the terminal has 256 colors
set mouse=a " use mouse in all modes
set report=0 " always report number of lines changed
set wrap " wrap lines
set scrolloff=5 " 5 lines above/below cursor when scrolling
set number " show line numbers
set showmatch " show matching bracket (briefly jump)
set showcmd " show typed command in status bar
set title " show file in titlebar
set laststatus=2 " use 2 lines for the status bar
set matchtime=2 " show matching bracket for 0.2 seconds
set matchpairs+=<:> " specially for html
set lazyredraw " don't redraw while executing macros (good performance config)
set magic " for regular expressions turn magic on
set foldcolumn=1 " add a bit extra margin to the left
set backspace=eol,start,indent " it acts as it should act
set wildmenu " wildmenu
set wildmode=longest,list,full " tab complete files up to longest unambiguous prefix
set so=7 " set 7 lines to the cursor - when moving vertically using j/k
set cc=80 " color the 80th column
set foldmethod=syntax " fold by syntax
set clipboard=unnamed " copy selection to OS X clipboard
set whichwrap+=<,>,h,l
" Show trailing whitespace
set list
" But only interesting whitespace
if &listchars ==# 'eol:$'
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
endif
" Turn backup off, since most stuff is in Git anyway...
set nobackup
set nowb
set noswapfile
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autoindent
set smartindent " indent when
set tabstop=4 " tab width
set softtabstop=4 " backspace
set shiftwidth=4 " indent width
set expandtab " expand tab to space
set smarttab
set formatoptions+=mM
" Linebreak on 500 characters
set lbr
set textwidth=500
augroup lang_config
autocmd!
autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=80
autocmd FileType php setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120
autocmd FileType coffee,javascript,yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=80
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=80
autocmd FileType html,htmldjango,xhtml,haml setlocal tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType sass,scss,css setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=80
autocmd BufRead,BufNewFile *.tex setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=80 ft=tex
autocmd BufEnter Makefile setlocal noexpandtab
autocmd FileType mkd setlocal spell textwidth=80
autocmd Filetype gitcommit setlocal spell textwidth=72
autocmd BufRead,BufNewFile *.lua,*.c,*.py,*.sh,*.pl,*.rb,*.erb 2match Underlined /.\%81v/
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:solarized_termcolors = 256
let g:solarized_termtrans = 1
set background=dark
try
colorscheme solarized
catch
endtry
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! SetColorColumn()
let col_num = virtcol(".")
let cc_list = split(&cc, ',')
if count(cc_list, string(col_num)) <= 0
exe "set cc+=" . col_num
else
exe "set cc-=" . col_num
endif
endfunc
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
" MyNext() and MyPrev(): Movement between tabs OR buffers
func! MyNext()
if exists('*tabpagenr') && tabpagenr('$') != 1
normal gt
else
exe ":bnext"
endif
endfunc
func! MyPrev()
if exists('*tabpagenr') && tabpagenr('$') != '1'
normal gT
else
exe ":bprev"
endif
endfunc
func! Header(word, ...)
if exists("a:1") | let a:symbol = a:1 | else | let a:symbol = '#' | endif
if exists("a:2") | let a:width = a:2 | else | let a:width = 80 | endif
let a:inserted_word = ' ' . a:word . ' '
let a:word_width = strlen(a:inserted_word)
let a:length_before = (a:width - a:word_width) / 2
let a:hashes_before = repeat(a:symbol, a:length_before)
let a:hashes_after = repeat(a:symbol, a:width - (a:word_width + a:length_before))
let a:hash_line = repeat(a:symbol, a:width)
let a:word_line = a:hashes_before . a:inserted_word . a:hashes_after
:put =a:hash_line | :put =a:word_line | :put =a:hash_line
endfunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
cmap w!! w !sudo tee >/dev/null %
" Allow the normal use of "," by pressing it twice
noremap ,, ,
nnoremap ; :
noremap <leader>; ;
cmap WQ wq
cmap QA qa
inoremap jj <ESC>
if exists("$TMUX") == 0
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
endif
" Fix <Up> and <Down> keys inserting A B character
inoremap <Esc>OA <Esc>ki
inoremap <Esc>OB <Esc>ji
inoremap <Esc>OC <Right>
inoremap <Esc>OD <Left>
" Treat long lines as break lines (useful when moving around in them)
nnoremap j gj
nnoremap k gk
nnoremap <leader>hc :call SetColorColumn()<CR>
nnoremap <leader>dt :call DeleteTrailingWS()<CR>
" Force redraw
map <silent> \r :redraw!<CR>
" Toggle spell checking
map <leader>ss :setlocal spell!<CR>
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
" Open file prompt with current path
nmap <leader>e :e <C-R>=expand("%:p:h") . '/'<CR>
" Disable highlight when <leader><CR> is pressed
" But preserve cursor coloring
map <silent> <leader><CR> :noh<CR>:hi Cursor ctermbg=red guibg=red<CR>
" Mappings for translation of snippets between multi Vim
vnoremap <leader>tee :!tee /tmp/t<CR>
vnoremap <leader>cat :!cat /tmp/t<CR>
" Movement between tabs OR buffers
nnoremap Q :call MyPrev()<CR>
nnoremap W :call MyNext()<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Highlight current line
" autocmd WinLeave * set nocursorline nocursorcolumn
" autocmd WinEnter * set cursorline cursorcolumn
" set cursorline cursorcolumn
" Reload the buffer upon detecting change
set autoread
autocmd CursorHold,CursorHoldI * silent! checktime
" Clear column highlight theme
highlight clear SignColumn
" Delete trailing whitespace
augroup whitespace
autocmd!
autocmd BufWrite *.lua,*.pl,*.py,*.rb,*.md
\ :call DeleteTrailingWS()
augroup END
" Source the vimrc file after saving it
augroup sourcing
autocmd!
autocmd BufWritePost .vimrc source $MYVIMRC
augroup END
" Return to last edit position when opening files (You want this!)
augroup last_edit
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Conversion
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Convert symbol to string
nnoremap <silent> <leader>2s F:r"Ea"<Esc>
" Convert string to symbol
nnoremap <silent> <leader>2y F"r:,x
" Visual substitute
vmap ss y:%s/<C-R>"/g<left><left>/
" Convert name to snake_case
nmap <leader>2_ cr_
" Convert name to camelCase
nmap <leader>2c crc
" Convert name to MixedCase
nmap <leader>2m crm
" Convert name to SNAKE_UPPERCASE
nmap <leader>2u cru
" Convert name to dash-case
nmap <leader>2- cr-