vi / vim editor: Can I paste text inside a colon command?
October 21, 2008 12:19 PM Subscribe
vi / vim editor: Can I paste text inside a colon command?
(Long-time emacs user here, having a great time learning vim) I often want to copy some text and then use it as the match portion of a substitution command, rather than re-typing it. I've looked over the FAQs, the tips, etc. and didn't see this addressed. Is it possible? Or is there some other vi-specific idiom for doing the same thing?
Bonus question: As I'm still getting my head around the vim terminology and resources, what/where could I have searched to find this answer myself?
(Long-time emacs user here, having a great time learning vim) I often want to copy some text and then use it as the match portion of a substitution command, rather than re-typing it. I've looked over the FAQs, the tips, etc. and didn't see this addressed. Is it possible? Or is there some other vi-specific idiom for doing the same thing?
Bonus question: As I'm still getting my head around the vim terminology and resources, what/where could I have searched to find this answer myself?
And in case you didn't know how to copy text: use 'v' to enter the visual mode, highlight the region, and then 'y' to yank it. That puts it in the default register, which gets overwritten all the time. To put it in another register, prefix the 'y' with '"'. For example, to place in the 'a' register, you would type: "ay. Then to paste while in ex mode, it's CTRL-R-a.
I love vi/vim because you can find it everywhere. But there's also a secret-society-handshake aspect to it :)
posted by sbutler at 12:50 PM on October 21, 2008
I love vi/vim because you can find it everywhere. But there's also a secret-society-handshake aspect to it :)
posted by sbutler at 12:50 PM on October 21, 2008
Arg... that's supposed to be: To put it in another register, prefix the 'y' with '"<letter>'
posted by sbutler at 12:53 PM on October 21, 2008
posted by sbutler at 12:53 PM on October 21, 2008
Response by poster: Great! Thanks for answering both parts of my question in one go. I was searching for answers with the term "command mode", but then using "paste" instead of "insert" (and "register" apparently would have helped, too)
posted by alb at 12:54 PM on October 21, 2008
posted by alb at 12:54 PM on October 21, 2008
You can also call up the "command line window", which you can edit like it was a normal buffer, or invoke items in it by hitting enter in normal or insert mode. In the command line window, you can use "p" to paste, just like when editing files. Read :help q: for more info.
posted by jepler at 2:15 PM on October 21, 2008
posted by jepler at 2:15 PM on October 21, 2008
if you're using vim, vimtutor is a great resource (on *nix just run vimtutor, in windows, check the start menu) quick intro to the terminology and methodology, as well as the must-know basics to be effective.
posted by namewithoutwords at 5:33 PM on October 21, 2008
posted by namewithoutwords at 5:33 PM on October 21, 2008
This thread is closed to new comments.
posted by sbutler at 12:40 PM on October 21, 2008 [2 favorites]