History
Article Edit this page Discussion

Restoring indent after typing hash

From Vim Tips Wiki

(Redirected from VimTip644)
Jump to: navigation, search

Tip 644 Previous Next Created: January 27, 2004 Complexity: basic Author: stsi Version: 6.0


In 'smartindent' mode, '#' removes the indent if it is the first char on the line. That can be very annoying.

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 fails to work when placed in vimrc.

The following mapping works in any case:

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

[edit] Comments

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>

Just do as the help on smartindent states and add the following line to your .vimrc file:

:inoremap # X<C-H>#

Nice, but does not help for indenting with '>>' or '<<'. The lines are still ignored.


You can avoid all this nastiness by just not enabling 'smartindent'. It's not very smart and really only makes sense for C-like languages.

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Restoring indent after typing hash"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation