Edit Page
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 158: | Line 158: | ||
</pre> |
</pre> |
||
− | ==Paste |
+ | ==Paste contents of search register (/) in insert/cmdline mode== |
+ | |||
− | When using <code>^r/</code> in INSERT mode what one most of the time wants is to paste the |
+ | When using <code>^r/</code> in INSERT mode what one most of the time wants is to paste the litteral text not the regex used to search the text. Example: after using * on a word, <code>^r/</code> will paste the word with <code>\<</code> prepended and <code>\></code> appended, not what we want. Similarly after a visual search we don't want the <code>\V</code> prepended. The following map takes care of these issues: |
<source lang="vim"> |
<source lang="vim"> |
||
function! Del_word_delims() |
function! Del_word_delims() |
||
Line 177: | Line 178: | ||
cnoremap <C-R>/ <C-R>=Del_word_delims()<CR> |
cnoremap <C-R>/ <C-R>=Del_word_delims()<CR> |
||
</source> |
</source> |
||
− | |||
− | For more complicated patterns, it's better to act on the text matched with the last search, using the {{help|prefix=no|gn}} object. |
||
− | |||
− | So, you could also accomplish insertion of a search match using <code>maygn`ap</code> in normal mode. I.e. <code>ma</code> to drop a mark to return to later, <code>y</code> to yank the <code>gn</code> object, then <code>`a</code> to jump back where you were (because the yank will leave you on the text copied), finally <code>p</code> to paste. |
||
− | |||
− | When starting from insert mode, you don't even need a mark: you can use the <code>gi</code> command to start again from where you left off. For example: |
||
− | |||
− | <pre> |
||
− | :inoremap <F3> <Esc>ygngi<C-R>0 |
||
− | </pre> |
||
− | |||
− | Here, <code>ygn</code> is as before, but <code>gi</code> is used to go back to insert mode in the same place you left off, then <code><C-R>0</code> inserts the copied text. |
||
==See also== |
==See also== |