Monday, June 13, 2011

VIM Searching

Every once in a while I'll want to find the second occurrence of a match in command mode so I can edit from that point. An example would be a line like this:
gem 'haml',             '3.0.25'
gem 'my_own_gem',       '0.1.10', path: "/path/to/my_own_gem"
gem 'pg',               '0.10.1',     :require => false

Say my cursor is at the beginning of the second line and I want to comment out the 'path' part cuz I pushed my code and don't need to develop from my local directory anymore. I used to have to hit 'l' tons of times till I got to the comma just before the path.

I tried using this search pattern '/\,', but that matches the first comma. I'd still have to hit 'l' a bunch of times to get the next one, or I could hit enter and 'n'.

I finally figured out that if I hit '2/\,/' that will find the second match in the expression :D That works with any number, 5, 9 10, etc. VIM is great. the end.

So this is how it ends up
`in command mode`
2/\,
gem 'haml',             '3.0.25'
gem 'my_own_gem',       '0.1.10' #, path: "/path/to/my_own_gem"
gem 'pg',               '0.10.1',     :require => false

No comments:

Post a Comment