Table of contents
building with vim
config examples when registering a compiler
/usr/share/vim/vim81/compiler
/usr/share/vim/vim81/ftplugin
change the compiler
:compiler ant
:compiler javac
overwrite the compiler (default = make)
:set makeprg=mvn
:set makeprg=echo\ string
pass the current file to the compiler
:set makeprg=echo\ %:S
call multiple commands in a row
:set makeprg=clear;echo\ 'calling ant';ant
run configured compiler and write errors to quickfix list
:make
:make [args]
specify location of error file (deleted before and after run)
:set makeef [file]
configure the shell pipe used to store the compiler output in an error file
:set shellpipe=[pipe]
set shellpipe back to default
:set shellpipe=2>&1|tee
example: poor mans filtering of compiler output
:set shellpipe=2>&1\|grep\ error\|tee
process compiler output directly in vim (or call a script that calls compiler)
:set makeprg=[compiler]
:set errorformat=[format]
:make [arg]*
# results in: /bin/bash -c [compiler] [arg]* 2>&1| tee [makeef]
shellpipe empty -> error file argument omitted, must be created by compiler
:set makeprg=[compiler]
:set shellpipe=
:set makeef [file]
:set errorformat=[format]
:make [arg]*
# results in: /bin/dash /tmp/b/iaac
filter output in shellpipe
:set makeprg=[compiler]
:set shellpipe=2>&1\|[script]
:set errorformat=[format]
:make [arg]*
# results in: /bin/bash -c [compiler] [arg]* 2>&1|[script] [makeef]
example script: print all output, but only errors in error file
#!/bin/dash
while read data; do
echo "$data"
if echo "$data" | grep -q 'error'; then
echo "# $data" >> $1
fi
done
# show how this script is being called
pgrep -a bash | tail -n 1
vim error format
set error format
:set efm
:set errorformat
%c = column number (number)
%f = file name (string)
%l = line number (number)
%m = error message (string)
%n = error number (number)
%o = module name (string)
%p = pointer line (sequence of '-', '.', ' ' or tabs)
%r = rest of line
%s = search text (string)
%t = error type (character), e=error, w=warning, i=info, n=note
%v = virtual column number (finds a number)
%A = start of a multi-line message (unspecified type)
%C = continuation of a multi-line message
%D = enter directory; expects a following %f (directory name)
%E = multiline error message (begin)
%I = start of a multi-line informational message
%N = start of a multi-line note message
%O = single-line file message: overread the matched part
%Q = single-line file message: pop the last file from stack
%P = single-line file message: push file %f onto the stack
%W = start of a multi-line warning message
%X = leave directory; expects a following %f
%Z = end of a multi-line message
%- = do not include the matching multi-line in any output
%+ = include the whole matching line in the %m error string
%-G = ignore this message
%+G = general message
%*{conv} = any scanf non-assignable conversion
%% = the single '%' character
%> = for next line start with current pattern again efm-%>
%\ = The single '\' character, Note that this has to be escaped ("%\\")
%. = The single '.' character.
%# = The single '*'(!) character.
%^ = The single '^' character. Note that this is not useful
%$ = The single '$' character. Note that this is not useful
%[ = The single '[' character for a [] character range.
%~ = The single '~' character.
%.%# = match any number of any character
example: delete all lines
%-G%.%#
example: delete lines starting with "info:"
\%-Ginfo%.%#
example: match all lines of format error:[file]:[line], filter everything else
:set efm=error:%f:%l,%-G%.%#
example: same as above, but expect a message after the line number
:set efm=error:%f:%l%m,%-G%.%#
example ant/junit/javac errorformat
:set errorformat=
\%-G%.%#build.xml:%.%#,
\%-G%.%#warning:\ %.%#,
\%-G%\\C%.%#EXPECTED%.%#,
\%f:%l:\ %#%m,
\C:%f:%l:\ %m,
\%DEntering:\ %f\ %\\=,
\%ECaused\ by:%[%^:]%#:%\\=\ %\\=%m,
\%ERoot\ cause:%[%^:]%#:%\\=\ %\\=%m,
\%Ecom.%[%^:]%#:%\\=\ %\\=%m,
\%Eorg.%[%^:]%#:%\\=\ %\\=%m,
\%Ejava.%[%^:]%#:%\\=\ %\\=%m,
\%Ejunit.%[%^:]%#:%\\=\ %\\=%m,
\%-Z%\\C\ at\ com.mypkg.%.%#.test%[A-Z]%.%#(%f:%l)\ %\\=,
\%-Z%\\C\ at\ com.mypkg.%.%#.setUp(%f:%l)\ %\\=,
\%-Z%\\C\ at\ com.mypkg.%.%#.tearDown(%f:%l)\ %\\=,
\%-Z%^\ %#%$,
\%-C%.%#,
\%-G%.%#
links
https://vimhelp.org/quickfix.txt.html#errorformat
https://linux.die.net/man/3/scanf
https://vimhelp.org/quickfix.txt.html#quickfix.txt
https://vonheikemen.github.io/devlog/tools/vim-and-the-quickfix-list/
vimgrep
vimgrep
searching multiple files at once
:vim //g **/*.txt
:vimgrep //g **/*.txt
usage of vim(grep) and lvim(grep)
vimgrep /[pattern]/[flags] [file]...
fill quickfix list using vimgrep instead
:vimgrep fill quickfix list using vimgrep
:grep fill quickfix list using external program (faster)
:lvimgrep fill window local list using vimgrep
:lgrep fill window local list using external program (faster)
:lvim alias for lvimgrep
:vim alias for vimgrep
available flags
g collect more than one match per line
j do not jump to first match automatically
show next result
:cnext
show previous result
:clast
list all results
:cope
search the files in the argument list with ##
:vimgrep // ##
other examples
:vimgrep /git/ install.sh
:vimgrep /apt/ **/*.sh
:vimgrep /"[^"]i\+"/ ~/.*
quick fix list
navigation in quick fix window
<enter> jump to file for entry
quick fix window
show/hide quickfix window
:copen cursor moves to quickfix window
:cwindow if already open, cursor remains in editor
:cclose close quickfix window
:ccl alias for cclose
:cw alias for cwindow
show all error messages for files
:clist
show all error messages even those not understood by vim
:clist!
show a subset of the errors
:clist [from] [to]
open in vertical split
:vert copen
:vert cw
cycle error messages / vimgrep results
:cprevious go to previous match (global)
:cNext go to previous match (global)
:cnext go to next match (global)
:cabove go to previous match in current buffer
:cbelow go to next match in current buffer
:crewind go to first match
:clast go to last match
:cnfile go to next file with matches
:cpfile go to previous file with matches
:cc [index] go to error by index
:cfirst alias for crewind
:cfir alias for crewind
:cr alias for crewind
:cla alias for clast
:cp alias for cprevious
:cn alias for cnext
:cN alias for cNext
:cpf alias for cpfile
:cnf alias for cnfile
cycle through error messages of previous builds / searches
:colder
:cnewer
:col
:cnew
show full error message (if used with make)
:cc
cdo, execute commands on quickfix list
execute command on all entries in the quickfix list
:cdo [cmd]
execute command once per file containing entries in the quickfix list
:cfdo [cmd]
allow vim to modify multiple buffers if :set hidden is not set
:hide cdo [CMD]
:hide cfdo [CMD]
example: remove all comments from shell scripts
:vim /^\s*#/ **/*.sh
:hide cdo d
example: replace TODO with FIXME me in all txt files
:vim TODO **/*.txt
:hide cdo s/TODO/FIXME/
example: replace only on the first 5 lines of each file
:vim TODO **/*.txt
:hide cfdo 1,5 s/TODO/FIXME/
example: replace only the entries that contain 'deprecated'
:vim TODO **/*.txt
:hide cfdo /deprecated/ s/TODO/FIXME/
example substitute and save changes in one go
:hide cfdo /deprecated/ s/TODO/FIXME/ | update
documentation
https://vimhelp.org/usr_30.txt.html#usr_30.txt
https://vimhelp.org/usr_41.txt.html#write-compiler-plugin
https://vimhelp.org/options.txt.html#%27errorformat%27
https://vimhelp.org/quickfix.txt.html#quickfix.txt