Hey kids! Guess what time it is? It’s time for some Vim Tips!
What? Don’t make that face! Vim is awesome! Don’t give me that “B-b-but mistur Luke, we don’t use vim!” That won’t work with me again! You know damn well you should be using it. What is your lame excuse today? Is it “vim is to hard”? Suck it up you babies. Real men and women use vi and that’s that! There is only one excuse that I’m willing to accept, and that excuse is “I use Emacs”. So, how many of you whining babies use emacs? One person? Ok, you are excused – you can go sit over there. Your exercise is to write an elisp macro to do something interesting.
The rest of you, STFU and listen. No, I don’t care you use Eclipse on a daily basis. Just get the viPlugin and you will have the combined power of Vi and Eclipse at your fingertips. How awesome is that. No, don’t shrug – it’s fucking awesome, and you are gonna like it, right now! There, that’s better.
Ok, question from the back row. Yes, you – the guy with the stupid face. You use word? You know what – get the fuck out! Just get out and never come back. Actually, on the second thought wait. Sit your ass down and try the ViEmu thing. I tested it a while ago and it was pretty cool. Unfortunately it tad expensive and I could not justify purchasing it since I only use Word when I’m forced to. Still, it might work for you.
Anyways, this might be the first post of a series. I’m going to use it to drop little bits of vim lore that I want to remember for the future.
How do I use Vim input methodology for my text boxes in Firefox?
I think I mentioned it before but I use the It’s All Text! plugin. It puts a tiny little button next to all the textarea elements on the page. Pressing that button opens up the textarea contents in your editor of choice. For me that’s gVim but just about anything will do.
Hey, emacs guy – did you hear that? That one will be useful for you too. Write it down. MS Word guy, STFU! You don’t get to say anything!
There is another plugin out there called MozEx which seems to be doing something very similar. I haven’t tested it but it seems like it will also let you use vim for textareas.
I use It’s All Text! and my HTML doesn’t get highlighted
That’s because the plugin saves your buffer as a txt file. I got around this by simply forcing all text files to highlight as if they were HTML. It doesn’t really affect normal .txt files, but if you plug some HTML into one of them, it will look nice. If you want to do the same, just paste this into your .vimrc
au BufRead,BufNewFile *.txt setfiletype html
Luke, why is this post so long? How many words have you typed so far?
I don’t know, let me check…
I typed 520 words so far. I’m like halfway done so stop whining. Anyway, this is how you do it. Select some text, then press g and then Ctrl+G and you will see bunch of useful information in the status line. For example, the number of words you have typed so far. Cool, eh? It’s especially useful if you are trying to meet some word count requirement. Which, I usually don’t do very often as you might have noticed. I start typing, and then stop when the post seems like it’s done.
Heh, I wonder how many times you typed the word “vim” in this post?
Again, not sure, but let me check…
I typed it exactly 7 times. Yep, it’s another nifty trick – you can use the good old regular expressions in a non-standard way. For example the n modifier will prevent the replacement taking place in the regex above. Instead vim will simply print out the number of matches on the status line.
Finally, last tip of the day:
How do I delete everything from the cursor up to but not including a specified character sequence?
A little specific, isn’t it? But it is useful when you want to delete a big chunk of text. I mean, yes there is always the good old dt command which deletes till the first occurence of a character that follows it. There is also d) which deletes the whole sentence and d} which deletes the whole paragraph but this let’s you be very, very specific. Here is how you do it:
That is, you press d (or c if you just want to switch to insert mode), then press ‘/’ to enter search mode, enter a character sequence, and hit return. This also works with other commands so you can also do:
That’s all I have for now. I hope you enjoyed this quick batch of Vim tips. And if you didn’t I don’t care. The emacs guy over there seems happy because he found out It’s All Text! plugin and the MS Word guy is crying cause I called him names. Eh…
There might be more of these. :)