-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
282 lines (234 loc) · 11.9 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
"Auto reload vimrc
augroup reloadvimrc " {
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END " }
"KEY MAPPINGS
"Leader Key
let mapleader=","
"Use Tab to switch windows
map <Tab> <C-W>w
"Use leader key + ee to edit vimrc
nnoremap <silent> <leader>ee :e $MYVIMRC<CR>
"Use leader key + ev to edit vimrc by splitting into a new window vertically
nnoremap <silent> <leader>ev :vsplit $MYVIMRC<CR>
"Use leader key + b to build ctags then set to update tag list automatically after each saving, assume that ctags has been installed into OS and .ctags file exists in Home directory
nnoremap <silent> <leader>b :!ctags<CR><CR> <bar> :autocmd BufWritePost * call system("ctags")<CR>
"Use // to search for visually selected text
vnoremap // y/<C-R>"<CR>
"Use SPACE to open a fold at the cursor in normal mode
nnoremap <space> zo
"Use leader key + SPACE to open all fold in normal mode
nnoremap <leader><space> zR
"Use leader key + w to close one tab
nnoremap <leader>w :tabc<CR>
"Use . to delete without cutting or copying (save to the black hole sregister)
noremap . "_d
"Use C-h and C-l to move to the left and right
nnoremap <c-h> 20h
nnoremap <c-l> 20l
"Move cursor in Insert mode
inoremap <c-h> <left>
inoremap <c-l> <right>
"Use leader key + p or P to paste from system clipboard
nnoremap <leader>p "+p
nnoremap <leader>P "+P
"Vim SETTINGS
set hlsearch "Set highlight searching
set number relativenumber "Vim starts with line numbers and relative number enabling
set numberwidth=4 "Setting number of spaces between line numbers and codes
set autoindent
set tabstop=4 "Setting tab width
set shiftwidth=4 "Setting indent
set statusline+=%F "Setting visible status line
set expandtab "Using spaces instead of tab
set ttyfast "make vim scrolls more smoothly, assume fast connection
set ttyscroll=0 "don't know why but this make smooth scroll much better when scroll down (no ghost cursor lines when scrolling down from the last line; no delay cursorline when scrolling down from somewhere in the middle. This will disable scrolling when set mouse=a
set mouse=a "enable using the mouse
set backspace=indent,eol,start "allow backspacing everything in insert mode
" set foldmethod=marker "enable folding triggered by markers (the {{{ things)
syntax on
set fillchars=vert:\│ "continuous vertical split line
set cursorline "highlight cursor line to easily spot the cursor
set viminfo+=n~/.vim/viminfo "specify the place of viminfo
set noshowmode "show mode using only airline, no need to show below it
set ignorecase "case-insensitive searching
set smartcase "search pattern contains uppercase => case-sensitive, and vice versa
"PLUGGINS using Vim-plug
call plug#begin('~/.vim/plugged') "Pluggins START
Plug 'scrooloose/nerdtree' "Directory tree of projects
"Use F4 for NERDTree toggling
nnoremap <F4> :NERDTreeToggle<CR>
let g:NERDTreeWinSize = 35 "Set NERDTree sidebar width
autocmd VimEnter * NERDTree "Open NERDTree at startup
" autocmd VimEnter * wincmd p "Move cursor to main window at opening
Plug 'majutsushi/tagbar' "Show functions, variables, etc. of a file
"Use F3 for Tagbar opening
nnoremap <F3> :TagbarToggle<CR>
let g:tagbar_sort = 0 "Sort tags according to their orders in file
" let g:tagbar_width = 35
Plug 'haya14busa/incsearch.vim' "Searching
" auto disable highlight after searching (by moving cursor)
let g:incsearch#auto_nohlsearch = 1
" If cursor is in first or last line of window, scroll to middle line.
function! s:MaybeMiddle()
let l:range=2
if winline() < 1 + l:range || winline() > winheight(0) - l:range
normal! zz
endif
endfunction
map <silent> n <Plug>(incsearch-nohl-n):call <SID>MaybeMiddle()<CR>
map <silent> N <Plug>(incsearch-nohl-N):call <SID>MaybeMiddle()<CR>
" add N for disabling moving cursor
map * <Plug>(incsearch-nohl-*)N
map # <Plug>(incsearch-nohl-#)N
map g* <Plug>(incsearch-nohl-g*)N
map g# <Plug>(incsearch-nohl-g#)N
let s:center_module = {"name": "Center"}
function! s:center_module.priority(event) abort
return a:event is# "on_char" ? 999 : 0
endfunction
function! s:center_module.on_leave(cmdline) abort
if exists("s:center_on_leave_flag")
unlet s:center_on_leave_flag
normal! zz
endif
endfunction
function! s:center_module.on_char_pre(cmdline) abort
if a:cmdline.is_input("<Over>(center)")
call a:cmdline.setchar("")
endif
endfunction
function! s:center_module.on_char(cmdline) abort
if a:cmdline.is_input("<Over>(center)")
normal! zz
let s:center_on_leave_flag = 1
endif
endfunction
function! s:config_center(...) abort
return extend(copy({
\ "modules": [s:center_module],
\ "keymap": {
\ "\<Tab>": {
\ "key": "<Over>(incsearch-next)<Over>(center)",
\ "noremap": 1
\ },
\ "\<S-Tab>": {
\ "key": "<Over>(incsearch-prev)<Over>(center)",
\ "noremap": 1
\ }
\ },
\ "is_expr": 0
\ }), get(a:, 1, {}))
endfunction
noremap <silent><expr> / incsearch#go(<SID>config_center({"command": "/"}))
noremap <silent><expr> ? incsearch#go(<SID>config_center({"command": "?"}))
noremap <silent><expr> g/ incsearch#go(<SID>config_center({"command": "/", "is_stay": 1}))
Plug 'chiel92/vim-autoformat' "Autoformat code: indentation, etc.
"Use F5 for autoformat
noremap <F5> :Autoformat<CR>
" Plug 'valloric/youcompleteme', { 'on': [], 'do': './install.py' } "Autocompletion
Plug 'valloric/youcompleteme' "Autocompletion
let g:ycm_key_list_select_completion=['<C-j>', '<Down>']
let g:ycm_key_list_previous_completion=['<C-k>', '<Up>']
Plug 'tomtom/tcomment_vim' "Used to comment code
Plug 'terryma/vim-smooth-scroll' "Used to move in a file easily
nnoremap <silent> <c-p> :call smooth_scroll#up(&scroll/2 ,20 ,1)<CR>
nnoremap <silent> <c-n> :call smooth_scroll#down(&scroll/2 ,20 ,1)<CR>
nnoremap <silent> <c-u> :call smooth_scroll#up(&scroll ,20 ,2)<CR>
nnoremap <silent> <c-d> :call smooth_scroll#down(&scroll ,20 ,2)<CR>
nnoremap <silent> <c-b> :call smooth_scroll#up(&scroll*2 ,20 ,2)<CR>
nnoremap <silent> <c-f> :call smooth_scroll#down(&scroll*2 ,20 ,2)<CR>
Plug 'sjl/gundo.vim' "Undo history
let g:gundo_right = 1 "move the tree to the right
nnoremap <F2> :GundoToggle<CR>
Plug 'SirVer/ultisnips' "Forming funtion syntax: name, parentheses, indentation, etc.
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
Plug 'honza/vim-snippets' "Give SilVer/ultiships database to process
Plug 'jszakmeister/vim-togglecursor' "toggle cursor shape in insert mode, but only useful in some terminals
let g:togglecursor_leave = "line"
let g:togglecursor_force = "cursorshape" "Assume the terminal is Konsole
Plug 'klen/python-mode' "More differentiate colors between portions of code
let g:pymode_folding = 0
let g:pymode_lint_on_write = 0
let g:pymode_rope = 0
let g:pymode_options = 0
Plug 'tpope/vim-fugitive' "show git branches on airline
Plug 'jiangmiao/auto-pairs' "auto brackets
let g:AutoPairsMapCh = 0 "unmap <C-h> to delete brackets, quotes in pair
Plug 'Shougo/unite.vim' "interface for searching
"Unite Settings
function! s:unite_my_settings()"{{{
nmap <buffer> <esc> <Plug>(unite_exit)
nmap <buffer> <C-p> <Plug>(unite_toggle_auto_preview)
nmap <buffer> <C-j> <Plug>(unite_loop_cursor_down)
nmap <buffer> <C-k> <Plug>(unite_loop_cursor_up)
nmap <buffer> <C-z> <Plug>(unite_toggle_mark_current_candidate)
nnoremap <silent><buffer><expr> <C-o> unite#do_action('switch')
nnoremap <silent><buffer><expr> <C-s> unite#do_action('split')
nnoremap <silent><buffer><expr> <C-v> unite#do_action('vsplit')
imap <buffer> <esc> <plug>(unite_exit)
imap <buffer> <C-p> <Plug>(unite_toggle_auto_preview)
imap <buffer> <C-j> <Plug>(unite_select_next_line)
imap <buffer> <C-k> <Plug>(unite_select_previous_line)
imap <buffer> <C-z> <Plug>(unite_toggle_mark_current_candidate)
inoremap <silent><buffer><expr> <C-o> unite#do_action('switch')
inoremap <silent><buffer><expr> <C-s> unite#do_action('split')
inoremap <silent><buffer><expr> <C-v> unite#do_action('vsplit')
endfunction"}}}
autocmd FileType unite call s:unite_my_settings()
"Use leader key + r to search for file names in current directory using Unite file_rec source
nnoremap <leader>r :<C-u>Unite -auto-resize -start-insert file_rec<CR>
"Use leader key + l to build a file list used for Unite file_list source
nnoremap <leader>l :!find . -iname '*.h' -o -iname '*.c' > filelist<CR><CR>
"Use leader key + f to search for file names in current directory using Unite file_list source
nnoremap <leader>f :<C-u>Unite -auto-resize -start-insert file_list:filelist<CR>
Plug 'Shougo/vimproc.vim', {'do': 'make'} "support for unite: file_rec/async and file_reg/git
if executable('ag') "Require installation of The Silver Searcher
let g:unite_source_grep_command='ag'
let g:unite_source_grep_recursive_opt=''
let g:unite_source_grep_default_opts =
\ '-i --vimgrep --hidden --ignore ' .
\ '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr''
\ --cc --make'
endif
"Use leader key + s to search for input pattern in multiple files
nnoremap <silent> <leader>s :<C-u>Unite -auto-resize -auto-preview -buffer-name=search grep:.<cr>
"Use leader key + w to search for the word under cursor in multiple files
nnoremap <silent> <leader>w :<C-u>Unite -auto-resize -auto-preview -buffer-name=search grep:.<cr><C-r><C-w><cr>
Plug 'haitran14/vim-airline'
let g:airline_themes='solarized'
let g:airline_powerline_fonts = 1 "enable powerline fonts
let g:airline#extensions#tabline#enabled = 1 "display tabline
" let g:airline#extensions#tabline#show_tabs = 1 "enable/disable displaying tabs, regardless of number
let g:airline#extensions#tabline#tab_min_count = 2 "only show tab line when there is >=2 tabs
let g:airline#extensions#tabline#tab_nr_type = 1 "show only tab number
let g:airline#extensions#tabline#show_tab_nr = 1 "enable displaying tab number
let g:airline#extensions#tabline#show_tab_type = 1 "show whether this tab is 'tabs' or 'buffer'
let g:airline#extensions#tabline#show_close_button = 0 "hide close button (X) of one opened tab in the tabline
let g:airline#extensions#tabline#fnamemod = ':t' "show only filename and hide path in tab name
let g:airline#extensions#tabline#formatter = 'unique_tail_improved' "show path when tabs have identical file name
let g:airline#extensions#tabline#show_buffers = 0 "hide buffers to activate tabline formatter right above
" let g:airline#extensions#tabline#left_sep = ' ' "set straight tab
" let g:airline#extensions#tabline#left_alt_sep = '|' "put '|' character between straight tabs on tabline
" let g:airline#extensions#tagbar#enabled = 0 "hide function name on airline, to save performance
let g:airline#extensions#branch#enabled = 1 "display git branch
" let g:airline#extensions#branch#displayed_head_limit = 10 "truncate long branch names to a fixed length
" let g:airline#extensions#branch#format = 2 "truncate all path sections but the last one
let g:airline#extensions#whitespace#enabled = 1 "enable detection of whitespace errors
let g:airline#extensions#whitespace#checks = ['trailing'] "specify which whitespace types to check for errors
let g:airline#extensions#whitespace#show_message = 1 "show messages when whitespace errors occur
let g:airline#extensions#whitespace#mixed_indent_algo = 0 "must be all spaces or all tabs before the first non-whitespace character
let g:airline#extensions#ycm#enabled = 1 "enable ycm integration
Plug 'haitran14/vim-colors-solarized'
syntax enable
set background=light
let &t_Co = 16
let g:solarized_termcolors = 16
nnoremap <silent> <F12> :let &background = (&background == "dark"? "light" : "dark")<CR>
call plug#end() "Pluggins END
call unite#filters#matcher_default#use(['matcher_glob'])
call unite#filters#sorter_default#use(['sorter_rank'])
colorscheme solarized