Vim, you either hate it or you love it, and if you have been following me at all over the past couple of years you will know that I am for sure a lover of Vim. One of the most powerful parts of Vim, and what hands-down makes it my favorite editor is the extensibility and configuration options that it offers right out of the box.
The beauty of all of this is that you can use or not use any of these. You can take them as an idea and build your own solution, or you can quite simply say piss on it and use Sublime. Personally, though, I find it hard to believe that anyone that spends any considerable amount of time in a text editor, for coding that is, wouldn’t fall in love with Vim after just a few days.
For those of you that want to see my entire .vimrc you can view it here on Github. Feel free to copy it, hack it, or whatever you want to it. It is probably a little bit more than somebody new to Vim would want to start with, though.
So without further ado, I present to you my must have Vim hacks that make my everyday coding more enjoyable and move faster and smoother.
Edit my .vimrc file.
This one lets me just swing right into my .vimrc file with a simple keystroke, “,ev”. If you didn’t guess it already, “ev” stands for edit vim. I use this a lot because I am constantly trying to improve my workflow.
Relative line numbers
You may have heard of relative line numbers, but if not, what they do is instead of showing you what line in the file a given line is at, it shows you how far from the current line a given line is at. What i did here is set both of the options to be true which gives us what Vim calls hybrid line numbers. This shows the current line’s line number and the relative number for the rest. The reason that I like these is because now I can just use a number and a movement key to jump anywhere on the screen.
Modify the cursor placement.
Because I am using relative line numbers, I like to keep the current line in the vertical center of the editor. Setting “so” to 999 will do just that. And just in case I need to move away from that centered setting I set a mapping to disable it and re-enable it in the next two lines.
Automatically source the .vimrc
This little tidbit is awesome. Every time you edit your .vimrc, it will re-source it so that the changes are immediately reflected in Vim without having to re-start. Like I said earlier I change my .vimrc a lot, so this one comes in handy pretty often and I don’t even think about it anymore.
Show line breaks more clearly.
Not only do I edit a lot of HTML files with long strings on a single line, but I also do most of my work on my 13″ Macbook Pro, so I don’t have a lot of screen real estate which leaves me with a lot of wrapping lines. This little addition just helps to make those a little bit more readable.
Make j and k work properly.
While we are talking about wrapping lines, I want to add this little tidbit that will make j and k work how you might expect. Typically, it will go up to the next line, however, with this addition it will go up one row in the editor, even if that row is the same line that was wrapped.
Jump to the end of the line.
This one seems like it might be kind of pointless, but it is really one of my favorites. Because I have a plugin that will automatically close things like quotes and parens I am often times done with a line of code but have several characters to the right of my cursor. Well that’s a problem because usually I have to add a semicolon to the end of the line. Instead of “<Esc>$;o“, I just whack “ii;o“, never leave the home row, and start writing the next line of code.
Leave insert mode.
Another one that seems like it might be kind of pointless but it’s another one that is a game changer in my opinion. Instead of leaving the home row, and getting up to the escape key I can just quickly hit “jk” and be in normal mode.
Remap ; to :
This one is pretty simple, but I like it a lot. I remap the ; to : when in normal mode so that I don’t have to hit shift when I write the file. Writing that just made me realize really how lazy Vim has made me.
Overall these are some pretty simple things that you can put in your .vimrc to make your life just a little bit easier. Let me know what kind of little Vim tricks that you have or you have in your .vimrc.