Nicolás Brailovsky


A modern blog

Archive for the ‘Vim’ Category

Thanks for flying vim

author Posted by: nico on date Jul 15th, 2010 | filed Filed under: Vim Tips

Have you ever used Vim through ssh and saw your xterm title changes to “Thanks for flying vim”? It happens a lot to me, and I usualy notice about an hour later. I’m not sure what’s the use of this, I guess it’s related to Vim airlines (no, really, check vim-avia.com), but it can be turned off:

When using vim in an xterm it renames the title of that window to “Thanks for flying vim” on exit.

Q: How to turn off the message “Thanks for flying vim”?
A: :set notitle

http://www.vmunix.com/vim/answ.html

Vim tips: make things work again

author Posted by: nico on date Jun 29th, 2010 | filed Filed under: Vim Tips
Are you using :make within vim? If you are, then you probably noticed that getting lots of compiler errors is not uncommon, and that vim has a tendency of jumping to the first error found… but what happens if you want to see subsequent errors too, because you’re a really crappy programmer and need to find the 10 or 20 errors you just introduced with your single line edit?

Luckily Vim is always the anwser, just use cnext and cprev until you reach the error you are looking for.

Nooooooooooo

author Posted by: nico on date Jun 23rd, 2010 | filed Filed under: Grumpy, Vim

(gvim:13664): Gdk-CRITICAL **: gdk_window_get_user_data: assertion `GDK_IS_WINDOW (window)’ failed
Vim: capté una señal de muerte SEGV
Vim: finalizado.

Vim tips: make things work

author Posted by: nico on date Jun 11th, 2010 | filed Filed under: Vim Tips
So, you are an uber console geek, using only vim and the command line to compile all your projects, execute the tests, blah blah blah… if only you could squeeze that microsecond lost whenever you switch from vim to compile you’d be 1e-4 seconds more productive… oh, wait, you can!

Whenever you think you’re project is good enough to compile just hit :make to be proven wrong. Type :make test to run your tests (because you are using TDD, aren’t you?) and watch all those red flags fly by.Also, add the following mapping to your ~/.vimrc for an extra happy coding session:

  1. map  :make
  2. map  :make test

Vim tip: reuse gVim instance

author Posted by: nico on date May 14th, 2010 | filed Filed under: Vim Tips
/* Usual rant about Vim being great */, /* usual rant about everything else being plain awful */. /* Comment stating that if you don’t use Vim then you suck */. And now, one more reason to use gVim: instance reuse! Yes, you can save many many KB or RAM by using –remote-tab-silent when openning a document in gVim. (clearly this would have been “many many GB of RAM” if we were talking about emacs).

If you don’t like adding –remote-tab-silent each and every time you use gVim to open a file, then you are a lazy bum and I congratulate you. Define an alias in your bashrc to save precious typing microseconds too.

/Sarcasm mode off

Vim tip: Word count

author Posted by: nico on date Apr 20th, 2010 | filed Filed under: Vim Tips
Trying to count words is a common task. Whenever you’re writting a report for class, that is. There are some legitimate reasons but they don’t matter now: it’s a great chance to show off how great Vim is.

First method: Type ggVgY”*p to copy the whole text. Then paste it into word and use word count.
Second method: Type %!wc -w, which executes wc on each line.
Third method: Type g^g (g, CTRL+g) and watch the bottom of your screen.

As ussual, Vim rocks.

Vim tip: Remapping

author Posted by: nico on date Mar 31st, 2010 | filed Filed under: Vim Tips
We all know is the funnier editor in the world. You can even use it to rot13 all your code and have lots of laughs when committing. But what if you want to automagicaly change a random word into another word? Well then inoremap comes handy, just adding this to your ~/.vimrc:
  1. inoremap hola mundo

and suddenly whenever typing “hola” you’ll see “mundo” instead. LOL. I guess it’s useful to fix typos, or to autocomplete code. Or to change “Hello” into “Fuck you” in you friend’s vimrc, whichever you think it’s appropriate..

Vim Tip: Open file in new tab

author Posted by: nico on date Oct 21st, 2009 | filed Filed under: Programming, Vim Tips
How many times have you been on a project which #includes another file and wanted to see what that file was? Well you can navigate the source code tree in a gui if you use eclipse. You can go to File > Open and, again, fight with a nice gui in Notepad. Or you can open up that file with four keystrokes in a real editor, THE real editor. Just use “C-W g f” with the cursor over the filename and it’ll open in a new tab, ready for you to hack away more code. success_vim

Vim Tip: Folding FTW

author Posted by: nico on date Oct 6th, 2009 | filed Filed under: Vim Tips
I always say methods should have two levels of indentation at most, but even if your code is perfect like mine you may still have to dwell with other people’s code (which, obviously, is ugly code), people how may have lots of fun shaping the program like a pyramid. 0040-teddy-bear-sepuku

Not all is lost, you don’t have to commit sepuku (at least not for this one). Just use Vim’s indent method like this:


:set foldmethod=indent

That should give you a better view of the code flow. As always, use ‘%’ to navigate all those pesky { and }.

Vim Tip: Rot 13

author Posted by: nico on date Sep 17th, 2009 | filed Filed under: Vim Tips
vim_editor Are you still puzzled by last week’s C++ question, yet you are too lazy to actually search for a Rot13 decoder OR use gcc to check if it works? Well, Vim can do the trick, just use g? to convert text to Rot13

You may combine it with block selection or you can just convert the whole damn thing using “ggg?G”. gg goes to the beggining, g? converts to rot13, G goes to the end.

This is all very nice but I’m still trying to figure out a way to convert back from rot13 to normal text, can anyone provide a clue?