6

私はvimユーザーgfで、カーソルの下のファイルを開くコマンドに慣れました。

今、tmuxにそのようなものがあるかどうか尋ねたいと思いました。

tmux ペインをナビゲートできますが、カーソルの下にファイル パスがあることがよくあります。今、私はそのファイルをカーソルの下でvimで開くことができるようにしたいと思っています。

  • A: 現在のウィンドウで
  • B: vim を含めて開いた別のウィンドウで

特別なキーの組み合わせを呼び出すときに、そのナビゲーション モードで sh スクリプトを実行する可能性はありますか? これにより、vimscript を使用して vim で慣れたように、独自のスクリプトを作成できるようになります。

私はすでにmux .tmux.confでいくつかのvi-copyモードを使用しています

# 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

目的を達成するには、コマンド ラインで stdin を使用し (xargsそれを実行できます) tmux、 anew-windowで、コピー バッファーからの引数を使用してデータを開くように指示する必要があります。

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

これにはさらに調整が必要です (適切なセッションを取得する、適切なコマンドを取得する、$EDITORvim の代わりに使用するなど)。

これは非常に危険です。コピーを考えてみてください/foo/bar/my;rm -rf /

また、現状では、これは tmux の作業ディレクトリへの相対パスに対してのみ機能します。

于 2016-02-15T14:56:45.990 に答える