- 
                Notifications
    You must be signed in to change notification settings 
- Fork 116
Command Specification
        Linwei edited this page Nov 28, 2022 
        ·
        12 revisions
      
    :AsyncRun[!] [options] {cmd} ...Macro variables in the parameters and -cwd= option will be expanded before executing:
$(VIM_FILEPATH)  - File name of current buffer with full path
$(VIM_FILENAME)  - File name of current buffer without path
$(VIM_FILEDIR)   - Full path of current buffer without the file name
$(VIM_FILEEXT)   - File extension of current buffer
$(VIM_FILENOEXT) - File name of current buffer without path and extension
$(VIM_PATHNOEXT) - Current file name with full path but without extension
$(VIM_CWD)       - Current directory
$(VIM_RELDIR)    - File path relativize to current directory
$(VIM_RELNAME)   - File name relativize to current directory 
$(VIM_ROOT)      - Project root directory
$(VIM_CWORD)     - Current word under cursor
$(VIM_CFILE)     - Current filename under cursor
$(VIM_GUI)       - Is running under gui ?
$(VIM_VERSION)   - Value of v:version
$(VIM_COLUMNS)   - How many columns in vim's screen
$(VIM_LINES)     - How many lines in vim's screen
$(VIM_SVRNAME)   - Value of v:servername for +clientserver usage
$(VIM_PRONAME)   - Name of current project root directory
$(VIM_DIRNAME)   - Name of current directory
Vim's filename modifiers are also accepted:
%:p     - File name of current buffer with full path
%:t     - File name of current buffer without path
%:p:h   - File path of current buffer without file name
%:e     - File extension of current buffer
%:t:r   - File name of current buffer without path and extension
%       - File name relativize to current directory
%:h:.   - File path relativize to current directory
<cwd>   - Current directory
<cword> - Current word under cursor
<cfile> - Current file name under cursor
But modifiers are not recommended, because it is evaluated before :AsyncRun command starts, so if there is a -cwd=xxx option, some modifiers may yield an out-dated result for the old working directory.
| Option | Default Value | Description | 
|---|---|---|
| -mode=? | "async" | specify how to run the command as -mode=?, available modes are"async"(default),"bang"(with!command) and"terminal"(in internal terminal), see running modes for details. | 
| -cwd=? | unset | initial directory (use current directory if unset), for example use -cwd=<root>to run commands in project root directory, or-cwd=$(VIM_FILEDIR)to run commands in current buffer's parent directory. | 
| -save=? | 0 | use -save=1to save current file,-save=2to save all modified files before executing. | 
| -program=? | unset | set to maketo use&makeprg,grepto use&grepprtandwslto execute commands in WSL (windows 10), see command modifiers. | 
| -post=? | unset | vimscript to exec after job finished, spaces must be escaped to '\ ' | 
| Option | Default Value | Description | 
|---|---|---|
| -auto=? | unset | event name to trigger QuickFixCmdPre/QuickFixCmdPost[name] autocmd. | 
| -raw | unset | use raw output if provided, and &errorformatwill be ignored. | 
| -strip | unset | remove the heading/trailing messages if provided (omit command and "[Finished in ...]" message). | 
| -errorformat=? | unset | errorformat for error matching, if it is unprovided, use current &errorformatvalue. Beware that%needs to be escaped into\%. | 
| -silent | unset | provide -silentto prevent open quickfix window (will overrideg:asyncrun_opentemporarily) | 
| -scroll=? | unset | set to 0to prevent quickfix auto-scrolling | 
| -once=? | unset | set to 1to buffer output and flush when job is finished, useful when there are multi-line patterns in yourerrorformat | 
| -encoding=? | unset | specify command encoding independently (overshadow g:asyncrun_encs) | 
| Option | Default Value | Description | 
|---|---|---|
| -pos=? | "bottom" | When using internal terminal with -mode=term,-posis used to specify where to split the terminal window, it can be one of"tab","TAB","curwin","top","bottom","left","right"and"external". And you can customize new runners and pass runner's name to-posoption. | 
| -rows=num | 0 | When using a horizontal split terminal, this value represents the height of terminal window. | 
| -cols=num | 0 | When using a vertical split terminal, this value represents the width of terminal window. | 
| -focus=? | 1 | set to 0to prevent focus changing when-mode=term | 
| -reuse=? | 1 | set to 0to prevent reusing previous terminal window | 
| -hidden=? | unset | set to 1to initbufhiddentohidefor terminal buffer and set to0to initbufhiddentodelete | 
| -listed | 1 | when using -mode=term, set to 0 to hide the terminal in the buffer list | 
| -close | unset | when using -mode=term, close the terminal automatically when terminal process is finished | 
| Option | Default Value | Description | 
|---|---|---|
| -option=? | empty | arbitrary string can be used to pass additional information to the user-defined runner, eg. :AsyncRun -option=xxx ... | 
call asyncrun#run('<bang>', opts, command)arguments:
- 
'<bang>': either'!'or an empty string''.
- opts: a dictionary of options, like {'post': 'echo 123'}
- command: a string of shell command.
examples:
call asyncrun#run('', {}, 'echo "haha"')
call asyncrun#run('', {'mode':'terminal', 'pos':'TAB'}, 'ls -la')The function form can be used to construct complex command.