将VIM上的线发送到另一个窗格或TMUX中的部分

发布于 2025-01-28 15:53:55 字数 471 浏览 3 评论 0 原文

我正在尝试使用VIM+TMUX设置来在R中写

代码R.

看起来很简单,但我对VIM的变量或功能不了解,我对Tmux是新的。

通过一些研究,我找到了 tmux send-keys 命令,看起来很有希望,因此我目前能够映射

之类的内容:silite! tmux send -keys -t 0:0.0'print(“ test”)'enter

,这有效地运行了“ pand”命令“窗格” 0:0.0“同名易于参考)。不知道这是否有效,也不知道如何将'print()'替换为某些编辑器的文本。

最终的目标是具有诸如< localleader> rr 之类的键键,以在r,< localleader> r [Motion] 运行运动和类似的东西中运行一行。运行选定的代码。

谢谢!

I am trying to use a vim+tmux setup to write code in R.

For that, I need to find a way to send lines (better if motions) to a terminal in other tmux pane (or section, if possible) which is running R.

Looks like a simple task, but I don't understand much about vim's variables or functions, and I'm new on tmux.

With some research, I found the tmux send-keys command, which looks pretty promising, so I'm currently able to map something like

:silent ! tmux send-keys -t 0:0.0 'print("test")' Enter

and that effectively runs the "print" command in the pane "0:0.0" (I'm thinking in always open a section with the same name for easy of reference). No idea if that's efficient, and no idea about how to substitute the 'print()' to some editor's text.

The final goal is to have keybindings like <localleader>rr to run a line in R, <localleader>r[motion] to run the motion, and something similar to run selected code.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山色无中 2025-02-04 15:53:55

有点晚,但是您可以尝试插件 vimtux 。它允许您选择一个特定的TMUX窗格,您可以在其中使用(也)动作(例如&lt; read&gt; rap &lt; rg&gt; rgg 等)。

A bit late, but you can try the plugin vimtux. It allows you to select a specific tmux pane, where you can send text to this tmux pane using (also) motions (e.g. <leader>rap, <leader>rgg etc.).

三人与歌 2025-02-04 15:53:55

$ home/.vim/plugin )中

function Send_to_Pane(text)
  if !exists("g:tmux_target")
    call Tmux_Vars()
  end
  echo system("tmux send-keys -t " . g:tmux_target . " '" . substitute(a:text, "'", "'\\\\''", 'g') . "'")
endfunction

function Tmux_Pane_Names(A,L,P)
  return system("tmux list-panes -a | awk '/active/ {printf \"%s:%s\n\", $1, $2}' FS=:")
endfunction

function Tmux_Vars()
  if !exists("g:tmux_target")
    let g:tmux_target = "%1"
  end
  let g:tmux_target = input("session:window.pane> ", "%1", "custom,Tmux_Pane_Names")
endfunction

vmap <C-c><C-c> "ry :call Send_to_Pane(@r)<CR>
nmap <C-c><C-c> vip<C-c><C-c>
nmap <C-c>v :call Tmux_Vars()<CR>

,在vim中,如果您键入&lt; cc&gt;&gt;&gt;&lt; cc&gt; ,当前段落将被发送到窗格(假设 vim 是使用 textObjects 启用功能构建的)。在视觉模式下,将发送选定的文本。要仅发送当前行,您可以通过执行 v&lt; cc&gt;&lt; cc&gt; 来使用线路视觉。 ( vim 实际上没有对线路文本对象的内置支持,但是有可用的插件。)

请注意,可以通过在运行中运行的过程中检查$ tmux_pane可以轻松确定目标窗格的正确值那个窗格。您可以使用 0:2.1 之类的特定目标,但是上面使用%1 作为默认值。这可能是一个不好的默认值。 YMMV

With some minor tweaks to slime.vim, you can do this by putting the following file in your vim plugin dir (eg $HOME/.vim/plugin)

function Send_to_Pane(text)
  if !exists("g:tmux_target")
    call Tmux_Vars()
  end
  echo system("tmux send-keys -t " . g:tmux_target . " '" . substitute(a:text, "'", "'\\\\''", 'g') . "'")
endfunction

function Tmux_Pane_Names(A,L,P)
  return system("tmux list-panes -a | awk '/active/ {printf \"%s:%s\n\", $1, $2}' FS=:")
endfunction

function Tmux_Vars()
  if !exists("g:tmux_target")
    let g:tmux_target = "%1"
  end
  let g:tmux_target = input("session:window.pane> ", "%1", "custom,Tmux_Pane_Names")
endfunction

vmap <C-c><C-c> "ry :call Send_to_Pane(@r)<CR>
nmap <C-c><C-c> vip<C-c><C-c>
nmap <C-c>v :call Tmux_Vars()<CR>

Now, in vim, if you type <C-c><C-c>, the current paragraph will be sent to the pane (assuming vim was built with the textobjects feature enabled). In visual mode, the selected text will be sent. To send just the current line, you can use linewise-visual by doing V<C-c><C-c>. (vim doesn't really have builtin support for linewise text objects, but there are plugins available.)

Note that the correct value for the target pane can easily be determined by inspecting $TMUX_PANE in the process running in that pane. You can use specific targets like 0:2.1, but the above uses %1 as a default. This is probably a bad default to use. YMMV

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文