-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
231 lines (197 loc) · 7.2 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
execute pathogen#infect()
syntax on " syntax highlight
"colorscheme default
"highlight Constant ctermfg=DarkGray
colorscheme PaperColor
set background=dark
filetype plugin on
let mapleader = "\<Space>"
set backup " make backup files
set backupdir=~/.vimbackups " where to put backup files
set ignorecase " case insensetive search
set incsearch " incremental search
set showmatch " highlight the brackets
set number
:nnoremap <F6> :set ignorecase!<return> " on/off ignorecase
:nnoremap <F7> :set hlsearch!<return> " on/off search matches hihglights
:nnoremap <F12> :set number!<return> " on/off line numbers
set tabstop=4 " tab 4 symbols
set shiftwidth=4 " ---//---
set smarttab " mass empty symbols treatment
set expandtab " spaces instead of tabs
set smartindent " auto text indents
:nnoremap <F10> :set smartindent!<return> " on/off auto text indent
set wildmenu " show menu on tab navigation
set fileencodings=utf8,cp1251 " try encodings on file open
set encoding=utf8
"<F8> Change encoding
set wcm=<Tab>
menu Enc.cp1251 :e ++enc=cp1251<CR>
menu Enc.koi8-r :e ++enc=koi8-r<CR>
menu Enc.cp866 :e ++enc=ibm866<CR>
menu Enc.utf-8 :e ++enc=utf-8<CR>
menu Enc.ucs-2le :e ++enc=ucs-2le<CR>
map <F8> :emenu Enc.<Tab>
" Treat long lines as break lines (useful when moving around in them)
noremap <C-down> gj
inoremap <C-down> <C-o>gj
noremap <C-up> gk
inoremap <C-up> <C-o>gk
" H J K L for large steps
noremap J 20j
noremap K 20k
" navigate windows by Ctrl-h,j,k,l
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" resize window
nnoremap <s-up> :res+7<cr>
nnoremap <s-down> :res-7<cr>
nnoremap <s-right> :vert res+17<cr>
nnoremap <s-left> :vert res-17<cr>
" statusline
set laststatus=2 " always show statusline
set statusline=%F "full filename
set statusline+=(%n) "buffer number
set statusline+=\ [%{strlen(&fenc)?&fenc:'none'}, "file encoding
set statusline+=%{&ff}] "file format
set statusline+=%h "help file flag
set statusline+=%m "modified flag
set statusline+=%r "read only flag
set statusline+=%= "left/right separator
set statusline+=%c, "cursor column
set statusline+=%l:%L "cursor line/total lines
set statusline+=\ \ \ %P "percent through file
function! StatuslineColor(mode)
if a:mode == 'i'
hi StatusLine ctermbg=white ctermfg=red
elseif a:mode == 'r'
hi StatusLine ctermbg=white ctermfg=brown
else
hi StatusLine ctermbg=black ctermfg=yellow
endif
endfunction
au InsertEnter * call StatuslineColor(v:insertmode)
au InsertChange * call StatuslineColor(v:insertmode)
au InsertLeave * hi StatusLine ctermbg=black ctermfg=green
" default the statusline to green when entering Vim
hi StatusLine ctermbg=black ctermfg=green
" ;ppp to insert debug print_r
noremap ;ppp iecho '<pre>'.print_r(, true).'</pre>'; exit;<left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left>
" type ;for to insert for expression
"inoremap ;for for($i=0; $i<; $i++){}<left><left><left><left><left><left><left><left><left>
inoremap func<space> function ()<cr>{<cr>}<up><up><esc><s-o>/**<cr><space>*<cr>*/<down><esc><s-a><left><left>
inoremap /**<cr> /**<cr><space>*<cr>*/<up><space>
inoremap /**<space> /**<space><space>*/<left><left><left>@var<space>
" when close buffer by \q, force load previous one in its window
"nnoremap <leader>q :bp<cr>:bw #<cr>
" <ctrl-w>t to open current buffer in new tab without closing current one
nnoremap <c-w>t :tab sb%<cr>
" <ctrl-w>T do the same but it closes window in current tab
" map <leader>n for toggle nerd-tree
nnoremap <leader>n :NERDTreeToggle<cr>
" map <leader>gn for go to current file in nerd-tree
nnoremap <leader>gn :NERDTreeFind<cr>
" map <leader>t for toggle tagbar
nnoremap <leader>t :TagbarToggle<cr>
let g:tagbar_autofocus=1
"redefine bufexplorer plugin mapping
nnoremap <leader>bi :BufExplorerHorizontalSplit<cr>
nnoremap <leader>bs :BufExplorerVerticalSplit<cr>
nnoremap <leader>bb :ToggleBufExplorer<cr>
" Set to auto read when a file is changed from the outside
set autoread
" show tabs as dots
set listchars=tab:··
set list
" set 3 lile offset while page scroll
set scrolloff=3
" folding
"set foldcolumn=2 " folding column width
nnoremap ff va{zf " create and close fold in {}
" replace every tab with 4 space
:command Fucktabs %s/ / /gc
" remove trailing spaces
:command Fuckspaces %s/\s\+$//gc
" show trailing spaces
:command Showspaces /\s\+$
" set color of constants to gray
:command Grconst highlight Constant ctermfg=DarkGray
" mark 81'th column
set colorcolumn=80
" mark background when row length becomes more than 120
"highlight OverLength ctermbg=darkgray ctermfg=white
"highlight OverLength ctermbg=darkred
"match OverLength /\%121v.\+/
command! ClearBuffers call s:ClearBuffers()
function! s:ClearBuffers()
let open_buffers = []
for i in range(tabpagenr('$'))
call extend(open_buffers, tabpagebuflist(i + 1))
endfor
for num in range(1, bufnr("$") + 1)
if buflisted(num) && index(open_buffers, num) == -1
exec "bwipeout ".num
"bdelete can be used instead of bdelete
endif
endfor
endfunction
"check current file php syntax by ctrl-f5
map <F5> :!php -l %<CR>
"To begin diffing on all visible windows:
":windo diffthis
"To end diff mode:
":diffoff!
"The ! makes diffoff apply to all windows of the current tab
" disable arrow keys in normal mode
"nnoremap <Up> :echomsg "k"<cr>
"nnoremap <Down> :echomsg "j"<cr>
"nnoremap <Left> :echomsg "h"<cr>
"nnoremap <Right> :echomsg "l"<cr>
" Reduce update screen time to 500ms
set updatetime=500
" vim-gitgutter plugin
nmap ]h <Plug>GitGutterNextHunk
nmap [h <Plug>GitGutterPrevHunk
" <leader>hp preview hunk
" <leader>hu undo hunk
" ctrl-wz close preview window
" to highlight .template files like html-source
" (http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/)
au BufNewFile,BufRead *.template set filetype=html
" you can set highlight for current file as follow:
" :set syntax=html
" CTAGS
" Ctrl-] goto definition
" Ctrl-t go back
" g] - list of definitions ( use Ctrl-w-t before to open buffer in new tab )
" [i - show first line with current tag in file
" ]i - show first line with current tag in file (from current position)
" [I - show all match of current tag in file
" ]I - show all match of current tag in file (from current position)
" open definition in new tab
map <c-\> :tab split<CR>:exec("tselect ".expand("<cword>"))<CR>
" open definition in vertical split
"map <???> :vsp <CR>:exec("tselect ".expand("<cword>"))<CR>
" disable autocomment next line by enter
set formatoptions-=r
" indent xml files on gg=G
au FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 2>/dev/null
" format json file
com! FormatJSON %!python -m json.tool
" goto last active tab by <leader>gt
let g:lasttab = 1
nmap <Leader>gt :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" remove variables from tagbar
let g:tagbar_type_php = {
\ 'ctagstype' : 'php',
\ 'kinds' : [
\ 'i:interfaces',
\ 'c:classes',
\ 'd:constant definitions',
\ 'f:functions',
\ 'j:javascript functions:1'
\ ]
\ }