Skip to content

Task Examples

Linwei edited this page Feb 18, 2020 · 25 revisions

CMake Example

[project-init]
command=mkdir build && cd build && cmake .. -G "MinGW Makefiles"
cwd=<root>
errorformat=

[project-build]
command=cmake --build build
cwd=<root>
errorformat=%f:%m:%l

[project-run]
command="build/$(VIM_PRONAME)"
cwd=<root>
output=terminal

Grep Example

Project wide grep, will ask you input a keyword to search:

[grep-word]
command=rg -n --no-heading --color never "$(?keyword)" "<root>" -tc -tcpp -tpy -tvim -tgo
cwd=$(VIM_ROOT)
errorformat=%f:%l:%m

If you want to search current word under cursor, you can use <c-r><c-w> to pick up current word, or define another task to search word under cursor directly:

[grep-cword]
command=rg -n --no-heading --color never "$(VIM_CWORD)" "<root>" -tc -tcpp -tpy -tvim -tgo 
cwd=$(VIM_ROOT)
errorformat=%f:%l:%m

They can be defined as a global task, and use a .ignore in each project to indicate what to search and what to skip.

Generate Ctags Database

[gen-tags]
command=ctags -R -f tags .
cwd=$(VIM_ROOT)
errorformat=

Don't forget set:

:set tags+=./tags;

It will allow vim search tags files in all parent directories of current buffer.

Universal File-Run Example

This is my own version of global file-run task:

[file-run]
command="$(VIM_FILEPATH)"
command:c,cpp="$(VIM_PATHNOEXT)"
command:go="$(VIM_PATHNOEXT)"
command:python=python "$(VIM_FILENAME)"
command:make=make -f "$(VIM_FILENAME)" run
command:emake=emake -e "$(VIM_FILENAME)"
command:javascript=node "$(VIM_FILENAME)"
command:sh=sh "$(VIM_FILENAME)"
command:lua=lua "$(VIM_FILENAME)"
command:perl=perl "$(VIM_FILENAME)"
command:ruby=ruby "$(VIM_FILENAME)"
command:zsh=zsh "$(VIM_FILENAME)"
command:bash=bash "$(VIM_FILENAME)"
command:fish=fish "$(VIM_FILENAME)"
command:php=php "$(VIM_FILENAME)"
command:erlang=escript "$(VIM_FILENAME)"
command:ps1=powershell -file "$(VIM_FILENAME)"
command:scala=scala "$(VIM_FILENAME)"
command:haskell=ghci "$(VIM_FILENAME)"
command:applescript=osascript "$(VIM_FILENAME)"
command:vim=echo cannot run $(VIM_FILEPATH)
output=terminal
cwd=$(VIM_FILEDIR)
save=2

Feel free to take and modify.

Internal Variable Example

asynctasks.vim allows command have internal variables in $(VIM:varname) form:

[test-var-replace]
command=echo $(VIM:my_name)

And in your vimrc, you can define a dictionary contains this internal variables:

let g:asynctasks_environ = {'my_name': 'Somebody'}

And command :AsyncTask test-var-replace will output:

Somebody
Clone this wiki locally