-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
234 lines (187 loc) · 5.32 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
source /etc/vimrc
syntax on
set colorcolumn=80
" Ctrl j inserts a blank line below and ctrl k inserts above
nmap <C-k> O<Esc>j
nmap <C-j> o<Esc>k
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" use 'space' to enter a single character in normal mode; similar to 'r'
nmap <Space> i_<Esc>r
"remember previous 100 commands
set history=1000
" :W <caps-w> saves the file with permission denied error
command W w !sudo tee % > /dev/null
" to highlight the current line
set cursorline
hi CursorLine cterm=NONE,underline guibg=#F4F4F4
" Highlight search results
set hlsearch
" Bash like autocompletion
set wildmode=longest,list,full
set wildmenu
" Makes search act like search in modern browsers
set incsearch
" Stop the search at end of file.
"set nowrapscan
" Use spaces instead of tabs
set expandtab
" autoindent
set autoindent
" set c style indentation
set cindent
" set partial command
set showcmd
" show relative line number
set rnu
" show line number
set nu
" ignore the case sensitive search
set ignorecase
set shiftwidth=2
set softtabstop=2
" Any uppercase in search string treated as case in-sensitive contrary to the
" above option
set smartcase
"always show the status line
set laststatus=2
" auto remove trailing spaces
autocmd BufWritePre * :%s/\s\+$//e
" Functions to view the diff in buffer to original file
" cmd :DiffSaved to see the diff
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
colorscheme darkblue
" Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Plugin 'gmarik/vundle'
Plugin 'tpope/vim-fugitive'
Plugin 'majutsushi/tagbar'
Plugin 'kien/ctrlp.vim'
Plugin 'flazz/vim-colorschemes'
Plugin 'sjl/gundo.vim'
Plugin 'rking/ag.vim'
"Plugin 'davidhalter/jedi-vim'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
Plugin 'vim-scripts/a.vim'
Plugin 'PProvost/vim-ps1'
"Plugin 'scrooloose/nerdtree'
Plugin 'congma/pylint.vim'
Plugin 'fatih/vim-go'
Plugin 'rhysd/vim-clang-format'
Plugin 'mileszs/ack.vim'
Plugin 'Chiel92/vim-autoformat'
"Plugin 'Valloric/YouCompleteMe'
"Plugin 'artur-shaik/vim-javacomplete2'
"Plugin 'xolox/vim-easytags'
" Beyond Vim7.4 no need to add this flag.
let g:go_version_warning = 0
let g:ackprg = 'ag --nogroup --nocolor --column'
let g:jedi#use_tabs_not_buffers = 1
filetype plugin indent on
let mapleader="," " leader is comma
" toggle gundo
nnoremap <leader>u :GundoToggle<CR>
nnoremap <leader>t :TagbarToggle<CR>
autocmd FileType tagbar setlocal nocursorline nocursorcolumn
" Switch betwen header and source files
nmap <leader>c :A<CR>
nmap <leader>h :A<CR>
" Fast saving
nmap <leader>w :w<cr>
"nmap <leader>b :CtrlPBuffer<cr>
nmap <leader>b :Buffers<cr>
nmap <leader>f :GFiles<cr>
nmap <leader>F :Files<cr>
vnoremap // y/<C-R>"<CR>
" FZF to search the tags file.
function! s:tags_sink(line)
let parts = split(a:line, '\t\zs')
let excmd = matchstr(parts[2:], '^.*\ze;"\t')
execute 'silent e' parts[1][:-2]
let [magic, &magic] = [&magic, 0]
execute excmd
let &magic = magic
endfunction
function! s:tags()
if empty(tagfiles())
echohl WarningMsg
echom 'Preparing tags'
echohl None
call system('ctags -R ')
endif
call fzf#run({
\ 'source': 'cat '.join(map(tagfiles(), 'fnamemodify(v:val, ":S")')).
\ '| grep -v -a ^!',
\ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index',
\ 'down': '40%',
\ 'sink': function('s:tags_sink')})
endfunction
command! Tags call s:tags()
" FZF to search tags in current file.
function! s:align_lists(lists)
let maxes = {}
for list in a:lists
let i = 0
while i < len(list)
let maxes[i] = max([get(maxes, i, 0), len(list[i])])
let i += 1
endwhile
endfor
for list in a:lists
call map(list, "printf('%-'.maxes[v:key].'s', v:val)")
endfor
return a:lists
endfunction
function! s:btags_source()
let lines = map(split(system(printf(
\ 'ctags -f - --sort=no --excmd=number --language-force=auto %s',
\ expand('%:S'))), "\n"), 'split(v:val, "\t")')
if v:shell_error
throw 'failed to extract tags'
endif
return map(s:align_lists(lines), 'join(v:val, "\t")')
endfunction
function! s:btags_sink(line)
execute split(a:line, "\t")[2]
endfunction
function! s:btags()
try
call fzf#run({
\ 'source': s:btags_source(),
\ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index',
\ 'down': '40%',
\ 'sink': function('s:btags_sink')})
catch
echohl WarningMsg
echom v:exception
echohl None
endtry
endfunction
" Command for git grep
" " - fzf#vim#grep(command, with_column, [options], [fullscreen])
command! -bang -nargs=* GGrep
\ call fzf#vim#grep(
\ 'git grep --line-number '.shellescape(<q-args>), 0,
\ { 'dir': systemlist('git rev-parse --show-toplevel')[0] }, <bang>0)
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
command! BTags call s:btags()
nmap <leader>s :Tags<cr>
nmap <leader>d :BTags<cr>
nmap <leader>l :BLines<cr>
nmap <leader>j gj
nmap <leader>k gk