Vim logo vim online Vim Book Ad

 Tip #330: how to stop auto indenting

 tip karma   Rating 173/63, Viewed by 1754 

created:   September 20, 2002 13:01      complexity:   intermediate
author:   Francis      as of Vim:   6.0

Since VIM 6.0 the indent has been improved so much.
But sometimes when we are pasting formated text (source code or HTML etc)
into a buffer, VIM indents again so that lines will be padded with too
much spaces.

Setting nocindent, noautoindent, nosmartindent still cannot stop this.
All you need to do is "set paste", then paste your stuff, and then
"set nopaste" again.

Ref: indentexpr

 rate this tip  Life Changing Helpful Unfulfilling 

<<A map for swapping words | modline magic... >>

Additional Notes

[email protected], September 20, 2002 22:50

:h pt

even better
[email protected], September 22, 2002 11:21
I find that I'm annoyed by the indent policy accompanying some file types (HTML and XML in particular).  Adding the following lines to your .vimrc will turn off ALL indenting for the given file types:

autocmd BufEnter *.html setlocal indentexpr=
autocmd BufEnter *.htm setlocal indentexpr=
autocmd BufEnter *.xml setlocal indentexpr=
autocmd BufEnter *.xsd setlocal indentexpr=

Just change the above to whatever file type (extension) you want to disable indenting for.
[email protected], October 2, 2002 5:51
As a 15 year + vi user I find the latest version of vim intensely irritating.

I would like a quick way of disabling the irritatingly stupid indentation and I
am not keen on wasting any time learning how to configure vim.

To my mind vim -C should disable indentation and highlighting (which is none to
clever either) but it doesn't- any hints?
[email protected], October 2, 2002 18:38
AMEN to the person who finds the indenting exceedingly annoying.  Does anyone know how to disable this so-called feature completely so that I can type things the way I  want rather than the way someone else decided I should want?  This sort of thing is very un-Unix-like.
[email protected], October 3, 2002 7:52
I finally found out how to disable the autoindent annoyance.

Put the following line in the file .vimrc in your home directory:

     filetype off

Amazingly easy to do.  Why was it so hard to find out how to do it?
[email protected], October 9, 2002 18:34
Another alternative is to modify $VIMRUNTIME/filetype.vim, which
is a fairly straight forward process.  Just find the section for the
file type in question and start commenting or deleting sections
that offend you.

--
Michael

And now, my Two Cents:

>>Amazingly easy to do.  Why was it so hard to find out how to do it?
Because most people are not so put off by it.

>>I [want to] type things the way I want rather than the way someone
>>decided I should want?  This sort of thing is very un-Unix-like.
Most of the indenting schemes are fairly configurable on an individual
basis, and almost all conform to de-facto and/or official code standards.
That's not so un-unix like, is it?

>>I'm a 15 year + vi user I find the latest version of vim intensely irritating.
>>I am not keen on wasting any time learning how to configure vim.
Why are you using VIM then?  Use a VI clone if you are not willing to
configure VIM.  Why are you unwilling to configure your editor?

>>To my mind vim -C should disable indentation and highlighting
I agree.  Intuitively I would expect that to disable those features.
Anonymous, October 22, 2002 11:55
:set pastetoggle=<F11>
[email protected], November 6, 2002 5:39
To turn off indenting, you can use:

:set noai
:set noautoindent
Anonymous, November 14, 2002 19:42
To rando:
':set no ai' will not work when filetype (or the new indent feature) exists. that's all this tip about.
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