linux 脚本的异步执行,Vim 异步运行 Shell 指令的插件 - AsyncRun - Skywind Inside

自制另一个新的 Vim 8.0 专用异步插件:asyncrun.vim,它可以让你在 Vim 里面异步运行各种 Shell 指令并且把结果实时输出到 Quickfix,需要 Vim 7.4.1829 以上版本。

安装方法

到插件首页 https://github.com/skywind3000/asyncrun.vim 下载项目,并拷贝 asyncrun.vim 到你的 ~/.vim/plugin。或者使用 Vundle 指向 skywind3000/asyncrun.vim 来自动更新。

基本教程

使用 gcc 异步编译当前文件:

:AsyncRun gcc % -o %<

:AsyncRun g++ -O3 % -o %< -lpthread

该命令会在后台运行 gcc 并且把输出实时显示在 Quickfix 窗口,宏 % 代表当前文件名,%< 代表没有扩展名的文件名。

异步运行 make:

:AsyncRun make

:AsyncRun make -f makefile

异步调用 grep:

:AsyncRun! grep -R word .

:AsyncRun! grep -R .

默认 :AsyncRun 运行命令后,输出添加到 Quickfix时 Quickfix 会自动滚动到最下面那一行,使用感叹号修饰符以后,可以避免 Quickfix 自动滚动。同时 代表当前光标下面的单词。

编译 go项目:

:AsyncRun go build %:p:h

宏 %:p:h 代表当前文件的目录

查询 man page,异步 git push ,以及把设置 F7异步编译当前文件:

:AsyncRun! man -S 3:2:1

:AsyncRun git push origin master

:noremap :AsyncRun gcc % -o %<

使用手册

AsyncRun – Run shell command:

:AsyncRun{!} [cmd] ...

后台运行命令并且实时输出到 quickfix 窗口,如果有感叹号修饰符,quickfix 窗口的自动滚动将会禁止。

命令参数以空格分割,接受下面这些以 ‘%‘, ‘#‘ or ‘

%: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

- Current working directory

- Current word under cursor

- Current file name under cursor

运行一个命令前,环境变量也会做如下设置:

$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_CWD - Current directory

$VIM_RELDIR - File path relativize to current directory

$VIM_RELNAME - File name relativize to current 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_MODE - Execute via 0:!, 1:makeprg, 2:system()

$VIM_COLUMNS - How many columns in vim's screen

$VIM_LINES - How many lines in vim's screen

AsyncStop – Stop the running job:

:AsyncStop{!}

停止后台任务(使用 TERM信号),如果有感叹号修饰,则使用 KILL 信号结束

基本设置:

g:asyncrun_exit - 字符串,如果不为空那么任务结束时会被执行(VimScript)

g:asyncrun_bell - 如果非零的话,任务结束后会响铃(终端输出控制符 \a)

g:asyncrun_mode - 0:异步(需要 vim 7.4.1829) 1:同步 2:直接运行

全局变量:

g:asyncrun_code - 退出码

g:asyncrun_status - 状态 'running', 'success' or 'failure'

aa5adb8150d34503256fd49a10f77801.gif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
各个插件配置设置单独配置: ls bundle/.configs/ : asyncrun.vim_conf.vim EasyMotion_conf.vim lookupfile_conf.vim supertab_conf.vim vim-markdown-toc_conf.vim bufexplorer_conf.vim eclim_conf.vim maximizer_conf.vim syntastic_conf.vim vim-powerline_conf.vim CCTree_conf.vim errormarker.vim_conf.vim neocomplcache_conf.vim tagbar_conf.vim vimshell.vim_conf.vim CompleteParameter.vim_conf.vim fuzzyfinder_conf.vim neocomplete.vim_conf.vim ultisnips_conf.vim vim-snippets_conf.vim deoplete-jedi_conf.vim grep.vim_conf.vim neosnippet_conf.vim unite.vim_conf.vim ydtrans_conf.vim deoplete.nvim_conf.vim init.vim nerdcommenter_conf.vim vcscommand_conf.vim YouCompleteMe_conf.vim DoxygenToolkit.vim_conf.vim jedi-vim_conf.vim nerdtree_conf.vim VimIM_conf.vim DrawIt_conf.vim jupyter-vim_conf.vim Nvim-R_conf.vim vim-instant-markdown_conf.vimvimrc文件进行基础配置: let mapleader="," let g:mapleader="," autocmd! :mapclear "==========很多插件,可能进行过修改, 若感觉不爽,可以在.vim搜索lidong, 进行还原=================== +-- 11 lines: 插件依赖设置 ---------------------------------------------------------------------------------- source ~/.vim/bundle/.configs/init.vim +--104 lines: F1~F12快捷键映射------------------------------------------------------------------------------- +-- 22 lines: 非F1~F12快捷键--------------------------------------------------------------------------------- +-- 5 lines: 自己定义的命令 -------------------------------------------------------------------------------- +-- 17 lines: 窗口配置--------------------------------------------------------------------------------------- +--229 lines: 简单配置--------------------------------------------------------------------------------------- +-- 55 lines: Gui选项 放到.gvimrc---------------------------------------------------------------------------- +-- 5 lines: 高亮 注释代码的颜色---------------------------------------------------------------------------- +-- 6 lines: 高亮 menu color ------------------------------------------------------------------------------- +-- 7 lines: 高亮 当前行(列)-------------------------------------------------------------------------------- +-- 3 lines: 高亮列----------------------------------------------------------------------------------------- +-- 13 lines: 高亮tab标签------------------------------------------------------------------------------------ +-- 8 lines: 高亮 其他-------------------------------------------------------------------------------------- +-- 10 lines: 字符编码(多字节)------------------------------------------------------------------------------- +-- 12 lines: 设置C/C++语言的具体缩进方式 eg. switch case 缩进----------------------------------------------- +-- 42 lines: vim折叠功能------------------------------------------------------------------------------------ +-- 19 lines: 文件比较--------------------------------------------------------------------------------------- +-- 26 lines: 单词列表匹配-----------------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值