无法为屏幕的复制模式提供类似 Vim 的 CW f

发布于 2024-07-22 05:08:31 字数 770 浏览 6 评论 0原文

我想从屏幕的复制模式打开到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ偶尔ゞ 2024-07-29 05:08:31

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

将以下内容放入 /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

更改然后

,要使用,请确保重新启动 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 "

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

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

但是,它会失败

 a/relative/path

Ok, here's a solution:

Put the following in /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

Then add this line to your .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

(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 to
see 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:

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.

So if we changed the stuff line above to

stuff "Bw Ebe "

it 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

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

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:

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

However, it's going to fail for

 a/relative/path
神经暖 2024-07-29 05:08:31

我对 vim 不太了解,但是用几个命令应该可以轻松完成。
当您的粘贴缓冲区中已经有文件名时,您可以使用这些有用的命令:

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

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

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

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

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:

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

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:

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

Later you can bind your own keys to these actions, and use them quite effectively.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文