无法为屏幕的复制模式提供类似 Vim 的 C-W f
-
23-08-2019 - |
题
我想从屏幕的复制模式打开一条通往 vim 的路径
Ctrl-A f
类似于我可以在 Vim 中打开外部文件
Ctrl-W f
如何在 Screen 的复制模式下在 Vim 中打开路径?
--- 感谢 Samuil 完成关键动作
假设鼠标位于以下代码中的 PATH/file 处,代表屏幕打开时的显示
text[space]PATH/file[space]text
我在 PATH/file 处按 ^A f。它应该将文件的路径保存到 /tmp/screenCopyFile 以便我们可以使用 cat
在以下命令中 ^A f
应该开始:
^A: exec vim `cat PATH/file`
我手动运行命令失败。它没有扩展 cat 命令,但它打开一个名为 cat 的文件。
换句话说,我们想让这封信 f
代表
exec vim `cat /tmp/screenCopyFile`
通过在 .screenrc 中绑定。
谢谢拉皮恩的回答!
解决方案
好的,这是一个解决方案:
将以下内容放入 /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
” 移至 |
的 ”|/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 "
似乎工作得相当好,因为它使用搜索来查找第一个和最后一个 /
(输入 ^M
在 vim 中按 CTRL-v,然后输入)。我还没有测试所有的边缘情况,但它似乎适用于:
/a/path #/a/path /a/path#
然而,它将会失败
a/relative/path
其他提示
我不知道VIM太好,但有几个命令就应该很容易做到。 如果你已经有文件名中的pastebuffer,您可以使用这些有用的命令:
^A : writebuf /tmp/.screenpomfile
^A : exec vim parameters
我不知道如何使vim
从文件中读取(我认为这是可能的)的文件名,但你可以:exec
自己的脚本编写能够解析`expr
`表达式壳:
#!/bin/sh
vim `cat /tmp/.screenpomfile`
之后,您可以绑定自己的钥匙,以这些行动,而且相当有效地使用它们。