-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
370 lines (290 loc) · 7.42 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
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
370
" .vimrc
" By Yongheng Lin ([email protected])
" Main References:
" https://github.com/amix/vimrc
" =====================================
" Detect OS
let osname = substitute(system('uname'), '\n', '', '')[0:5]
if osname == 'Linux'
let os = 'linux'
elseif osname == 'Darwin'
let os = 'osx'
elseif osname == 'CYGWIN'
let os = 'cygwin'
else
let os = 'unknown'
endif
" =====================================
" General
" eliminate vi-compatibility
set nocompatible
" set the number of lines that are remembered
set history=500
" turn off backup
set nobackup
set nowritebackup
set noswapfile
" reload file changed outside
set autoread
" set encoding
set encoding=utf-8
" disable error bells
set noerrorbells
set novisualbell
set t_vb=
" set timeout length
set timeoutlen=500
" remap <leader>
let mapleader = ","
let g:mapleader = ","
let maplocalleader = ","
" toggle paste mode
map <leader>pp :setlocal paste!<CR>
" =====================================
" Display
" theme
colorscheme desert
set background=dark
" enable syntax highlighting
syntax enable
" display line number
set number
" toggle line number
map <leader>nn :set number!<CR>
" display 80th column
if exists('+colorcolumn')
set colorcolumn=80
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
highlight ColorColumn ctermbg=4
" set number of screen lines to use for the command-line
set cmdheight=2
" show status line
set laststatus=2
" =====================================
" File
" enable filetype plugins
filetype plugin on
filetype indent on
" set EOL format
set fileformats=unix,dos,mac
" prevent from expanding tab
autocmd FileType make setlocal noexpandtab
" treat .md file as .markdown file
au BufRead,BufNewFile *.md set filetype=markdown
" convert markdown to HTML
" nmap <leader>md :%!markdown % <CR>
" remove trailing whitespace on save
" function! RemoveTrailingWhitespace()
" exe 'normal mz'
" %s/\s\+$//ge
" exe 'normal `z'
" endfunction
" autocmd BufWritePre * :call RemoveTrailingWhitespace()
" save
nmap <leader>w :w!<CR>
" exit
nmap <leader>q :q<CR>
" save and exit
nmap <leader>wq :wq<CR>
" return to last edit position when opening file
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" remember info about open buffers on close
set viminfo^=%
" ======================================
" Navigation
" treat long lines as break lines
map j gj
map k gk
" keep cursor away from top and bottom
set scrolloff=5
" keep cursor centered after movement
nmap G Gzz
nmap n nzz
nmap N Nzz
nmap } }zz
nmap { {zz
" move between buffers
map <leader>h :bprevious<CR>
map <leader>l :bnext<CR>
" close buffer
map <leader>d :bdelete<CR>
" hide abandoned buffers
set hidden
" switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<CR>:pwd<CR>
" buffer switching behavior
try
set switchbuf=useopen,usetab,newtab
set showtabline=2
catch
endtry
" manage tabs
map <leader>tn :tabnew<CR>
map <leader>to :tabonly<CR>
map <leader>tc :tabclose<CR>
map <leader>tm :tabmove
" opens a new tab with the current buffer's path
map <leader>te :tabedit <C-R>=expand('%:p:h')<CR>/
" reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
vnoremap = =gv
" move cursors faster
nnoremap <C-j> 10j
nnoremap <C-k> 10k
nnoremap <C-h> b
nnoremap <C-l> w
" move lines
" nnoremap <C-d> :m .+1<CR>==
" nnoremap <C-u> :m .-2<CR>==
" inoremap <C-d> <Esc>:m .+1<CR>==gi
" inoremap <C-u> <Esc>:m .-2<CR>==gi
" vnoremap <C-d> :m '>+1<CR>gv=gv
" vnoremap <C-u> :m '<-2<CR>gv=gv
" =====================================
" Search
" search behavior
set hlsearch
set incsearch
set ignorecase
set smartcase
" search visually selected text
" http://vim.wikia.com/wiki/Search_for_visually_selected_text
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>
" search and replace visually selected text
" http://stackoverflow.com/a/676619
vnoremap <leader>r0 "hy:%s/<C-r>h//gc<left><left><left>
vnoremap <leader>r "hy:.,$s/<C-r>h//gc<left><left><left>
" remove highlighting
map <silent> <leader><CR> :noh<CR>
" set alias for '/' and '?'
map <Space> /
map <C-Space> ?
" =====================================
" Editing
" tab
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4
" space
set autoindent
set cindent
set wrap
" turn on the wild menu
set wildmenu
set wildignore=*.o,*~,*.pyc
" don't redraw while executing macros
set lazyredraw
" turn on magic for regular expression
set magic
" show matching bracket
set showmatch
set mat=2
" set line breaking behavior
set wrap
set linebreak
set nolist
" configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" create new line above/below
nmap gO O<ESC>j
nmap go o<ESC>k
" pair and ready for input
imap <leader>' ''<ESC>i
imap <leader>" ""<ESC>i
imap <leader>( ()<ESC>i
imap <leader>[ []<ESC>i
" yank and replace word
nmap <leader>yw yiw
nmap <leader>rw ciw<C-R>0<ESC>
" spell checking
map <leader>ss :setlocal spell!<cr>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
" ======================================
" Vundle
" set the runtime path to include Vundle and initialize
set rtp+=$HOME/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" plugins
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'bling/vim-airline'
Plugin 'kien/ctrlp.vim'
Plugin 'godlygeek/tabular'
Plugin 'epeli/slimux'
call vundle#end()
" ======================================
" Plugins
" NERDTree
autocmd bufenter *
\ if (winnr('$') == 1 && exists('b:NERDTreeType') &&
\ b:NERDTreeType == 'primary') | q |
\ endif
map <C-n> :NERDTreeToggle<CR>
" let NERDTreeMinimalUI = 1
" let NERDTreeDirArrows = 1
" NERDCommenter
let g:NERDDefaultAlign = 'left'
" vim-airline
if os == 'linux'
let g:airline_powerline_fonts = 0
let g:airline_left_sep = ''
let g:airline_right_sep = ''
else
let g:airline_powerline_fonts = 1
endif
" let g:airline_detect_whitespace = 0
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
" ctrlp.vim
let g:ctrlp_show_hidden = 1
" Tabular
nmap <leader>a= :Tabularize /=<CR>
vmap <leader>a= :Tabularize /=<CR>
nmap <leader>a: :Tabularize /:<CR>
vmap <leader>a: :Tabularize /:<CR>
nmap <leader>as :Tabularize / \+/l0<CR>
vmap <leader>as :Tabularize / \+/l0<CR>
nmap <leader>ao :Tabularize /<<<CR>
vmap <leader>ao :Tabularize /<<<CR>
" Slimux
map <leader>s :SlimuxREPLSendLine<CR>
vmap <leader>s :SlimuxREPLSendSelection<CR>
map <leader>a :SlimuxShellLast<CR>
map <leader>k :SlimuxSendKeysLast<CR>
" ======================================
" GUI
" set extra options when running in GUI mode
if has('gui_running')
set guioptions-=T
set guioptions+=e
set t_Co=256
set guitablabel=%M\ %t
if has('gui_gtk2')
set guifont=Inconsolata\ 12
elseif has('gui_win32')
set guifont=Consolas:h11:cANSI
endif
endif