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?
posted by alb to computers & internet (6 comments total)
1 user marked this as a favorite
CTRL-R {0-9a-z"%#:-=.} *c_CTRL-R* *c_<C-R>* Insert the contents of a numbered or named register. Between typing CTRL-R and the second character '"'' will be displayed to indicate that you are expected to enter the name of a register. The text is inserted as if you typed it, but mappings and abbreviations are not used. Command-line completion through 'wildchar' is not triggered though. And characters that end the command line are inserted literally (<Esc>, <CR>, <NL>, <C-C>). A <BS> or CTRL-W could still end the command line though, and remaining characters will then be interpreted in another mode, which might not be what you intended. Special registers: '"'' the unnamed register, containing the text of the last delete or yank '%' the current file name '#' the alternate file name '*' the clipboard contents (X11: primary selection) '+' the clipboard contents '/' the last search pattern ':' the last command-line '-' the last small (less than a line) delete '.' the last inserted text *c_CTRL-R_=* '=' the expression register: you are prompted to enter an expression (see |expression|) (doesn't work at the expression prompt; some things such as changing the buffer or current window are not allowed to avoid side effects) See |registers| about registers. {not in Vi} Implementation detail: When using the |expression| register and invoking setcmdpos(), this sets the position before inserting the resulting string. Use CTRL-R CTRL-R to set theSo the short answer is, if you want to paste the last line yanked or deleted, then do CTRL-R-".posted by sbutler at 12:40 PM on October 21, 2008 [2 favorites]