Ⅰ. 插件描述
Extensible way to send commands and keys from vim to tmux.Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'kassio/vim-tmux-runner'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'kassio/vim-tmux-runner'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'kassio/vim-tmux-runner'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/kassio/vim-tmux-runner
Ⅳ. 文档说明
TmuxRunner
(not)Just another plugin to send commands to tmux, based on tslime.vim
Why TmuxRunner
The main reason to write a new tmux plugin was to avoid the setup needed to run
each programming language test suit. Nowadays I use ruby/rails with rpsec, testunit,
and minitest, and I'm trying to have some fun with Elixir.
Before TmuxRunner I had a setup of keymaps for each language and testing framework I wanted to
run, now I can have one setup that works for all of them.
TmuxRunner can check the current project structure and autoselect the right testing runner. For instance,
if there is a spec/spec_helper.rb file in the current directory, TmuxRunner will assume that your tests should
be ran with rspec.
With TmuxRunner you can send any command or key combination to a tmux
pane, just like tslime and vimux. Moreover you can run your test suit based on 3
scopes:
unscoped: Run your entire test suit.file: Run the current test file.nearest: Run the test nearest(back) the cursor.custom: Have a custom behaviour accordantly with the runner
The Runner
The runner is a dictionary with 3 keys:
name: Just a string with the runner name, e.g. 'rspec'.validate: A function that receives the current file and check if it's a valid test file.commandFor: A function that receives the current file and a scope to build
- command that will be sent to tmux.
The runner file is located in the ftplugin directory, and it's loaded based on the file
- It's also possible to create a file in the
ftdetectdirectory to select a specific runner - on your custom rules.
Features
TmuxRunner.setTmuxPane()or:SetTmuxPane
(Re)Selects tmux pane target to send commands and keys.

TmuxRunner.execute(text)or:Tmux
Executes a text in tmux pane. This command automatically executes
the text.

TmuxRunner.sendKeys(keys)
Sends keys to tmux pane, you can send more than one combination of
keys splitted by space.

TmuxRunner.register(runner)
Registers a Runner
TmuxRunner.selectRunner()or:SelectTmuxRunner

TmuxRunner.run(scope)
Runs selected runner with given scope.

:MapTmuxCmd
Creates a map for a command in the current session.

Suggested Setup
" Kill current process
noremap <leader>tc :call TmuxRunner.sendKeys('C-c')<CR>
" Kill current process and clear screen
noremap <leader>tl :call TmuxRunner.sendKeys('C-c C-l')<CR>
" Kill current process, clear screen and repeat last command
noremap <leader>tp :call TmuxRunner.sendKeys('C-c C-l C-p Enter')<CR>
" Reset tmux pane target
noremap <leader>tr :call TmuxRunner.setTmuxPane()<CR>
" Reset which runner will be used
noremap <leader>ct :call TmuxRunner.selectRunner()<CR>
" Run unscoped runner
noremap <leader>rt :call TmuxRunner.run('unscoped')<CR>
" Run runner with file scope
noremap <leader>rf :call TmuxRunner.run('file')<CR>
" Run runner with nearest scope
noremap <leader>rl :call TmuxRunner.run('nearest')<CR>
" Run runner with custom scope
noremap <leader>rc :call TmuxRunner.run('custom')<CR>
" Kill current process, clear screen and repeat last runner command
noremap <leader>rr :call TmuxRunner.sendKeys('C-c C-l') \|
\ call TmuxRunner.reExecute()<CR> 