Monday, February 22, 2010

Vim multiple commands in configuration file

I was struggling to come up with a means of mapping a keystroke to execute multiple Vim commands, within the .vimrc settings file.
Somewhere I read that to string multiple commands on one line, they must be separated with a | (pipe). That works inside of Vim, but causes errors when placed inside the configuration file.
Then I tried using :argdo, which also worked inside of Vim but not in the configuration file.

Finally I came upon a blog post which solved my problem. It appears that in the configuration file, pipes for separating commands must be escaped with a forward slash \.

I used to have a line in my configuration file:
noremap <silent> <C-h> :noh <CR>

This means that pushing Control-h would remove search highlighting.

Now it is:
noremap <silent> <C-h> :noh\| :set number!\| :set list! <CR>

The added commands toggle visibility of line numbers and whitespace. I like having those things visible, but I often need to copy text from vim to somewhere else and the line numbers and line-terminators get copied with it if they are displayed.

As for why I added these commands to an existing mapping: I am a vim novice and unaware of many vim shortcuts, so I decided not to accidentally overwrite any shortcuts. I figured that the existing Ctrl-h command was used rarely enough so that the annoyance of having to now push it twice for clearing highlighting (to negate the toggling produced by the first push) was an acceptable price to pay. And also one less shortcut to remember.

Sunday, February 7, 2010

Salsa and rice

Here's two things you can do if you have salsa and no tortilla chips:
1. Buy some tortilla chips.
2. Cook some rice and eat it with salsa. Rice on its own is too bland to eat, but the salsa is already full of vegetables and spices and can turn a bowl of rice into a delicious meal.

No joke, try it.

P.S. You can do this with other foods like pasta, buckwheat, etc.

Saturday, February 6, 2010

Tortilla chips and corn

Here's two things you can do if you have tortilla chips and no salsa:
1. Buy some salsa
2. Open a can of corn and use it as dip. Tortilla chips are delicious with canned corn.

No joke, try it.