6

我是 vim 用户,习惯了gf打开光标下文件的命令。

现在我想问一下,tmux 是否有类似的东西。

我可以在 tmux 窗格中导航,并且经常发生光标下有一个文件路径的情况。现在我喜欢用 vim 打开光标下的那个文件。

  • A:在当前窗口
  • B:在另一个包含并打开vim的窗口中

调用特殊组合键时,也许有可能在该导航模式下运行 sh 脚本?这样就可以编写自己的脚本,就像我习惯在 vim 中使用 vimscript 一样。

我已经在 mux .tmux.conf 中使用了一些 vi 复制模式

# VIM
# ===================================================================

# Vimlike copy mode.
unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-selection

# Enable vi keys.
setw -g mode-keys vi

# https://coderwall.com/p/4b0d0a/how-to-copy-and-paste-with-tmux-on-ubuntu
bind -t vi-copy y copy-pipe "xclip -sel clip -i"
4

3 回答 3

1

tmux 有一个 mod,允许在“模式”中绑定任何复杂的动作:http: //ershov.github.io/tmux/

有一个如何使用该补丁标记光标下的单词的示例:

proc is_word_char {c} {
    print [scan $c %c]
    return [expr {$c > " " && $c != "\x7f"}]
}

proc mark-current-word {} {
    clear-selection
    set l [copy-mode-screenline]
    set x [copy-mode-get-cx]
    if {![is_word_char [string range $l $x $x]]} return
    incr x
    while {[is_word_char [string range $l $x $x]]} {
        cursor-right
        incr x
    }
    incr x -2
    begin-selection
    while {[is_word_char [string range $l $x $x]]} {
        cursor-left
        if {$x < 1} return
        incr x -1
    }
}

# Open selection in a vim mini-window (no shell and files)
bind-key -t vi-copy y tcl {
    split-window -c [f #{pane_current_path}] -l 5 "
        echo -n [shell-quote [copy-mode-selection]] | vim -R -"
}

因此,要在 vim 中打开当前文件:

mark-current-word
split-window -c [f #{pane_current_path}] -l 5 "vim -R [shell-quote [copy-mode-selection]]"
于 2016-04-18T15:32:16.380 回答
1

为了实现您想要的,您需要在命令行中使用标准输入(xargs可以这样做)并告诉tmux在 anew-window中使用来自复制缓冲区的参数打开数据:

bind -t vi-copy y copy-pipe "xargs -I{} tmux new-window 'vim {}'"

这需要更多的调整(获得正确的会话、正确的命令、使用$EDITOR而不是 vim 等。

这是相当危险的:想想抄袭/foo/bar/my;rm -rf /

此外,按原样,这仅适用于相对于 tmux 工作目录的路径。

于 2016-02-15T14:56:45.990 回答
0

所以我使用以下绑定运行它:

bind -t vi-copy y copy-pipe "xargs -I{} tmux send-keys -t 1 ';edit {}' Enter && tmux select-pane -t 1"

笔记

  • 我将 vim 命令 : 更改为 ;
  • 我在窗格 1 中有一个打开的 vim
于 2016-02-15T18:39:22.483 回答