Skip to content

Instantly share code, notes, and snippets.

@stronk7
Last active December 10, 2021 14:16
Show Gist options
  • Save stronk7/b0624e66e150ff4ed28c0278f7e1d601 to your computer and use it in GitHub Desktop.
Save stronk7/b0624e66e150ff4ed28c0278f7e1d601 to your computer and use it in GitHub Desktop.
My IDE (vim) configuration as of 20200805, mainly for PHP (autocompletion, jump to definition, quick search, LSP integration, Vundle packages, Dash, Spelling on comments, git support... and other personal tricks/niceties). Note that "-" in the file names means "/" (dirs)
" Override the default @Spell on strings via after syntax.
" The lines are 100% the original ones, just changing @Spell by @NoSpell
" Maybe this can be done simpler, but it's easier to just keep a copy
" of the original php.vim code and perform the replacement to @NoSpell.
if (exists("php_parent_error_open") && php_parent_error_open)
syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+ contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@NoSpell,@phpAddStrings,phpStrEsc contained keepend
else
syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained extend keepend
syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+ contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimmply,phpIdentifierComplex,phpStrEsc contained extend keepend
syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@NoSpell,@phpAddStrings,phpStrEsc contained keepend extend
endif
"<Leader> key is ,
let mapleader=","
"Set the UI and encoding
let $LANG = 'en_AU.UTF-8'
let $LC_ALL = 'en_AU.UTF-8'
set langmenu=none
set encoding=utf-8
"Set tags
set tags=tags;$HOME
"Set title to current file being edited
set title
set titleold=""
set titlestring=%t
"Set tabs to 4 spaces
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
"Briefly jump to start of parenthesis/brackets
set showmatch
"(to completely prevent it to load and work, use next line)
"let loaded_matchparen = 1
"Search incrementaly
set incsearch
"Highlight search matches
set hls
"make sure that bottom status bar is running.
set ruler
set laststatus=2
"want line numbers
"set number
" Enable syntax highlight
syntax on
" Disable all folding
set nofoldenable
" Use system clipboard
" (disabled, doesn't work ok, maybe becasue of "Clip.app" or so)
"set clipboard=unnamed
" Allow mouse interactions (visual selections, then (y)ank/copy, (d)elete/cut, (p)aste.
" (disabled, better use OS copy & paste, turning gutter off with F5
"set mouse+=a
" Special php highlight
let php_sql_query = 1
let php_baselib = 1
let php_htmlInStrings = 1
"let php_folding = 1
" Enable .less syntax highlight
au BufNewFile,BufRead *.less set filetype=less
" Enable .md syntax highlight
au BufNewFile,BufRead *.mkd,*.markdown,*.mdwn,*.md set filetype=mkd
" Insert current comment leader after <Enter>
set formatoptions+=or
" backup files into /.vim/backup
set backup
set backupskip=/tmp/*,/private/tmp/*
set backupdir=~/.vim/backup,.,~/
" save backup files each 50cc
set updatecount=50
" remember things between sessions
"
" '200 - remember marks for 200 previous files
" \"50 - save 50 lines for each register
" :20 - remember 20 items in command-line history!
" % - remember the buffer list (if vim started without a file arg)
" n - set name of viminfo file
set viminfo='200,\"50,:20,%,n~/.vim/viminfo
" go to the last-edited cursor position
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")|execute("normal `\"")|endif
" set spell
setlocal spell spelllang=en_au
set spellfile=~/.vim/spell/en.utf-8.add
set spell
" map F4: toggle spell on/off
map <F4> :call ToggleSpell()<CR>
" map F5: toggle the sign column
map <F5> :call ToggleSignColumn()<CR>
" map F6: disable automatic indenting befor paste
set pastetoggle=<F6>
" Toggle spell. Works only on vim>=8.0 or NeoVim
function ToggleSpell()
if ! &spell
set spell
else
set nospell
endif
endfunction
" Toggle signcolumn. Works only on vim>=8.0 or NeoVim
function ToggleSignColumn()
if !exists("b:signcolumn_on") || b:signcolumn_on
set signcolumn=no
let b:signcolumn_on=0
else
set signcolumn=auto
let b:signcolumn_on=1
endif
endfunction
" map F10: view the highlight groups at the cursor
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" open vimdiff with vertical splits
set diffopt=vertical
" Integration with Dash
au FileType php command! Dash call SearchDash('moodle')
au FileType css command! Dash call SearchDash('css')
au FileType less command! Dash call SearchDash('bs')
au FileType javascript command! Dash call SearchDash('js')
nmap <silent> } :Dash<cr>
function SearchDash(lib)
set iskeyword+=- "allow word expansion to include hyphen
set iskeyword+=: "allow word expansion to include colon
set iskeyword+=\\ "allow word expansion to include backslash
let s:url = "dash://" . UrlEncode(a:lib . ":" . expand("<cword>")) "since BigSur need % encoded stuff - aka urlEncode().
set iskeyword-=- "back to normal, hyphen breaks word expansion
set iskeyword-=: "back to normal, colon breaks word expansion
set iskeyword-=\\ "back to normal, backslash breaks word expansion
" Prepare the final command
let command = '/usr/bin/open ' . s:url
call system(command)
"redraw!
endfunction
function! UrlEncode(string)
let urlsafe = ""
for char in split(a:string, '.\zs')
if matchend(char, '[-_.~a-zA-Z0-9]') >= 0
let urlsafe = urlsafe . char
else
let decimal = char2nr(char)
let urlsafe = urlsafe . "%" . printf("%02x", decimal)
endif
endfor
return urlsafe
endfunction
" Integration with Vundle as package manager
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'StanAngeloff/php.vim'
Plugin 'morhetz/gruvbox'
Plugin 'bling/vim-airline'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-rhubarb'
Plugin 'shumphrey/fugitive-gitlab.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'shawncplus/phpcomplete.vim'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'dense-analysis/ale'
Plugin 'vim-scripts/Decho'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
let g:fugitive_gitlab_domains = ['https://git.in.moodle.com']
" Set gutter priorities / conf, so various plugins can show own signs
let g:gitgutter_sign_priority = 10
let g:ale_sign_priority = 11
" Use Ctrl j/k to navigate between problems.
nmap <silent> <C-j> <Plug>(ale_previous_wrap)
nmap <silent> <C-k> <Plug>(ale_next_wrap)"
" Make ALE launch linting after 5 seconds
let g:ale_lint_delay = 5000
" This is to allow separated gutter cols and only supported by NeoVim v0.4.0
" and up, but doesns't hart to have it in case someday Vim alo gets it.
let g:gitgutter_sign_allow_clobber = 1
" Allow vim-airline plugin to populate the graphs symbols needed.
" (note terminal must support 256 colors and powerline fonts configured)
let g:airline_powerline_fonts = 1
" Airline to handle the tab line too, showing buffers when only 1 tab is open
" let g:airline#extensions#tabline#enabled = 1
" Make omnicompletion to work like IDE's one
:set completeopt=longest,menuone,preview
" Instruct phpcomplete to show phpdocs
let g:phpcomplete_parse_docblock_comments = 1
" Look for variables in ctags
let g:phpcomplete_search_tags_for_variables = 1
" Set the scratch/preview window vertically on right
" and make it zero columns width
" Commented out, was unable to get the preview buffer properly
" defined. So let's use the horizontal top default one.
"autocmd FileType php call DefineScratch()
"function DefineScratch()
" botright vertical pedit previewwindow
" vertical resize 102
"endfunction
" Use CtrlP with <c-p> (mixed mode)
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlPMixed'
" Configure Ale PHP
let g:ale_php_php_executable = '/opt/local/bin/php'
" Configure Ale codechecker
" old
"let g:ale_php_phpcs_executable = '/Users/stronk7/git_moodle/moodle-local_codechecker/pear/PHP/scripts/phpcs'
"let g:ale_php_phpcs_standard = '/Users/stronk7/git_moodle/moodle-local_codechecker/moodle'
" new
let g:ale_php_phpcs_executable = '/Users/stronk7/git_moodle/moodle/local/codechecker/phpcs/bin/phpcs'
let g:ale_php_phpcs_standard = '/Users/stronk7/git_moodle/moodle/local/codechecker/moodle'
let g:ale_php_phpcs_options = '--encoding=utf-8'
" Configure Ale phpstan
"let g:ale_php_phpstan_executable = '/Users/stronk7/git_moodle/phpstan/phpstan'
" Configure Ale psalm
"let g:ale_php_psalm_executable = '/Users/stronk7/git_moodle/psalm/psalm'
" Use ag if available for quicker searches
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
" Search recursively from the ancestor containing .git
let g:ctrlp_working_path_mode = 'ra'
" dark colour scheme we want
set background=dark
" Terminal application doesn't support true colours (just 256)
set t_Co=256
" gruvbox settings
" Some terminals do not support italics, disable them
if !has("gui_running")
let g:gruvbox_italic=0
endif
" Delegates guisp colorings to guibg (fixes some problems with spelling
" errors, linter errors... not being shown by default.
let g:gruvbox_guisp_fallback = "bg"
colorscheme gruvbox
" Highlight redundant whitespaces and tabs (must be after colorscheme)
highlight RedundantSpaces ctermfg=DarkRed guifg=DarkRed cterm=inverse
match RedundantSpaces /\s\+$\| \+\ze\t\|\t/
#!/bin/bash
# Simple script to build moodle ctags against a number of dirs.
# Note this uses (requires) modern ctags. Currently using upstream:
# https://github.com/universal-ctags/ctags
# (that already includes all the impeding stuff, previously it was
# needed to manually patch it)
# Also note that there are other ctags "flavors" out there that can
# work ok (supporting namespaces and friends). I've not tested them.
# List of default directories (absolute paths) that will be processed
defaultdirs="/path/to/your/checkout/dir1
/path/to/your/checkout/dir2
...
/path/to/your/checkout/dirN"
dirs="${1:-${defaultdirs}}"
for dir in $dirs
do
echo "processing $dir";
cd $dir
$HOME/bin/ctags -R --languages=php \
--output-format=e-ctags \
--exclude="CVS" \
--exclude=".git" \
--exclude="vendor" \
--exclude="node_modules" \
--fields=+aimlS \
--php-kinds=vcdfint \
--tag-relative=yes \
--totals=yes
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment