vim tips
vim tips
So, I’ve been using vim for my ruby/rails dev of late and I thought I’d share a few things I picked up along the way. Another tool that I’ve begun relying on heavily is GNU screen. It didn’t make sense to put that in a separate post so I’m going to include some of my screen setup here as well. This is primarily aimed at people who’ve already begun with vim and are looking for examples of development setups.
The Tools:
vim
One of the core features of vim that you’ll find amazingly useful is the split screen. Incredibly useful when dealing with multiple files that you constantly have to refer to(while writing tests for instance). For more about some handy core features have a look at my .vimrc. Of course the real power of vim is in its amazing repository of plugins(advantage of being a nearly 20 year old project). Some of the ones that I find indispensible are:
- rails.vim: The most basic plugin that you will need for rails development.
- NERD_tree: File browser.
- command-t: File finder
- fugitive: git integration done right
- specky: makes specs your friend again.
- irb_slime.vim: For integrating irb and vim through screen
For my complete .vim folder clone git://github.com/rjsvaljean/vim_config.git
screen
GNU screen is one of those tools, that, once you’re exposed to will become essential to any sort of terminal intensive work that you do. I like to think of it as a window manager for your terminal. It basically hosts a bunch of terminals in different windows(tabs) and makes sure that you never have to Alt-Tab again. But of course its much more than that the killer feature is that ability to detach screen sessions. I do most of my development on a laptop which I almost never shutdown. So I’m working in my screen for project A, when I need to switch, I don’t need to worry about shutting down the various programs safely. I just need to detach the session and re-attach when I need it. This way I get back to work with no interuptions. It nicely allows you to keep all the terminal based programs that you run with a particular project in one place.
Bringing it all together
As I’d put in the list of plugins this ties vim, irb and screen together nicely. Next master fugitive(which is alarmingly simple to use) and you’ve got SCM integration in your editor. Its starting to look more like an IDE, isn’t it? Now sugar coat the whole deal by opening vim up in your project directory within a screen session. But of course development seldom involves just your editor so go ahead and open a bung of windows for your REPL, your test running window, IRC client etc. etc. But you don’t want ot keep repeating this every time you start a screen session of a different project. What I do is create a project specific .screenrc which in my project root directory with a bunch of screen -t declarations to open the windows that I need for that project and add an alias to my ~/.bashrc. Something like:
alias work="screen -c .screenrc"
This I find works pretty well. Additionally the irb_slime plugin I’d mentioned eariler requires you to specify the screen session name and the name of the window where your REPL is running. You only have to do this the first time but its still pretty annoying. To automate things further do the following in your .screerc
screen -t vim 0 vim -c 'let g:screen_sessionname=session'\
-c 'let g:screen_windowname=repl'
That makes sure that once you execute work in your project directory you’re all ready to start hacking.
Hope this helps!