无法为屏幕的复制模式提供类似 Vim 的 CW f
我想从屏幕的复制模式打开到 vim 的路径,
Ctrl-A f
就像我可以通过
Ctrl-W f
How can you open a path in Vim in Screen's copy-mode?
--- 在 Vim 中打开外部文件一样感谢 Samuil 解决了关键问题
让我们假设鼠标位于以下代码中的 PATH/file 处,这代表屏幕打开时的显示,
text[space]PATH/file[space]text
我在 PATH/file 处按 ^A f 。 它应该将文件的 PATH 保存到 /tmp/screenCopyFile ,以便我们可以在 ^A f
应该启动的以下命令中使用 cat
:
^A: exec vim `cat PATH/file`
我手动运行命令不成功。 它没有扩展 cat 命令,但它打开一个名为 cat 的文件。
换句话说,我们希望
exec vim `cat /tmp/screenCopyFile`
通过在.screenrc中绑定来使字母f
代表字母。
感谢 Rampion 的回答!
I want open a path to vim from Screen's copy-mode by
Ctrl-A f
similarly as I can open external files in Vim by
Ctrl-W f
How can you open a path in Vim in Screen's copy-mode?
--- Thank you for Samuil to get the crux move
Let's assume mouse is at PATH/file in the following code which represents display when Screen is on
text[space]PATH/file[space]text
I press ^A f at PATH/file. It should save the PATH of the file to /tmp/screenCopyFile such that we can use cat
in the following command which the ^A f
should start:
^A: exec vim `cat PATH/file`
I run the command manually unsuccessfully. It did not expand the cat command, but it opens a file called cat.
In other words, we want to make the letter f
stands for
exec vim `cat /tmp/screenCopyFile`
by binding in .screenrc.
Thank you Rampion for your answer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这是一个解决方案:
将以下内容放入
/path/to/edit-file-under-cursor.screen
中:然后将此行添加到您的
.screenrc
中:(更改然后
,要使用,请确保重新启动
screen
(或重新加载.screenrc
)。使用
^A[
进入复制模式,将光标移至文件名的第一个字符,然后点击
CTRL-f
。我已经测试过这个,它对我有用,所以如果您有任何问题请告诉我。
如果您想了解我如何知道如何执行此操作,请检查
man screen
以看看所有不同的命令是如何工作的。
可以进行的一个改进是能够找到路径的开头,但我无法仅使用屏幕的复制模式移动命令可靠地做到这一点(例如,移动到第一个
/
的任何内容) “/a/path
”移至“|/a/path
”的|
)这是由于
的限制screen
在复制模式下的移动命令:因此,如果我们将上面的
stuff
行更改为,它将移动到路径的开头,但它也会包含任何非空白垃圾来到了小路之前。 因此,只要您的所有路径都是空格分隔的(两侧),这应该可以工作。
实际上
似乎工作得相当好,因为它使用搜索来查找第一个和最后一个
/
(通过按 CTRL-v 在 vim 中键入^M
,然后输入)。 我还没有测试所有的边缘情况,但它似乎适用于:但是,它会失败
Ok, here's a solution:
Put the following in
/path/to/edit-file-under-cursor.screen
:Then add this line to your
.screenrc
:(changing the
/path/to/
appropriately)Then, to use, make sure you restart
screen
(or reload the.screenrc
).Enter copy mode with
^A[
, cursor to the first character of a filename,then hit
CTRL-f
.I've tested this, and it works for me, so tell me if you have any issues.
If you want to see how I knew how to do this, check
man screen
tosee how all the various commands work.
One improvement that could be made is to be able to find the beginning of a path, but I couldn't do that reliably with only screen's copy mode movement commands (e.g. anything that moved to the first
/
of "/a/path
" moved to the|
of "|/a/path
")This is due to the limitations of
screen
's movement commands in copy mode:So if we changed the
stuff
line above toit would move to the start of a path, but it would also include any non-whitespace junk that came before the path. So as long as all your paths are whitespace delimited (on both sides) this should work.
Actually
seems to work fairly well, since that uses searching to find the first and last
/
(type the^M
in vim by hitting CTRL-v, then enter). I haven't tested all the edge cases, but it seems to work for:However, it's going to fail for
我对 vim 不太了解,但是用几个命令应该可以轻松完成。
当您的粘贴缓冲区中已经有文件名时,您可以使用这些有用的命令:
我不知道如何使
vim
从文件中读取文件名(我认为这是可能的),但您可以: exec
在能够解析`expr
` 表达式的 shell 中编写的您自己的脚本:稍后您可以将自己的键绑定到这些操作,并非常有效地使用它们。
I do not know vim too good, but with a few commands it should be done easily.
When you already have filename in your pastebuffer, you can use these useful commands:
I do not know how to make
vim
read filename from file (I think it is possible), but you could:exec
your own script written in a shell able to parse`expr
` expressions:Later you can bind your own keys to these actions, and use them quite effectively.