forked from slax0rr/MyConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc.old
345 lines (288 loc) · 9.65 KB
/
.vimrc.old
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
" Syntax settings
syntax on
set background=dark
set nocompatible " be iMproved, required
let g:vimdir = ".vim"
if has("win32")
let g:vimdir = "vimfiles"
endif
" set the runtime path to include Vundle and initialize
if has("win32")
set rtp+=~/vimfiles/bundle/Vundle.vim
call vundle#begin('~/' . g:vimdir . '/')
else
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
endif
Plugin 'gmarik/Vundle.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'shawncplus/phpcomplete.vim'
Plugin 'joonty/vim-phpqa'
Plugin 'alvan/vim-php-manual'
Plugin 'bling/vim-airline'
Plugin 'sheerun/vim-polyglot'
Plugin 'suan/vim-instant-markdown'
Plugin 'ctrlp.vim'
Plugin 'The-NERD-tree'
Plugin 'Valloric/YouCompleteMe'
Plugin 'fatih/vim-go'
Plugin 'WebAPI.vim'
Plugin 'metarw'
call vundle#end() " required
filetype plugin indent on " required
execute pathogen#infect()
" Tab and indent settings
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
" Backup file dir
set backupdir=~/tmp
" Line numbers
set relativenumber
" FuGITive status line
set laststatus=2
set statusline=%<\ %f\ %{fugitive#statusline()}
" Set backspace to work as in other apps
set backspace=2
" Enable wmnu
set wmnu
" Set autocompletion
set omnifunc=syntaxcomplete#Complete
" set search highligh
set hlsearch
" remove gui elements
set guioptions-=m " remove menu bar
set guioptions-=T " remove toolbar
set guioptions-=r " remove right-hand scroll bar
set guioptions-=L " remove left-hand scroll bar
" add custom ctags file
set tags=.tags;
" set forward slashes
set shellslash
" Disable mouse
set mouse=
" Airline settings
" Enable powerline symbols
let g:airline_powerline_fonts = 1
" Show pretty tabline
let g:airline#extensions#tabline#enabled = 1
" Change theme for cli version
let g:airline_theme='base16'
" Turn on all python highlights of the python syntax plugin
let python_highlight_all = 1
" Disable polyglot language packages
let g:polyglot_disables = ['php']
" NERDTree config
let g:NERDTreeWinSize = 40
map <leader>nt :NERDTree<CR>
" set colorscheme
colorscheme base16-atelierheath
" set font
if has('gui_gtk2')
set guifont=Hack\ 9
else
set guifont=Hack:h9
endif
" Add cursorline and cursorcolumn
set cursorline
set cursorcolumn
" spellcheck
map <leader>se :setlocal spell spelllang=en_gb<CR>
map <leader>sd :setlocal nospell<CR>
" color scheme settings
highlight Search ctermbg=0 ctermfg=6 cterm=bold,underline
highlight CursorLine cterm=underline
" Spell highlight
highlight SpellBad ctermbg=0 ctermfg=1 cterm=bold,underline
highlight SpellCap ctermbg=0 ctermfg=2 cterm=bold,underline
highlight SpellRare ctermbg=0 ctermfg=0 cterm=bold,underline
highlight SpellLocal ctermbg=0 ctermfg=5 cterm=bold,underline
" highligh docblock inline tags
highlight docblockTags ctermfg=180 cterm=bold
" define match for php docblock inline tags
match docblockTags "^\s\+\*\s\zs@.\{-}\ze\s"
" Key remaps
" Remap Ctrl+x Ctrl+o to Ctrl+Space (omni complete)
"inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
"\ "\<lt>C-n>" :
"\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
"\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
"\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
"imap <C-@> <C-Space>
" Add closing brackets when an opening bracket is written
" Squirly brackets
inoremap { {}<Left>
inoremap {<CR> {<CR>}<Esc>O
inoremap {{ {
inoremap {} {}
inoremap { {}<Left>
inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "}"
" Parenthesis
inoremap ( ()<Left>
inoremap (<CR> (<CR>)<Esc>O
inoremap (( (
inoremap () ()
inoremap ( ()<Left>
inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
" Square brackets
inoremap [ []<Left>
inoremap [<CR> [<CR>]<Esc>O
inoremap [[ [
inoremap [] []
inoremap [ []<Left>
inoremap <expr> ] strpart(getline('.'), col('.')-1, 1) == "]" ? "\<Right>" : "]"
" Add closing quotes when an opening bracket is written, and jump over closing
inoremap " ""<Left>
inoremap "" "
inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<Right>" : "\"\"\<Left>"
inoremap ' ''<Left>
inoremap '' '
inoremap <expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<Right>" : "\'\'\<Left>"
" Hide search highlights for current search
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" Find on PHP.net
command! -nargs=1 Pdoc !xdg-open http://php.net/<args> &
nmap <leader>pd :Pdoc <cword><CR>
" Autocomplete already-existing words in the file with tab (extremely useful!)
"function! InsertTabWrapper()
"let col = col('.') - 1
"if !col || getline('.')[col - 1] !~ '\k'
"return "\<tab>"
"else
"return "\<c-p>"
"endif
"endfunction
"inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" Highligh 80 and 120 columns
let &colorcolumn="80,".join(range(120,999),",")
" ctag bar
nmap <leader>tb :TagbarToggle<CR>
" Folding and unfolding
map ,f :set foldmethod=indent<cr>zM<cr>
map ,F :set foldmethod=manual<cr>zR<cr>
" Map F6 and F7 keys to search for tags
map <leader>j g<C-]>
map <leader>sj <C-W>g<C-]>
" Horizontal split to vertical split
map <leader>h <C-w>H
map <leader>k <C-w>K
" Run some formatting rules on a file
map <leader>f :call FixFormatting()<cr>
" Debugger config
let g:dbgPavimPort = 9000
let g:dbgPavimBreakAtEntry = 0
"\ "/mnt/hgfs/webserver/": "/media/sf_S_DRIVE/projects/"
" sharing is caring
command! -range=% VP execute <line1> . "," . <line2> . "w !vpaste ft=" . &filetype
command! -range=% SP silent execute <line1> . "," . <line2> . "w !curl -F 'sprunge=<-' http://sprunge.us/ | tr -d '\\n' | awk '{print $1\"?" . &filetype . "\"}' | xclip -selection clipboard"
command! -range=% IX silent execute <line1> . "," . <line2> . "w !curl -F 'f:1=<-' ix.io | tr -d '\\n' | xclip -selection clipboard"
command! CMD let @+ = ':' . @:
" Functions, functions everywhere!
" Creates a session
function! MakeSession()
let b:sessiondir = substitute($HOME . "/" . g:vimdir . "/sessions" . substitute(getcwd(), '\(\w\):', '/\1/', 'gi'), '\', '/', 'g')
if (filewritable(b:sessiondir) != 2)
if has('win32')
exe 'silent !mkdir ' b:sessiondir
else
exe 'silent !mkdir -p ' b:sessiondir
endif
redraw!
endif
let b:sessionfile = b:sessiondir . '/session.vim'
exe "mksession! " . b:sessionfile
endfunction
" Updates a session, BUT ONLY IF IT ALREADY EXISTS
function! UpdateSession()
let b:sessiondir = substitute($HOME . "/" . g:vimdir . "/sessions" . substitute(getcwd(), '\(\w\):', '/\1/', 'gi'), '\', '/', 'g')
let b:sessionfile = b:sessiondir . "/session.vim"
if (filereadable(b:sessionfile))
exe "mksession! " . b:sessionfile
echo "updating session"
endif
endfunction
" Loads a session if it exists
function! LoadSession()
if argc() == 0
let b:sessiondir = substitute($HOME . "/" . g:vimdir . "/sessions" . substitute(getcwd(), '\(\w\):', '/\1/', 'gi'), '\', '/', 'g')
let b:sessionfile = b:sessiondir . "/session.vim"
if (filereadable(b:sessionfile))
exe 'source ' b:sessionfile
else
echo "No session loaded."
endif
else
let b:sessionfile = ""
let b:sessiondir = ""
endif
endfunction
" Fix formatting
function! FixFormatting()
" wrap logical operators with spaces if there aren't any
execute '%s/\(\S\{-}\)\([<>!]\{-}=\+\|[<>|]\+\)\(\S\{-}\)/\1 \2 \3/ge'
execute '%s/[,a-zA-Z0-9 ^I]\@<!\([a-zA-Z0-9 ^I]\+\)\(&\+\)/\1 \2 /ge'
execute '%s/< ?php/<?php/ge'
" Add a space after control structure keyword, and after closing parenthesis
execute '%s/\(if\|for\|foreach\|while\|switch\)\s\{-}\((.*)\)\s\{-}{/\1 \2 {/ge'
" Turn else if into elseif
execute '%s/}\s\{-}else\s*if\s\{-}/} elseif/ge'
" Wrap else statement with spaces if there aren't any
execute '%s/}\s\{-}else\s\{-}{/} else {/ge'
" Remove whitespace in parenthesis
execute '%s/(\s*\(.*\)\s*)/(\1)/ge'
" Remove excesive whitespace
execute '%s/\(\S\+\) \{2,}\(\S\+\)/\1 \2/ge'
execute '%s/\(\S\+\) \{2,}\(\S\+\)/\1 \2/ge'
" Add whitespace after each comma
execute '%s/,\(\S\+\)/, \1/ge'
" Properly format function definitions
execute '%s/function\s\+\(.\{-}\)\s\{-}(\(.\{-})\)\s*{/function \1(\2) {/ge'
" Properly format class definitions
execute '%s/\(class\|interface\)\s\+\([a-zA-Z0-9]*\)\(.\{-}\)\s*{/\1 \2\3 {/ge'
" Retab the whole file
execute 'retab'
normal gg=G
" Remove any trailing whitespace
execute '%s/\s\+$//ge'
" Remove excesive blank lines
execute '%s/\n\{3,}/\r\r/e'
endfunction
" Change to relative numbering and back
function! NumberToggle()
if (&relativenumber == 1)
set number
set norelativenumber
else
set nonumber
set relativenumber
endif
endfunction
nnoremap <leader>n :call NumberToggle()<CR>
" DBGPavim config
let g:dbgPavimPathMap = [['/home/slax0r/Development/projects/', '/mnt/hgfs/webserver/',]]
" YCM settings
let g:ycm_auto_trigger = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_cache_omnifunc = 1
" Instant markdown preview settings
let g:instant_markdown_autostart = 0
map <leader>md :InstantMarkdownPreview<CR>
" Reopen file on same line as it was closed
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
au VimEnter * nested :call LoadSession()
au VimLeave * :call UpdateSession()
au FileType php set keywordprg=pman
endif
map <leader>m :call MakeSession()<CR>
map <leader>l :call LoadSession()<CR>
" Load environment specific files, if it exists
if !empty(glob("~/.vimrc_env"))
source ~/.vimrc_env
endif
" Load computer specific config file, if it exists
if !empty(glob("~/.vimrc_local"))
source ~/.vimrc_local
endif