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!
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 screentosee 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
stuffline 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^Min 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