TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Advanced tricks with vim registers

114 pointsby nyellinalmost 14 years ago

7 comments

mcantoralmost 14 years ago
- <i>How do delete without clobbering the "clipboard" register:</i><p>Delete to the "black hole register", "_". For example:<p><pre><code> "_dd </code></pre> - <i>How to enter the solution to a quick math equation while in insert mode:</i><p>Use the "expression register", "=". You can even use variables. For example:<p><pre><code> ^r=5325*30&#60;ENTER&#62; </code></pre> - <i>How to edit a macro once you've recorded it:</i><p>Paste, edit, and re-yank its register. For example, hitting "qq" will record to register "q". If you want to edit it, you can do <i>"qp</i>, make your changes, then visually select it and do <i>"qy</i>.<p>- <i>How to access prior contents in the clipboard:</i><p>Use registers 0 - 9. For example, <i>"0p</i> will paste whatever was in the clipboard register <i>before</i> you yanked whatever's in there now.<p>BONUS ROUND:<p>- <i>In command mode, how to insert the word currently under the cursor:</i><p><pre><code> ^r^w </code></pre> (That's Ctrl-r, Ctrl-w)<p>- <i>Insert a register's</i> literal <i>contents:</i> For example, if you have a <i>^m</i> (newline) character in the <i>a</i> register, but you want to input the <i>^m</i> character instead of an actual newline while in insert mode:<p><pre><code> ^r^ra </code></pre> - <i>Insert the full path of the filename currently under the cursor:</i><p><pre><code> ^r^f </code></pre> (This only works if it's in your 'path' variable, like with <i>gf</i>.)
Pewpewarrowsalmost 14 years ago
The two "advanced" topics that I've never bothered to learn, despite my years of using vim, are registers and buffers. Thanks to the answers on SO and the comments here, I think I have a pretty good grasp of registers (the being able to paste yanked text after a delete would have saved me so much god-damn time).<p>So all that leaves is buffers. I've traditionally been using tabs and splits for all my editing multitasking, with NERDTree and Command-T to open new files quickly. Is there anything to be gained from me learning/using buffers at this point? I don't know what benefits they offer, and I've never had any problems with my current tab &#38; split setup.<p>Any buffer evangelists out there that care to chime in?
评论 #2870670 未加载
评论 #2870570 未加载
评论 #2871785 未加载
评论 #2871011 未加载
评论 #2870682 未加载
Symmetryalmost 14 years ago
A great trick I didn't know about was the 0 register. I've lost tracked of the number of times I've copied some text, and then deleted something by mistake not realizing I'd overwritten the default register. I could still have pasted what I wanted with "0p, though.
评论 #2870239 未加载
评论 #2873067 未加载
nyellinalmost 14 years ago
My favorite trick is using capital-letters to append to registers:<p>"kyy - copy a line to register k<p>"Kyy - append a line to register k
herTTTzalmost 14 years ago
I use YankRing (<a href="http://www.vim.org/scripts/script.php?script_id=1234" rel="nofollow">http://www.vim.org/scripts/script.php?script_id=1234</a>) which takes care of the problem of remembering yank history. Just map :YRShow to a key and you are good to go.
评论 #2870335 未加载
sixtofouralmost 14 years ago
Vim is the tech equivalent of "line movies." A line movie is one where guys (it's usually guys) throw lines back and forth at each other, usually in the current context. Princes Bride and Real Men are line movies. I love line movies.<p>Vim lets geeks throw "vim tricks" back and forth at each other. I love Vim, and I love vim tricks.<p>Good SO thread, and good HN thread. I never tire of Vim threads.
jjcmalmost 14 years ago
If you guys are interesting in learning vim more, checkout vimcasts.org. Drew Neil does some really nice walkthroughs that are extremely helpful for beginner and intermediate vim users.