-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
325 lines (252 loc) · 11 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
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
source ~/.vim/funcs.vim
Bundle 'JazzCore/vundle'
Bundle 'JazzCore/ctrlp-cmatcher'
Bundle 'JazzCore/UltiSnips-Snippets'
Bundle 'JazzCore/vim-hybrid'
Bundle 'JazzCore/vim-python-syntax'
Bundle 'JazzCore/vim-space'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-endwise'
Bundle 'tpope/vim-markdown'
Bundle 'tpope/vim-unimpaired'
Bundle 'tpope/vim-repeat'
"Bundle 'tpope/vim-vinegar'
" this one sets shiftwidth and tabstop automatically
Bundle 'tpope/vim-sleuth'
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/nerdcommenter'
Bundle 'kien/ctrlp.vim'
Bundle 'tacahiroy/ctrlp-funky'
"Bundle 'mileszs/ack.vim'
Bundle 'Raimondi/delimitMate'
Bundle "myusuf3/numbers.vim"
Bundle 'SirVer/ultisnips'
Bundle 'maxbrunsfeld/vim-yankstack'
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
" Disable menu translation
set langmenu=none
if has('win32')
source $VIMRUNTIME/mswin.vim
behave mswin
endif
" Set directories for temp and swap files.
" Make them manually
set backupdir=~/.vim/backup//
set directory=~/.vim/swap//
set undodir=~/.vim/undo//
" Make those folders automatically if they don't already exist.
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
set undofile
set undolevels=2000
set undoreload=10000
set history=1000 " remember more commands and search history
syntax on " syntax highlight
set number " Enable num lines
set autoread " auto read when file is changed from outside
set encoding=utf-8 " this options breaks menu encoding, so we disabling menu translation
set fileencoding=utf-8
set fencs=utf-8,cp1251,koi8-r,cp866 " encodings by default
set hlsearch " search highlighting
set autoindent " auto indentation
set incsearch " incremental search
set nobackup " no *~ backup files
set copyindent " copy the previous indentation on autoindenting
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to context
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set formatoptions+=r " automatic formatting: auto insert current comment leader after enter
set hidden " put unsaved buffers in the background
set wrap " don't wrap lines
set linebreak " don't wrap inside word
set tabstop=4 " a tab is four spaces
set softtabstop=4 " when hitting <BS>, pretend like a tab is removed, even if spaces
set expandtab " expand tabs by default (overloadable per file type later)
set shiftwidth=4 " number of spaces to use for autoindenting
set foldlevel=100 " Don't autofold anything (but I can still fold manually)
set foldopen=block,hor,mark,percent,quickfix,tag " what movements open folds
set shortmess+=filmnrxoOtTc " Abbrev. of messages (avoids 'hit enter'), disable completion messages
"colorscheme mustang
colorscheme hybrid
set background=dark " Assume a dark background
highlight clear SignColumn " SignColumn should match background for things like vim-gitgutter
set showcmd " Show partial commands in status line and selected characters/lines in visual mode
set scrolloff=3 " Minimum lines to keep above and below cursor
set backspace=indent,eol,start " Make backspace delete lots of things
set showmatch " show matched braces
set fileformat=unix " file mode is unix
set fileformats=unix,dos,mac " detects unix, dos, mac file formats in that order
set mousemodel=popup_setpos " Right-click on selection should bring up a menu
set list listchars=tab:»·,precedes:<,extends:> " Make tabs visible. This disables 'wrap'. See g:List_toggle() below
set wildmode=longest,list,full
set wildmenu
set wildignore=*.swp,*.bak,*.pyc,*.pyd,*.class
set pastetoggle=<F2>
set virtualedit=block
set noerrorbells
set novisualbell
set t_vb=
set tm=500
set splitright
set nrformats-=octal
set lazyredraw
"highlight word under cursor
"autocmd CursorMoved * silent! exe printf("match Search /\\<%s\\>/", expand('<cword>'))
if has('gui')
" disable graphical tabs
set guioptions-=e
" disable icons
set guioptions-=T
" disable menu
set guioptions-=m
if has('win32')
" This a patched Consolas for Powerline, from
" https://github.com/nicolalamacchia/powerline-consolas
set guifont=Consolas:h10
else
set guifont=Droid\ Sans\ Mono\ for\ Powerline\ 9
endif
endif
" Look for tag def in a "tags" file in the dir of the current file, then for
" that same file in every folder above the folder of the current file, until the
" root.
set tags=./tags;/
" Set the status line
set statusline=%<%F " File path
set statusline+=\ %2*%{&ro?'RO':''}%*%4*%{&mod?'+':''}%<%* " RO and modification flags. %2 - red, %4 - green
set statusline+=%3*\ %{matchstr(fugitive#statusline(),'(\\zs.*\\ze)')}%* " Fugitive flag. %3 - orange
set statusline+=%=\ %{&fileformat}\ \| " Remaining items are right-aligned. File format
set statusline+=%{&fileencoding}\ \| " Encoding
set statusline+=%{&filetype}\ \| " filetype
set statusline+=%p%%\ \| " % of document
set statusline+=%l:%c\ " Line num and col
" tell VIM to always put a status line in, even if there is only one window
set laststatus=2
" We need to update this colors to match stl background color of the new theme
autocmd ColorScheme * silent! call g:SetSTLColors()
call g:SetSTLColors()
" Highlight trailing whitespace (but not in insert mode)
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
augroup extra_whitespace
autocmd!
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
augroup END
" Filetype-specific settings
autocmd FileType python setlocal colorcolumn=80
" ==================== Mappings ======================
" System default for mappings is now the "," character
let mapleader = ","
nnoremap ; :
" Using '<' and '>' in visual mode to shift code by a tab-width left/right by
" default exits visual mode. With this mapping we remain in visual mode after
" such an operation.
vnoremap < <gv
vnoremap > >gv
nnoremap <silent> j gj
nnoremap <silent> k gk
" Change Working Directory to that of the current file
cmap cwd lcd %:p:h
cmap cd. lcd %:p:h
" Toggle search highlighting
nmap <silent> <leader>/ :set invhlsearch<CR>
" Edit the vimrc file
nmap <silent> ,ev :e $MYVIMRC<CR>
nmap <silent> ,sv :so $MYVIMRC<CR>
" Map <Leader>ff to display all lines with keyword under cursor
" and ask which one to jump to
" TODO ,ff conficts with vim-easymotion
"nmap <Leader>ff [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR>
" ,f for global git serach for word under the cursor (with highlight)
"nmap <leader>f :let @/="\\<<C-R><C-W>\\>"<CR>:set hls<CR>:silent Ggrep -w "<C-R><C-W>"<CR>:ccl<CR>:cw<CR><CR>
" Toggle search highlighting
nmap <silent> <leader>/ :set invhlsearch<CR>
" For when you forget to sudo.. Really Write the file.
cmap w!! w !sudo tee % >/dev/null
nnoremap <F1> <ESC>
inoremap <F1> <ESC>
vnoremap <F1> <ESC>
" easily insert an escaped / on the search prompt
"cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/'
" map control-backspace to delete the previous word in insert mode
" imap <C-BS> <C-W>
inoremap <C-BS> <C-W>
" and map control-delete to delete the next word in insert mode
inoremap <C-Del> <C-O>dw
nnoremap & :&&<CR>
xnoremap & :&&<CR>
" Make Y consistent with C and D. See :help Y.
nnoremap Y y$
" Unfortunately, visible tabs require 'list', which makes soft word wrap behave
" badly. So it should be toggleable.
noremap <F8> :call g:List_toggle()<CR>
noremap! <F8> <Esc>:call g:List_toggle()<CR>a
" ==================== CtrlP ====================
" funky adds functions definitions mode to CtrlP
let g:ctrlp_extensions = ['tag', 'funky']
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$',
\ 'file': '\.exe$\|\.so$\|\.dll$' }
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
\ 2: ['.hg', 'hg --cwd %s locate -I .'],
\ }
\ }
nnoremap <C-l> :CtrlPMRUFiles<CR>
" ==================== TagBar ====================
" toggle Tagbar display
map <F4> :TagbarToggle<CR>
" autofocus on Tagbar open
let g:tagbar_autofocus = 1
" ==================== Fugitive ====================
nnoremap <silent> <leader>gs :Gstatus<CR>
nnoremap <silent> <leader>gd :Gdiff<CR>
nnoremap <silent> <leader>gc :Gcommit<CR>
nnoremap <silent> <leader>gb :Gblame<CR>
nnoremap <silent> <leader>gl :Glog<CR>
nnoremap <silent> <leader>gp :Git push<CR>
" ==================== vim-session ====================
let g:session_autosave = 1
let g:session_autoload = 1
" ==================== Ack.vim ====================
" Make ack.vim use Ag (silver searcher ) instead of ack
let g:ackprg = 'ag --nogroup --nocolor --column'
" ==================== UltiSnips ====================
let g:ultisnips_python_style = "sphinx"
let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips-snippets"]
let g:UltiSnipsDontReverseSearchPath=1
let g:UltiSnipsExpandTrigger = '<C-CR>'
let g:UltiSnipsJumpForwardTrigger = '<C-d>'
let g:UltiSnipsJumpBackwardTrigger = '<C-a>'
" ==================== YouCompleteMe ====================
" Disable completion previews with function prototypes, etc.
set completeopt=menu
let g:ycm_add_preview_to_completeopt = 0
"let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_complete_in_comments_and_strings = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
" ==================== EasyMotion ====================
" maps: <leader> and f,F,e,E,w,W,ge,gE,j,k,n,N,t,T,b,B
let g:EasyMotion_leader_key="<Leader>"
" ==================== Python-syntax ====================
" Highlight all python syntax
let g:python_highlight_all = 1