Much Ado About Everything

Anime, Games, Music, Life, Universe

Much Ado About Everything header image 2

Annoying VIM

March 2nd, 2006 · No Comments · Hardware & Software

While working on creating build scripts for my website – I started with some tricks off a website dealing with a substitution preprocessor I ended up getting really annoyed by my editor vim, up to the point of trashing the keyboard.  This was caused by so-called “smart” audoindenting.  There is just no way to turn it off, even using the options panel, if you can call it that.  So I after wasting good part of an hour trying to dig someting in the help, I decided I had to get to the bottom of this.

This seems to be a common problem.  I found a kind of a solution – see this: Turning off Vim Autoindent (and while you’re there, take a look at some general vim tips).

To cut the long story short – wait, there is no way to cut it short!  So you’ll have to hear it all, or not hear it at all.  Here it goes.  Iit is not enough to simply say “set noai” in order to turn off autoindent.  Unbelievable, isn’t it?  Not to mention that your firs instinct would be to try “set ai off” or “set ai 0″ – none of which are ”correct”.  And when you finally find out that contrary to any normal program you need to turn the “off” feature on, instead of turning the feature  off (oh you can also do set ai! which toggles it but still there is no logical way to turn the ai off! – correction, I believe there is also “set ai!” but I haven’t tried that, and even if it works, it’s really different from anything else).  Oh yeah, and normal # or ! comments don’t work either in config files – try ” (double quote).  Go ahead, don’t believe me and find out for yourself.  It’s really the character to signify a comment.  Anyhow,  to prevent utterly stupid autoindent messing up with your sanity, do the following:

filetype plugin indent off

This will turn autoindent off permanently for all file types.  Sadly, there is simply no logical way to turn it off temporarily (because the feature can be used to your benefit, the real problem is that you don’t get to control when it’s going to do something and when it isn’t).  How nice.

When you do want to use it, you’ll really have to comment that line in your vimrc (which is in your vim installation directory and is named _vimrc if you’re using windows – in unix it’d be in your home directory, named .vimrc).  Other than while typing, it can be told to do its stuff by, for example, selecting lines you want to indent by pressing shift and V at the same time to enter some kind of special mode that is unique to vim.  Then use arrows while holding down shift to select lines you want and then press =.  It will auto format and indent your selected lines.  Or use any standard vi way to select lines to use the = operation on.

If you’re going to use the autoindent, do yourself a favour and configure it properly.  For example, you could try inserting this into your vimrc file.

set ts=3
set sw=3
set expandtab
set smarttab
set pastetoggle=

So it will insert spaces instead of tabs – 3 of them to be exact (set it with sw) and if there are actual tabs around, they’ll be
3 characters long instead of default 8.  This will make formatting much easier.  When you want to paste in something, it will usually mess up formatting badly.  Toggle paste mode with F11 before and after pasting to prevent autoindent from messing it up.  Just don’t try to set paste mode by default and hope it will act as a temporary turn-off for autoindent (which is a feature I’d really want to have) – it will mess up a lot of other things, specifically windows event management (scrolling, mouse presses, selections, etc.) making it unuseable on windows, at least.

Tags:

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment