/
.vimrc
449 lines (364 loc) · 11.8 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
set nocompatible
filetype off
" Force loading python3
if has('python3')
endif
" Using vim-plug for plugins https://github.com/junegunn/vim-plug
call plug#begin("~/.vim/bundle")
Plug 'VundleVim/Vundle.vim'
Plug 'scrooloose/nerdtree'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'FelikZ/ctrlp-py-matcher'
Plug 'easymotion/vim-easymotion'
Plug 'bronson/vim-trailing-whitespace'
Plug 'takac/vim-hardtime'
Plug 'airblade/vim-rooter'
Plug 'vim-scripts/PreserveNoEOL'
Plug '2072/PHP-Indenting-for-VIm'
Plug '2072/vim-syntax-for-PHP'
Plug 'itchyny/lightline.vim'
Plug 'majutsushi/tagbar'
Plug 'vim-php/tagbar-phpctags.vim'
Plug 'arnaud-lb/vim-php-namespace'
Plug 'ludovicchabant/vim-gutentags'
Plug 'w0rp/ale'
Plug 'php-vim/phpcd.vim', { 'for': 'php' , 'do': 'composer update' }
Plug 'tpope/vim-surround'
Plug 'sirver/ultisnips'
Plug 'sniphpets/sniphpets'
Plug 'sniphpets/sniphpets-common'
Plug 'pearofducks/ansible-vim'
Plug 'ddrscott/vim-side-search'
Plug 'wellle/targets.vim'
Plug '~/.vim/bundle/vim-syntax-for-phtml'
Plug 'robertbasic/vim-argument-swapper'
Plug 'robertbasic/vim-pyqt5-importer'
Plug 'robertbasic/vim-hugo-helper'
Plug 'phpstan/vim-phpstan'
Plug '~/projects/vim-functions'
call plug#end()
" Enable filetype indentation
filetype plugin indent on
" Do smart autoindenting
set smartindent
set autoindent
" Use UTF-8 encoding
set encoding=utf-8
" Can't remember why is this in
" or from where did I pick it up
let bash_is_sh=1
" ==== Display settings ====
" P - whatever is yanked is automatically put in the system clipboard
" m - show menu bar
set guioptions=Pm
" The ruler shows line, column numbers
" and relative position of the cursor
set ruler
" Show line numbers
set number
" Show in what mode we are
set showmode
" Show command entered in bottom right
set showcmd
" Remember the last 100 commands on the command-line
set history=100
" Hide buffers instead of unloading them
" If we unload a buffer it means it's local history/undo stack
" will be gone if we switch buffers
set hidden
" Tab settings
" One tab is 4 space
set tabstop=4
" Number of spaces for (auto)indent
set shiftwidth=4
" Round indent to multiple of shiftwidth
set shiftround
" Expand tabs to spaces
set expandtab
set softtabstop=4
" Syntax!
" Turn on syntax highlightning
syntax on
colorscheme desert
set background=dark
" Turn on command-line completion
set wildmenu
" List all matches and complete till longest common string
set wildmode=full
" Always have a status line
set laststatus=2
" Hide mouse when typing
set mousehide
" When scrolling up/down the page, number of lines when scrolling starts
set scrolloff=8
" change how the cursor looks
set guicursor=n-v-c:block-Cursor-blinkon0
set guicursor+=ve:ver35-Cursor
set guicursor+=o:hor50-Cursor
set guicursor+=i-ci:ver25-Cursor
set guicursor+=r-cr:hor20-Cursor
set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
" Show cursorline for the active buffer
" Hide cursorline for inactive buffers
augroup CursorLine
au!
au WinLeave * setlocal nocursorline
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
augroup End
" Set font
set guifont=DejaVu\ Sans\ Mono\ 12
function! SetBigFont()
set guifont=DejaVu\ Sans\ Mono\ 12
endfun
function! SetSmallFont()
set guifont=DejaVu\ Sans\ Mono\ 10
endfun
" ==== End display settings ====
" Make backspace behave normally
set backspace=2
" Space, the Leader!
let mapleader="\<space>"
" ==== Search/yank settings ====
" Yank/delete copies to system clipboard
set clipboard=unnamed
" Search settings
" Ignore case when searching
set ignorecase
" Ignore ignorecase when search pattern contains uppercase chars
set smartcase
" Incremental search - start highlighting search results as the
" search string is typed
set incsearch
" Highlight search results
set hlsearch
" Normal, non-recursive map
" Clear the search buffer
nnoremap <leader>, :noh<cr>
" Make n always search forward
" Make N always search backward
nnoremap <expr> n 'Nn'[v:searchforward]
nnoremap <expr> N 'nN'[v:searchforward]
" ==== End search/yank settings ====
" consider
" set selection=old
" ==== Plugins settings ====
" ==== VIM PyQt5 Importer settings ====
map <leader>pi :PyQt5ImportClass<cr>
" ==== End VIM PyQt5 Importer settings ====
"
" ==== VIM Argument Swapper settings ====
map <leader>as :ArgumentSwapperSwap<cr>
" ==== End VIM Argument Swapper settings ====
"
" ==== NERDTree settings ====
nnoremap <silent> <c-n> :NERDTreeToggle<CR>
let NERDTreeMapHelp='<f1>'
let NERDTreeIgnore = ['\.pyc$', '__init__.py', '__pycache__']
" ==== End NERDtree settings ====
"
" ==== CtrlP settings ====
" Open CtrlP buffers
map <tab> :CtrlPBuffer<cr>
map <leader>tb :CtrlPBufTag<cr>
map <leader>ta :CtrlPTag<cr>
" Jump to definition
map <silent> <leader>jd :CtrlPTag<cr><C-\>w
" Things to ignore with CtrlP
let g:ctrlp_user_command = 'ag %s -l --nocolor -g "" '
" uses ~/.agignore
"let g:ctrlp_custom_ignore = 'vendor/\|tests\/log\|git\|env\|build/\|dist/\|__pycache__\|docs\/build/\|public_html\/api/\|public_html\/docs/\|*.pyc'
let g:ctrlp_match_current_file = 1
let g:ctrlp_lazy_update = 1
let g:ctrlp_extensions = ['tag', 'buffertag']
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
let g:ctrlp_use_caching = 0
" ==== End CtrlP settings ====
"
" ==== Easymotion settings ====
" Disable default easymotion mappings
let g:EasyMotion_do_mapping = 0
" Turn on case insensitive feature
let g:EasyMotion_smartcase = 1
nmap <leader>s <Plug>(easymotion-s)
vmap <leader>s <Plug>(easymotion-s)
" ==== End Easymotion settings ====
"
" ==== hardtime settings ====
" Turn on hardtime
let g:hardtime_default_on = 0
" Allow different movement key
let g:hardtime_allow_different_key = 1
" Max 3 of the same movement allowed at a time
let g:hardtime_maxcount = 3
" ==== End hardtime settings ====
"
" ==== rooter settings ====
let g:rooter_silent_chdir=1
let g:rooter_patterns = ['composer.json', 'Vagrantfile', '.git/']
" ==== End rooter settings ====
"
" ==== PreserveNoEOL settings ====
let g:PreserveNoEOL=0
" ==== End Preserver NoEOL settings ====
"
" ==== tagbar settings ====
" Open tagbar with F8
nnoremap <F8> :TagbarToggle<CR>
" Location of phpctags bin
let g:tagbar_phpctags_bin='~/.vim/phpctags'
" ==== End tagbar settings ====
"
" ==== gutentags settings ====
" Exclude css, html, js files from generating tag files
let g:gutentags_exclude = ['*.css', '*.html', '*.js', '*.json', '*.xml',
\ '*.phar', '*.ini', '*.rst', '*.md',
\ '*vendor/*/test*', '*vendor/*/Test*',
\ '*vendor/*/fixture*', '*vendor/*/Fixture*',
\ '*var/cache*', '*var/log*']
" Where to store tag files
let g:gutentags_cache_dir = '~/.vim/gutentags'
" ==== End gutentags settings ====
"
let g:ale_linters = {
\ 'php': ['php'],
\}
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 0
" ==== lightline settings ====
let g:lightline = {
\ 'active': {
\ 'left': [['mode'], ['readonly', 'filename', 'modified'], ['tagbar', 'ale', 'gutentags']],
\ 'right': [['lineinfo'], ['filetype']]
\ },
\ 'inactive': {
\ 'left': [['absolutepath']],
\ 'right': [['lineinfo'], ['filetype']]
\ },
\ 'component': {
\ 'lineinfo': '%l\%L [%p%%], %c, %n',
\ 'tagbar': '%{tagbar#currenttag("[%s]", "", "f")}',
\ 'ale': '%{ale#statusline#Status()}',
\ 'gutentags': '%{gutentags#statusline("[Generating...]")}'
\ },
\ }
" ==== End lightline settings ====
"
" ==== UltiSnips settings ====
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsSnippetDirectories=[$HOME.'/.vim/UltiSnips', $HOME.'/.vim/bundle/sniphpets-common/UltiSnips', $HOME.'/.vim/bundle/sniphpets']
" ==== End UltiSnips settings ====
"
" ==== vim side search settings ====
let g:side_search_prg = 'ag --word-regexp --heading --stats -B 1 -A 4 --ignore="*.js"'
let g:side_search_splitter = 'vnew'
let g:side_search_split_pct = 0.5
nnoremap <leader>gw :SideSearch <C-r><C-w><CR> | wincmd p
cabbrev SS SideSearch
" ==== End vim side search settings ====
"
" ==== vim-php-namespace settings ====
function! IPhpInsertUse()
call PhpInsertUse()
call feedkeys('a', 'n')
endfunction
autocmd FileType php inoremap <Leader>pnu <Esc>:call IPhpInsertUse()<CR>
autocmd FileType php noremap <Leader>pnu :call PhpInsertUse()<CR>
function! IPhpExpandClass()
call PhpExpandClass()
call feedkeys('a', 'n')
endfunction
autocmd FileType php inoremap <Leader>pne <Esc>:call IPhpExpandClass()<CR>
autocmd FileType php noremap <Leader>pne :call PhpExpandClass()<CR>
autocmd FileType php inoremap <Leader>pns <Esc>:call PhpSortUse()<CR>
autocmd FileType php noremap <Leader>pns :call PhpSortUse()<CR>
let g:php_namespace_sort_after_insert=1
" ==== End plugin settings ====
" ==== Automatic ====
" Automatically change cwd to the directory of the file in the current buffer
autocmd BufEnter * silent! lcd %:p:h
" Set file types for some of the PHP related extensions
autocmd BufNewFile,BufRead *.inc set ft=php
autocmd BufNewFile,BufRead *.phtml set ft=phtml
autocmd BufNewFile,BufRead *.tpl set ft=phtml
" since installing vim-indent-object
" PHP block comments got broken
" this whatever is fixes it
" looks like this is not needed anymore
" granted, not using vim-indent-object
" au FileType php setlocal comments=s1:/*,mb:*,ex:*/,://,:#
" au FileType php setlocal formatoptions+=cro
autocmd BufNewFile,BufRead *.xsd set ft=xml
let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax
au BufRead,BufNewFile *.twig set ft=html
" ==== End automatic ====
" ==== Custom functions ====
function! FixSyntax()
" nmap <silent> <leader><leader>fs :syntax sync fromstart<cr>
syntax sync fromstart
endfun
function! OpenTestFile()
let b:file = expand("%:p:r")
let b:root_dir = getbufvar('%', 'rootDir')
let b:tests_dir = b:root_dir . "/tests"
let b:test_file = substitute(b:file, b:root_dir, b:tests_dir, "") . "Test.php"
exe ":vsp " b:test_file
endfun
function! OpenTestMethodFile()
let b:file = expand("%:p:r")
let b:root_dir = getbufvar('%', 'rootDir')
let b:tests_dir = b:root_dir . "/tests"
let b:class_test_dir = substitute(b:file, b:root_dir, b:tests_dir, "")
let b:current_method = substitute(tagbar#currenttag('%s',''), '\(^.\)', '\u&', 'g')
if !isdirectory(b:class_test_dir)
call mkdir(b:class_test_dir, 'p')
endif
let b:test_file = b:class_test_dir . "/" . b:current_method . "Test.php"
exe ":vsp " b:test_file
endfun
function! CopyPasteMethodBody(from_line, to_line)
execute a:from_line
normal! yiB
execute a:to_line
normal! p
endfun
function! IndentHtmlFile()
set ft=html
normal! ggVG=<cr>
set ft=php
endfun
function! SectionLink()
exe "normal! ^wi[\elv$hyA](#)\ePvibu"
endfun
function! CreateNamespace()
let b:file = expand("%:p:h")
let b:root_dir = getbufvar('%', 'rootDir')
let b:class = substitute(b:file, b:root_dir . '/src', '', "")
let b:namespace = substitute(b:class, '/', '\\', 'g')
let b:namespace = substitute(b:namespace, '\\', '', '')
exe "normal! Inamespace " . b:namespace . ";"
endfun
" ==== End custom functions ====
" ==== Remappings ====
" edit .vimrc
nmap <silent> <leader>vev :e $MYVIMRC<cr>
" source .vimrc
nmap <silent> <leader>vsv :so $MYVIMRC<cr>
" check with ctrl+l the current file for php syntax errors
autocmd FileType php noremap <C-l> :!/usr/bin/php -l %<cr>
" Swap the current line and the line below
nmap <leader>clb dd:pu<cr>
" Swap the current line and the line above
nmap <leader>cla ddkP<cr>
" Fix indent in curly Braces
noremap <leader>fiB viB=<cr>k
" Fix indent in [square braces
noremap <leader>fi[ vi[j=<cr>k
" Call OpenTestFile() custom function
nnoremap <leader>otf :call OpenTestFile()<cr>
nnoremap <leader>otmf :call OpenTestMethodFile()<cr>
" Highlight word under cursor
nnoremap <silent> <Leader>* :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
" Swap current and next variable
nnoremap <silent> <Leader>vs 2wdw2bPa, <ESC>2wx
" ==== End remappings ====