Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

I am the chief technical something or other at Reverb.com - The Marketplace for Musicians. We're hiring web designers!

Recent Tweets

Selected Reading

Archives

Contact

Reach me at yan at pritzker.ws

Vim – Navigating files in vertical splits

Posted 12 March 2012 @ 11am in vim



Submit to HN

The two most useful native vim mappings for navigation are arguably

gf

(go to file, use it over any reference to a file, such as a Rails partial), and

Ctrl-]

(go to tag, use it over any class or function name). But one problem in vim is that by doing these commands, you lose your previous place. Sure it’s easy to go back to with Ctrl-O or similar, but I find it much more useful to open the new location in a split, as you are usually exploring them while retaining the current context. Here are two mappings that do that for you:

If you like these, you might want to check out my Yet Another Dotfile Repo project, which includes these and more!

14 Comments

Posted by
Tim Scheer
12 March 2012 @ 1pm

At least for go to tag (CTRL-]) I believe you can use the Jump to older entry in the tag stack (CTRL-T) command to traverse back up the stack


Posted by
paul
12 March 2012 @ 1pm

There are builtin bindings for those things, if you don’t mind a horizontal split instead of vertical. The nice thing about builtins is that they work anywhere.

CTRL-W ] – Splits current window, jumps to tag under cursor
CTRL-W f – Splits current window, edits file name under cursor

There’s a couple more variations that you can see at :help window-tag


Posted by
Jarrod
12 March 2012 @ 1pm

great mappings! throw them up on http://vimbits.com/ too… that crowd will appreciate them


Posted by
yan
12 March 2012 @ 1pm

@Jarrod cool site! didn’t know about vimbits – thanks


[...] original post here: Vim – Navigating files in vertical splits This entry was posted in Tyson Zinn and tagged tyson l zinn, tysonzinn, your-app, zinn tyson by [...]


Posted by
bryan kennedy
12 March 2012 @ 3pm

I’m a bit of a noob when it comes to ctags, so it took me a while to figure out that you need to generate the tags file for your project before this will work. With:

ctags -R *

If I’ve got that wrong, please correct me.


Posted by
yan
12 March 2012 @ 4pm

If you’re a rails dev, use rails.vim and :Rtags command, which does this:

:!ctags -f /path/to/tmp/tags -R –langmap=”ruby:+.rake.builder.rjs” –languages=-javascript /path/to/your/project


Posted by
yan
12 March 2012 @ 4pm

@paul – Yes there are built in bindings, but they are no good. Having to hit two keys in a row, one of them being a chord? What is this emacs? :) Also, they split horizontally which is not as useful on modern wide screens. I love vim but it has some bad ux in places, and having more useable keybindings is very valuable to me. Also if you keep your dotfiles portable on github, your setup can work anywhere.


Posted by
Kartik Agaram
12 March 2012 @ 5pm

Christian Brabandt on the vim mailing list was kind enough to make me a patch to make all split commands open vertically by default:

http://groups.google.com/d/topic/vim_dev/CaMmJW3y7K4/discussion


Posted by
yan
12 March 2012 @ 10pm

@Kartik oh that’s really cool, I’ll take a look thanks


Posted by
Andy
13 March 2012 @ 2pm

I tried your ,F mapping but it gave me an error in vim:
Invalid expression: expand(“”):vsp:wincmd w:exec(“tag “. word)


Posted by
yan
13 March 2012 @ 2pm

Doh stupid blog formatting software! Fixing…


Posted by
yan
13 March 2012 @ 2pm

All fixed up. See also https://gist.github.com/2031016


Posted by
Learning Web Design
17 April 2012 @ 5pm

[...] Firefox, there's FireBug -=VIM=- DotShare.it (Great site in general if you use Linux/*BSD etc.) Vim – Navigating files in vertical splits Vim hacks – Linux Tutorials, Guides and Tips – CODECALL VIM an a PHP IDE – Thomas Koch -=General [...]


Leave a Comment

To post code, use <code></code> tag around your code