使用tmux + vim发送测试代码行的键绑定? [英] Key bindings to send lines of test code with tmux+vim?

查看:78
本文介绍了使用tmux + vim发送测试代码行的键绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tmux + vim 创建类似ide的设置.我已经在互联网上看到很多有关此的文章,但是我一直无法弄清楚如何做一件关键的事情:执行代码测试行.

例如,您可以创建一个tmux会话,其vim窗格用于编写代码,而python窗格用于执行测试,如下所示:

 #创建一个新的Tmux会话.session ="ide"tmux启动服务器tmux new-session -d -s $ session -n ide#水平分割窗格并启动vim.tmux选择p -t 1tmux splitw -v -p 50tmux选择p -t 1tmux发送键"vim" C-m#进入插入模式并开始编码...tmux发送键"i"tmux发送键"print('hello world')" C-m#选择第二个窗格并启动python.tmux选择p -t 2tmux发送键"python" C-m#附加到tmux会话.tmux附加-t ide 

因此,我知道您可能如何使用 tmux发送键或tmux的命令模式(< prefix>:)将命令发送到另一个窗格.但是,我想制作一个vim键绑定,该键绑定可以复制我所在的行,然后通过几次快速击键将其发送到相对的窗格.

如果您有一些神奇的调味料,我将不胜感激!

解决方案

我认为 https://github.com/jpalardy/vim-slime 是您要寻找的.

一旦安装并配置好( tmux 不是默认设置, screen 是),就可以使用< C-c>在光标下方执行文本;< C-c> .

以下内容对我有用:

  • 安装Vim-slime.我正在使用Vundle,因此我在 .vimrc 中添加了以下内容:
    插入'jpalardy/vim-slime',并在vim中运行:PluginInstall .

  • 通过将以下内容添加到您的 .vimrc 中来为tmux配置史莱姆:
    让g:slime_target ="tmux"

  • 尝试发送一条带有默认键绑定( C-c C-c )的vim-slime的行.Vim-Slime应该提示您输入Tmux的套接字和目标窗格.我发现Tmux的插座有:
    echo $ TMUX |cut -f1 -d','.

  • 或者,您可以使用:SlimeConfig .

  • 现在可以使用了!

I am trying to create an ide-like setup with tmux + vim. I've seen a lot written about this on the internet, but I've been unable to figure out how to do one critical thing: execute test lines of code.

For example, you may create a tmux session with a vim pane for writing code and a python pane for executing tests, like so:

# Create a new Tmux session.
session="ide"
tmux start-server
tmux new-session -d -s $session -n ide

# Split the pane horizontally and launch vim.
tmux selectp -t 1
tmux splitw -v -p 50
tmux selectp -t 1
tmux send-keys "vim" C-m

# Enter insert mode and start coding...
tmux send-keys "i"
tmux send-keys "print('hello world')" C-m

# Select the second pane and launch python.
tmux selectp -t 2
tmux send-keys "python" C-m

# Attach to tmux session.
tmux attach -t ide

So, I am aware of how you might use tmux send-keys or tmux's command mode (<prefix> :) to send commands to another pane. However, I'd like to make a vim key binding that copies whatever line I'm on and sends this to the opposite pane in a couple of quick keystrokes.

If you have some magic sauce, I'd be grateful if you could share!

解决方案

I think https://github.com/jpalardy/vim-slime is what you are be looking for.

Once installed and configured (tmux is not the default used, screen is), you can execute the text under the cursor with <C-c><C-c>.

The following worked for me:

  • Install Vim-slime. I'm using Vundle, so I added the following to my .vimrc:
    Plugin 'jpalardy/vim-slime', and ran :PluginInstall in vim.

  • Configure slime for tmux by adding the following to your .vimrc:
    let g:slime_target = "tmux"

  • Try sending a line with vim-slime with the default key-binding (C-c C-c). Vim-Slime should prompt you for Tmux's socket and target pane. I found Tmux's socket with:
    echo $TMUX | cut -f1 -d','.

  • Alternatively, you can use :SlimeConfig.

  • Now it's working!

这篇关于使用tmux + vim发送测试代码行的键绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆