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