Skip to content

Instantly share code, notes, and snippets.

@haringsrob
Created November 4, 2018 16:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save haringsrob/8e63de892afadf728b0f0077324111ac to your computer and use it in GitHub Desktop.
Save haringsrob/8e63de892afadf728b0f0077324111ac to your computer and use it in GitHub Desktop.
VIM config for PHP/Drupal editing
" Leader key <SPACE>
let mapleader=" "
nnoremap <Space> <Nop>
call plug#begin('~/.config/nvim/plugged')
Plug 'phpactor/phpactor' , {'do': 'composer install', 'for': 'php'}
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'phpactor/ncm2-phpactor'
Plug 'ncm2/ncm2-ultisnips'
Plug 'Shougo/echodoc.vim'
Plug 'SirVer/ultisnips'
Plug 'vim-airline/vim-airline'
Plug 'hecal3/vim-leader-guide'
Plug 'tpope/vim-sleuth'
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
Plug 'jacks0n/Drupal-Hook-Generator.vim', { 'for': 'php' }
Plug 'majutsushi/tagbar'
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
Plug 'vim-vdebug/vdebug'
Plug 'vvmk/AutoClose'
Plug 'scrooloose/nerdtree'
Plug 'lumiliet/vim-twig'
Plug 'ntpeters/vim-better-whitespace'
Plug 'airblade/vim-rooter'
Plug 'w0rp/ale'
Plug 'janko-m/vim-test'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-dispatch'
Plug 'godlygeek/tabular'
Plug 'sonph/onehalf', {'rtp': 'vim/'}
Plug 'quentindecock/vim-cucumber-align-pipes'
call plug#end()
" Drupal filetypes
if has("autocmd")
" Drupal *.module and *.install files.
augroup module
autocmd BufRead,BufNewFile *.module set filetype=php
autocmd BufRead,BufNewFile *.install set filetype=php
autocmd BufRead,BufNewFile *.test set filetype=php
autocmd BufRead,BufNewFile *.inc set filetype=php
autocmd BufRead,BufNewFile *.profile set filetype=php
autocmd BufRead,BufNewFile *.view set filetype=php
augroup END
endif
" Default settings
filetype plugin indent on
syntax on
set mouse=a
set hidden
set number
set signcolumn=yes
let loaded_matchparen = 1
set lazyredraw
set termguicolors
set t_Co=256
set cursorline
colorscheme onehalfdark
let g:airline_theme='onehalfdark'
" Clipboard sharing
set clipboard+=unnamedplus
" Root finder
let g:rooter_patterns = ['.phpactor.yml', 'vendor/', '.git', 'composer.lock']
let g:rooter_silent_chdir = 1
" PHPActor
let g:phpactorPhpBin = '/usr/local/Cellar/php/7.2.11/bin/php'
let g:phpactorOmniError = v:true
autocmd FileType php setlocal omnifunc=phpactor#Complete
" Debug
let g:vdebug_options= {
\ "port" : 9000,
\ "server" : '',
\ "timeout" : 200,
\ "on_close" : 'detach',
\ "break_on_open" : 0,
\ "ide_key" : 'PHPSTORM',
\ "path_maps" : {},
\ "debug_window_level" : 0,
\ "debug_file_level" : 0,
\ "debug_file" : "",
\ "watch_window_style" : 'compact',
\ "marker_default" : '⬦',
\ "marker_closed_tree" : '▸',
\ "marker_open_tree" : '▾',
\ "window_commands": {
\ 'DebuggerWatch': 'vertical belowright new',
\ 'DebuggerStack': 'belowright new +res5',
\ 'DebuggerStatus': 'belowright new +res5'
\ },
\ }
" Airline
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
" Tree
map <C-n> :NERDTreeToggle<CR>
let NERDTreeWinPos='right'
let NERDTreeShowHidden=1
" searching
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>, '--skip-vcs-ignores',
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%'),
\ <bang>0)
" Whitespaces
let g:strip_whitespace_on_save=1
" Testing
let g:test#project_root = "tests"
let test#strategy = "dispatch"
let test#php#behat#executable = './behat -c behat.yml'
let test#php#phpunit#executable = '../vendor/bin/phpunit'
" ALE
let g:ale_fix_on_save = 0
let g:ale_lint_delay = 1000
let b:ale_warn_about_trailing_whitespace = 1
let g:ale_lint_on_text_changed = 0
let g:ale_lint_on_enter = 0
let g:ale_lint_on_save = 1
let g:ale_fixers = {
\ 'php': ['phpcbf'],
\}
let g:ale_linters = {
\ 'php': ['php', 'phpcs', 'phpmd'],
\}
let g:ale_php_phpcbf_standard = 'Drupal'
let g:ale_php_phpcs_standard = 'Drupal'
function StandardsPSR()
let g:ale_php_phpcbf_standard = 'PSR2'
let g:ale_php_phpcs_standard = 'PSR2'
endfunction
" Config for keybinds.
let g:lmap = {}
call leaderGuide#register_prefix_descriptions("<Space>", "g:lmap")
nnoremap <silent> <leader> :<c-u>LeaderGuide '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>LeaderGuideVisual '<Space>'<CR>
let g:lmap.k = {
\'name': 'PhpActor',
\'b': ['call phpactor#ClassExpand()', 'ExpandClass'],
\'c': ['call phpactor#CopyFile()', 'Copy file'],
\'d': ['call phpactor#GotoDefinition()', 'Go to definition'],
\'e': ['call phpactor#mxtractMethod()', 'Extract method'],
\'f': ['call phpactor#FindReferences()', 'Find references'],
\'k': ['call phpactor#ContextMenu()', 'Menu'],
\'h': ['call phpactor#Hover()', 'Hover'],
\'i': ['call phpactor#ClassInflect()', 'Inflect'],
\'l': ['call phpactor#ClassNew()', 'New class'],
\'m': ['call phpactor#MoveFile()', 'Move file'],
\'n': ['call phpactor#Navigate()', 'Navigate'],
\'t': ['call phpactor#Transform()', 'Transform/Complete'],
\'u': ['call phpactor#UseAdd()', 'UseAdd'],
\}
let g:lmap.d = {
\'name': 'Drupal',
\'h': ['GenerateDrupalHook', 'Hook'],
\}
let g:lmap.b = {
\'name': 'DEBUGGER',
\'l': [':VdebugStart', 'Start listening'],
\'<F10>': [':Breakpoint', 'Toggl breakpoint'],
\}
let g:lmap.b = {
\'name': 'Buffers',
\'l': [':Buffers', 'List buffers'],
\}
let g:lmap.s = {
\'name': 'Search',
\'f': ['call feedkeys(":Ag ")', 'Fuzzy Search project'],
\}
let g:lmap.f = {
\'name': 'Files',
\'p': ['Files', 'Find project files'],
\'g': ['GFiles', 'Find git files'],
\'o': ['NERDTreeFind', 'Open current file in tree'],
\'t': ['NERDTreeToggle', 'Open nerd tree'],
\}
let g:lmap.t = {
\'name': 'Testing',
\'n': ['TestNearest', 'Nearest'],
\'f': ['TestFile', 'File'],
\'s': ['TestSuite', 'Suite'],
\'l': ['TestLast', 'Last'],
\}
"" Search word under cursor.
nnoremap <Plug>(search-cursor-word) :Ag <C-R><C-W><CR>
nmap <leader>sw <Plug>(search-cursor-word)
"" Search tags for cursor word.
nnoremap <Plug>(search-cursor-word-tags) :Tags <C-R><C-W><CR>
nmap <leader>st <Plug>(search-cursor-word-tags)
" History
nnoremap <Plug>(file-history) :History<CR>
nmap <leader>h <Plug>(file-history)
nmap <C-e> <Plug>(file-history)
nnoremap <Plug>(search-history) :History/<CR>
nmap <leader>sh <Plug>(search-history)
nnoremap <silent> gd :call phpactor#GotoDefinition()<CR>
nnoremap <silent> <leader>p :so ~/.config/nvim/init.vim<CR>
nmap <C-l> :Buffers<CR>
" buffers
nnoremap <Plug>(last-buffer) :e#<CR>
nmap <leader>gl <Plug>(last-buffer)
" Alignment
nnoremap <Plug>(align-tabs) :Tab /\|<CR>
nmap <leader>l <Plug>(align-tabs)
" Various
nmap <F8> :TagbarToggle<CR>
map <C-p> :FZF<CR>
" Copy with ctrl c
map <C-c> :let @*=expand("%s")<CR>
" NCM2
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=noinsert,menuone
inoremap <expr> <c-j> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <c-k> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <silent> <expr> <c-u> ncm2_ultisnips#expand_or("\<CR>", 'n')
let g:UltiSnipsJumpForwardTrigger="<tab>"
l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment