Reputation: 4343
Quite often when I'm reading some documentation and also doing the hands-on in terminal I want to copy some block of command text from the doc, then edit it (such as replace a host name, etc.) then paste it to the terminal and execute it. I can do this with another editor or with a temp file in my current dir. However, this process is cumbersome. I think I have seen somebody achieving this with a somewhat inline
vim editor. The flow is that he hits some shortcut key, a vim editor opens right in the terminal with the content in the clipboard in it already, and then he makes the changes. Upon saving and exiting, the content shows up on the terminal. All he needs to do then is hit enter. Unfortunately I can't ask this person because I only saw it in passing. How do I achieve this?
Upvotes: 1
Views: 69
Reputation: 11790
You could bind the "edit command line" to some keybinding i think the default is
Ctrl-x Ctrl-e
then you can use the clipboard register "+p
or even start inserting mode and typing Ctrl-r +
. after saving and exiting the editor the command will be at your command line.
Upvotes: 2
Reputation: 6016
You could define an alias for vim which pastes the *
register, and overwrite the save command so it saves to the *
register. However there is an easier way.
readline has an vi-mode just add set editing-mode vi
and set keymap vi-command
to your .inputrc
.
Now your readline is in vi mode once you press <ESC>
. v
brings up vim to edit the actual line in your terminal. But for simple stuff you won't even need it. Your readline now accepts cw
,dw
and so on... (But only vi commands, no vim).
This is of course only a solution, if you anyway want to have vi commands in your terminal. But since you are even trying to edit your clipboard in vi, i would guess that you are okay with that.
Upvotes: 1