tmux:如何在光标下打开文件 [英] tmux: how to open file under cursor

查看:125
本文介绍了tmux:如何在光标下打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是vim用户,习惯了gf命令,该命令在光标下打开文件.

i am a vim user and got used to the gf command, which opens the file under the cursor.

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

Now i wanted to ask, if there is something like that for tmux.

我可以在一个tmux窗格中导航,并且经常发生在光标下面有一个文件路径的情况.现在,我希望可以用vim在光标下打开该文件.

I can navigate through a tmux-pane and it happens often that there is a file-path under the cursor. Now i like to have the possibility to open that file under the cursor with vim.

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

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

Maybe there is a possibility to run a sh-script in that navigation-mode when invoking a special key-combination? that would make it possible to write my own scripts like i got used to in vim with vimscript.

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

I am already using some vi-copy modes in mux .tmux.conf

# 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"

推荐答案

有一个tmux的mod可以在模式"下绑定任何复杂的动作:

There's a mod for tmux allowing to bind an action of any complexity in 'mode': http://ershov.github.io/tmux/

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

There's an example of how to mark the word under cursor using that patch:

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中打开当前文件:

Hence, to open the current file in vim:

mark-current-word
split-window -c [f #{pane_current_path}] -l 5 "vim -R [shell-quote [copy-mode-selection]]"

这篇关于tmux:如何在光标下打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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