A few people have asked me a few questions about VIM usage after reading my previous post about VIM. Here they are with my answers.

Show whitespaces
There seems to be no particular option like :set list for showing white spaces. One can use a mapping like below to see the white spaces temporarily

nmap <F2> :%s/ /./g^M        # Note that you have to type CTRL-V,CTRL-M to get the ^M

Pressing F2 will show you the spaces as dots. Just do undo(u) to get back to the original text.

Show trailing white spaces at the end of line
nmap <F2> :%s/ +$/ยท/g^M
Switching off the smart indentation
This is one of the few features I hate. VIM tries to move the text to follow an indentation pattern. For example, in an html file, if you type

        <td>
              text
</td>

VIM converts it to

        <td>
              text
        </td>

Sometimes, this is useful, but other times it’s extremely annoying, especially when you have multiple nested elements and you don’t want to have indentation. This is almost like automatic capitalization in MS word. Anyway, this can be disabled with

:set nosmartindent
:set indentexpr=                # Note that there's nothing after the = sign
Showing line and column number.
:set ruler
Formatting Paragraphs
gqap

This is a pretty cool thing, that I use quite often. Often, you write a paragraph and insert a few things and it becomes ugly. Use gqap to nicely format it depending on the textwidth. This can also be used to change the textwidth of a paragraph. Say you wanted to change the textwidth to 60 characters, do this

:set textwidth=60
gqap

I wish VIM guys spent sometime explaining cool features of VIM instead of adding new features. A lot of simple/cool things are lost in the sheer amount of options. I wonder how many people use advanced features like folding.

Share