News for hackers. Stuff that matters.
Re:Advanced Vim Registers by gws on Wednesday January 09, 2013 @03:25AM (#5030707)
A less powerful but much simpler alternative to using the registers is the Yankring plugin (https://github.com/vim-scripts/YankRing.vim)

With that anything you have ever yanked or deleted is in the ring and when you paste something you can easily rotate through the items in the ring. Basically you type 'p' to paste and if that's not what you wanted you keep pressing ctrl-p until you get what you want.

Re:Advanced Vim Registers by petepete on Wednesday January 09, 2013 @07:00AM (#5031137)
I've just been through the YankRing tutorial and it's fantastic; I don't know how I haven't come across this before. Thanks!
Re:Advanced Vim Registers by crazydiamond on Wednesday January 09, 2013 @11:43PM (#5035469)
I used it (YankRing) for some time, but it was never consistent. The plus point is that it works across terminal, otoh often "p" did not work, so i would have to do "YRShow" and select.

Often this is used, but everything you delete gets copied to your clipboard.

       set clipboard=unnamed
So i prefer to map C-c and C-x (or whatever) to copy/cut to clipboard.

    " regardless of clipboard option, c-c copies selection to clip
    vmap <C-c> "+y
    " cut into clipboard
    vmap <C-x> "+d
    " copy to clipboard, http://news.ycombinator.com/item?id=4767227 , use 3 \y to copy 3 lines
    map <leader>y "+yy
    " paste from clipboard
    map <leader>p "+p
    " delete to black hole register, not going to clipboard etc
    nnoremap <leader>d "_d
    vnoremap <leader>d "_d
I've also mapped a key to write selected lines to a file, and another to read from it.

    map <silent> <leader>ww  :w! ~/tmp/vimxfer<CR>
    map <silent> <leader>wa  :w!>> ~/tmp/vimxfer<CR>
    nmap <silent> <leader>rr  :r ~/tmp/vimxfer<CR>
Pls refer to post below on "reattach to user namespace" for OSX ML users.
Re:Advanced Vim Registers by bilalq on Wednesday January 09, 2013 @01:38AM (#5030513)
This was an incredibly helpful article. Tom Ryder's written a lot of other blog posts that were really insightful and enlightening as well. I even learned how to use ed from him.
Re:Advanced Vim Registers by koralatov on Wednesday January 09, 2013 @03:18AM (#5030698)
His blog has taught me more about using vim than any other single resource, and I recommend it unreservedly to anyone thinking of starting out with vim.
Re:Advanced Vim Registers by ZeroGravitas on Wednesday January 09, 2013 @05:19AM (#5030928)
Does anyone know of a service where I could point to "timeless" blog content like this and it would give me a feed that it picks old content on a random, perhaps weekly basis? Then I can integrate it with more timely sources.

I feel like this must exist but I've no idea what to Google for.

Re:Advanced Vim Registers by crazydiamond on Wednesday January 09, 2013 @11:56PM (#5035520)
Try http://www.vimtips-blog.com/

Also vimcasts.org, and check the zzapper page linked in the tips blog.

Re:Advanced Vim Registers by srik on Tuesday January 08, 2013 @10:56PM (#5030045)
Always glad to see vim usage articles pop up now and then. Here's a similar HN thread from a while ago - http://news.ycombinator.com/item?id=2870024
Re:Advanced Vim Registers by LauriL on Wednesday January 09, 2013 @01:18AM (#5030468)
A useful article for at least intermediate VIM users.

Regarding the system clipboard register: in OS X 10.8 the `"+` register no longer works. Has anyone found a way to get it working again?

Re:Advanced Vim Registers by bilalq on Wednesday January 09, 2013 @01:36AM (#5030505)
It works fine for me. Seems like whatever install of Vim you have doesn't support the clipboard. Run "vim --version | grep clipboard" and see if you get a + or - for the clipboard.

If you want a quick fix for getting it working again, make sure /usr/local/bin is early on in your PATH and run "brew install macvim --override-system-vim"

Re:Advanced Vim Registers by RegEx on Wednesday January 09, 2013 @05:26AM (#5030944)
I visually highlight and call pbcopy on OS X and xclip on ubuntu. It has the annoying side effect of deleting the text, but a simple u fixes that.

So, highlight in visual mode, go into command mode, and !pbcopy

Re:Advanced Vim Registers by Lio on Wednesday January 09, 2013 @09:01AM (#5031469)
If you use Vim within tmux (on Mac OSX) the clipboard can become 'detached'. To get it working again I use Chris Johnsen's excellent little command.

https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard

You can install using 'brew install reattach-to-user-namespace'

You need to config tmux:- set-option -g default-command "reattach-to-user-namespace -l zsh"

then set vim to use to use the unnamed clipboard by default.

Re:Advanced Vim Registers by tyler-dodge on Wednesday January 09, 2013 @02:08PM (#5032840)
My version didn't have it builtin so I use fake clip https://github.com/kana/vim-fakeclip
Re:Advanced Vim Registers by reyan on Wednesday January 09, 2013 @05:59AM (#5031000)
If you want to edit your macros, (e.g., the default register q) do "qp, edit, visual select and do "qy.
Re:Advanced Vim Registers by dschobel on Wednesday January 09, 2013 @01:37AM (#5030507)
wow, capital register appending is super useful. lots of good tips in this one.

thanks for posting this!

Re:Advanced Vim Registers by terhechte on Wednesday January 09, 2013 @03:09AM (#5030683)
I find the difficulty is remembering this when I need it. I've read about capital registers several times, but when I am editing, and I need to copy several distinct lines, I do a "ayy "byy "cyy and then "ap "bp "cp instead of a "ayy "Ayy "Ayy -> "ap because I never remember to use capital registers. I'd love a VIM plugin that tells me that there is an easier way to what I just did by pattern matching my input.
Re:Advanced Vim Registers by dschobel on Wednesday January 09, 2013 @03:50AM (#5030758)
I wonder what the complexity of a plugin would be that watches you use vim and tells if you're doing an anti-pattern?

My only gripe with vim is that the discoverability of features is god awful because :help is so overwhelming.

Re:Advanced Vim Registers by terhechte on Wednesday January 09, 2013 @03:31PM (#5033314)
Yeah me too. I guess it would need to match all the wrong ways against a right way. It is probably easy for something like "jjjjj", but already someone doing BBBBi instead of I would be difficult to match: because one would also need to see where he ended up with BBBB: beginning of line or somewhere in the middle
Re:Advanced Vim Registers by mercurial on Wednesday January 09, 2013 @02:42AM (#5030633)
I found the numbered registers even better, since "overwrite text with pasted content, multiple times" is a relatively common operation.
Re:Advanced Vim Registers by lavkesh on Wednesday January 09, 2013 @07:17AM (#5031173)
I am going to buy a t-shirt which says "I use Vim"
Re:Advanced Vim Registers by gaving on Wednesday January 09, 2013 @07:47AM (#5031233)
why