Newspeak

August 6, 2008

Week 3: Vim tricks - Indenting Code

Filed under: vim — Stephen Paulger @ 9:28 am

For a long time now I have known how to indent using Vim’s ‘>’ command to indent a block of text. I have learnt a few new tricks that might speed me up a bit. (more…)

July 29, 2008

Week 2: Vim tricks - Automatic code completion

Filed under: tech, vim — Stephen Paulger @ 4:20 pm

You may have used an IDE before that allows you to automatically complete parts of your code. In Microsoft’s Visual Studio this is called “intellisense”. It’s very handy for speeding up development and for exploring objects that you can’t quite remember the attributes of. This week I found out how to add it to Vim. (more…)

July 21, 2008

New Vim tricks

Filed under: vim — Stephen Paulger @ 5:05 pm

I’ve been using vim as my main text editor for over 5 years now and because I’m now dependent on it and using it every day at work I’ve decided to challenge myself to learn a new trick every week. Last week’s trick was sorting lines.

Sorting Lines

I actually learnt two new tricks to be able to do this. The first is selecting lines using visual mode.

By placing the cursor on the first line you wish to select then pressing Shift+V and moving the cursor the last line to select you select the range of lines between the two and you can do any of your normal ex commands on just the selected text.

To sort the selected lines type :sort, this runs the sort command and replaces the selection with the result. You notice if you try to sort lines with numbers they will be sorted alphanumerically, ie. 700 would come before 8, if you want to sort numerically use :sort n. You can also remove duplicates from a list by using :sort u, to remove duplicates and sort numerically use :sort un.

Powered by WordPress