无法为屏幕的复制模式设置类似Vim的C-W f

时间:2009-05-21 22:36:20

标签: vim gnu-screen copy-mode

我希望通过

从Screen的复制模式打开vim的路径
Ctrl-A f

类似于我可以通过

在Vim中打开外部文件
Ctrl-W f

如何在屏幕的复制模式下在Vim中打开路径?


---感谢Samuil采取紧要关头

我们假设鼠标位于以下代码中的PATH /文件中,该代码表示​​屏幕开启时的显示

text[space]PATH/file[space]text

我在PATH /文件中按^ A f。它应该将文件的PATH保存到/ tmp / screenCopyFile,以便我们可以在cat应该开始的以下命令中使用^A f

^A: exec vim `cat PATH/file`

我手动运行该命令失败。它没有扩展cat命令,但它打开了一个名为cat的文件。

换句话说,我们希望字母f代表

exec vim `cat /tmp/screenCopyFile`

通过绑定在.screenrc。

感谢Rampion的回答!

2 个答案:

答案 0 :(得分:1)

我不知道vim太好了,但是用一些命令就可以轻松完成。 当您的pastebuffer中已有文件名时,您可以使用以下有用的命令:

^A : writebuf /tmp/.screenpomfile
^A : exec vim parameters

我不知道如何让vim从文件中读取文件名(我认为这是可能的),但你可以:exec自己编写的shell脚本能够解析`expr `表达式:

#!/bin/sh
vim `cat /tmp/.screenpomfile`

稍后您可以将自己的密钥绑定到这些操作,并非常有效地使用它们。

答案 1 :(得分:1)

好的,这是一个解决方案:

将以下内容放入/path/to/edit-file-under-cursor.screen

# edit-file-under-cursor.screen

# prevent messages from slowing this down
msgminwait 0
# copy path starting at cursor
stuff " Ebe "
# write the path to a file
writebuf /tmp/screen-copied-path
# open that file in vim in a new screen window
screen /bin/sh -c 'vim `cat /tmp/screen-copied-path`'
# turn message waiting back on
msgminwait 1

# vi: ft=screen

然后将此行添加到.screenrc

# bind CTRL-f to open the file starting at the cursor
# when in copy mode
bindkey -m ^f source /path/to/edit-file-under-cursor.screen

(适当更改/path/to/

然后,要使用,请确保重新启动screen(或重新加载.screenrc)。 使用^A[进入复制模式,将光标输入文件名的第一个字符, 然后点击CTRL-f

我已经测试了这个,它对我有用,所以请告诉我你是否有任何问题。

如果您想知道我如何知道如何操作,请检查man screen 看看所有各种命令是如何工作的。

可以做出的一个改进是能够找到路径的开头,但是我不能仅使用屏幕的复制模式移动命令(例如移动到第一个/的任何内容)来做到这一点。 “/a/path”已移至|“{/ p>的|/a/path

这是由于screen在复制模式下的移动命令的限制:

Movement keys:
  h, j, k, l move the cursor line by line or column by column.
  0, ^ and $ move to the leftmost column, to the first or last non-whitespace character on the line.
  H, M and L move the cursor to the leftmost column of the top, center or bottom line of the window.
  + and - positions one line up and down.
  G moves to the specified absolute line (default: end of buffer).
  | moves to the specified absolute column.
  w, b, e move the cursor word by word.
  B, E move the cursor WORD by WORD (as in vi).
  C-u and C-d scroll the display up/down by the specified amount of lines while preserving the cursor position. (Default: half screen-full).
  C-b and C-f scroll the display up/down a full screen.
  g moves to the beginning of the buffer.
  % jumps to the specified percentage of the buffer.
...
Searching:
  / Vi-like search forward.
  ? Vi-like search backward.
  C-a s Emacs style incremental search forward.
  C-r Emacs style reverse i-search.

因此,如果我们将上面的stuff行更改为

stuff "Bw Ebe "

它会移动到路径的开头,但它也会包含路径前面的任何非空白垃圾。所以,只要你的所有路径都是以空格分隔(两边),这应该可行。

实际上

stuff "B//^M E?/^Me "

似乎工作得相当好,因为它使用搜索来查找第一个和最后一个/(通过按CTRL-v键入vim中的^M,然后输入)。我还没有测试过所有边缘情况,但它似乎适用于:

 /a/path
 #/a/path
 /a/path#

然而,

会失败
 a/relative/path