sponsor Vim development Vim logo Vim Book Ad

basic Tip #644: restoring indent for '#'

 tip karma   Rating 16/4, Viewed by 534 

created:   January 27, 2004 1:50      complexity:   basic
author:   stsi      as of Vim:   6.0

In 'smatrindent' mode '#' removes the indent if it is the first char on the line.
Very annoying for me.

From Vim's help:
        When typing '#' as the first character in a new line, the indent for
        that line is removed, the '#' is put in the first column.  The indent
        is restored for the next line.  If you don't want this, use this
        mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.

This helps, but it failes to work when placed in ~/.vimrc.
The fillowing mapping work in any case:

:inoremap # a#^Oh^Ox^OA, where ^O is entered with CTRL-V CTRL-O.

 rate this tip  Life Changing Helpful Unfulfilling 

<<Disable built-in command | Enabling Windows shortcuts (eg alt+space, F10 etc) for gvim window >>

Additional Notes

Anonymous, January 29, 2004 19:45
Too bad that map doesn't work when there are characters on the line after where you are trying to insert the #, then you wind up with an "a" instead. Instead try
:inoremap # a#<Left><BS><Right>
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo