Can't use V-shaped CW f for screen copy mode
I want to open the path to vim from Screen copy-mode to
Ctrl-A f
the same way I can open external files in Vim
Ctrl-W f
How can you open a path in Vim in screen copy mode?
--- Thank you for Samuel getting a cool move
Suppose the mouse is in the PATH / file in the following code that displays the display when the screen is on.
text[space]PATH/file[space]text
I press ^ A f in the PATH / file. It should save the PATH of the file to / tmp / screenCopyFile so that we can use it cat
in the next command that we should run ^A f
:
^A: exec vim `cat PATH/file`
I run the command manually with no luck. It hasn't expanded the cat command, but it opens a file named cat.
In other words, we want the letter to f
mean
exec vim `cat /tmp/screenCopyFile`
by binding in .screenrc.
Thank you Rampion for your answer!
a source to share
Ok, here's the solution:
Place 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
(change /path/to/
accordingly)
Then, to use, make sure you restart screen
(or reboot .screenrc
). Enter copy mode with by ^A[
pointing to the first character of the file name, then press CTRL-f
.
I tested this and it works for me, so tell me if you have any problems.
If you want to see how I know how to do this, check the box man screen
on see how all the different commands work.
One of the improvements that could be made, is the ability to find the beginning of the way, but I could not do so reliably only by using motion commands copy mode screen (for example, all that has moved into the first /
of the /a/path
"moved in |
to" |/a/path
")
This is due to the limitations of screen
the copy mode move commands :
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). Cu and Cd scroll the display up / down by the specified amount of lines while preserving the cursor position. (Default: half screen-full). Cb and Cf 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. Ca s Emacs style incremental search forward. Cr Emacs style reverse i-search.
So if we changed the line stuff
above to
stuff "Bw Ebe "
it would move to the start of the path, but it would also include any non-zero garbage that came before this path. So as long as all your paths are space-delimited (on both sides) this should work.
Actually
stuff "B//^M E?/^Me "
seems to work well enough as it uses search to find the first and last /
(type ^M
in vim by hitting CTRL-v then type). I haven't tested all edges, but it seems to work for:
/ a / path # / a / path / a / path #
However, it will fail for
a / relative / path
a source to share
I don't know that vim is too good, but with a few commands it should be easy. When you already have the filename in your pastebuffer, you can use these useful commands:
^A : writebuf /tmp/.screenpomfile
^A : exec vim parameters
I don't know how to make it vim
read the filename from a file (I think it is possible), but you could :exec
create your own script in a shell capable of parsing expressions `expr
:
#!/bin/sh
vim `cat /tmp/.screenpomfile`
You can later bind your own keys to these actions and use them quite effectively.
a source to share