How to turn off auto-indentation?

277 views
Skip to first unread message

Yves S. Garret

unread,
Jul 31, 2012, 4:33:47 PM7/31/12
to v...@vim.org
Hello,

   I've started to use gVim in place of Notepad++ on my Windows 7 machine (something I prefer since I use vim on my Ubuntu box).  However, I'm running into 2 particular issues that are quite annoying.

1 - When I try to modify JavaScript and I write the function, the editor automatically inserts a tab (8 spaces) before the existing spaces and somehow after I delete the tab, it also seems to have deleted 2 spaces on top of that!  I like code high-lighting, makes code readable, but generally I hate any sort of auto-indentation (a preference -- or lack of a preference? -- that spans all existing browsers and now just in VI).  How do I turn of _all_ auto-indentation and just have me worry about that stuff?

2 - Say I'm modifying multiple files.  The "buffers" feature makes it much easier to have multiple files in a single window and then switch between them.  This keeps my desktop sane by having just one window to look at.  However, when I'm finished with a particular file (or it was modified by one of my apps and I don't care about it any more) I would like to do :close and just be done with it.  But... that buffer does not "close".  What am I doing wrong and what is the purpose of :close?

Gary Johnson

unread,
Jul 31, 2012, 6:00:52 PM7/31/12
to vim...@googlegroups.com
On 2012-07-31, Yves S. Garret wrote:
> Hello,
>
> I've started to use gVim in place of Notepad++ on my Windows 7 machine
> (something I prefer since I use vim on my Ubuntu box). However, I'm running
> into 2 particular issues that are quite annoying.
>
> 1 - When I try to modify JavaScript and I write the function, the editor
> automatically inserts a tab (8 spaces) before the existing spaces and somehow
> after I delete the tab, it also seems to have deleted 2 spaces on top of that!
> I like code high-lighting, makes code readable, but generally I hate any sort
> of auto-indentation (a preference -- or lack of a preference? -- that spans all
> existing browsers and now just in VI). How do I turn of _all_ auto-indentation
> and just have me worry about that stuff?

The Vim program does not have indentation enabled by default.
Indentation is enabled by a configuration file or from the command
line. If you don't want it enabled, just find the place where it is
enabled and delete or modify that line.

In your case, you're probably sourcing $VIMRUNTIME/vimrc_example.vim
which contains this line:

filetype plugin indent on

It's not a good idea to modify any file under $VIMRUNTIME, so you
can instead just turn off filetype-dependent indentation by putting
this in your _vimrc:

filetype indent off

See

:help filetype-indent-off


> 2 - Say I'm modifying multiple files. The "buffers" feature makes it much
> easier to have multiple files in a single window and then switch between them.
> This keeps my desktop sane by having just one window to look at. However, when
> I'm finished with a particular file (or it was modified by one of my apps and I
> don't care about it any more) I would like to do :close and just be done with
> it. But... that buffer does not "close". What am I doing wrong and what is
> the purpose of :close?

Note that from ":help :close", :close does not close a buffer, it
closes a window. For an explanation of the difference, see

:help windows-intro

Vim cannot display no window and a window cannot contain no
buffer. When you have only one window, :close will do nothing.

If you want to replace the buffer in your last window with an empty
buffer, just use

:enew

HTH,
Gary

sc

unread,
Jul 31, 2012, 8:48:52 PM7/31/12
to vim...@googlegroups.com
On Tue, Jul 31, 2012 at 04:33:47PM -0400, Yves S. Garret wrote:
> Hello,

> 2 - Say I'm modifying multiple files. The "buffers" feature makes it much
> easier to have multiple files in a single window and then switch between
> them. This keeps my desktop sane by having just one window to look at.
> However, when I'm finished with a particular file (or it was modified by
> one of my apps and I don't care about it any more) I would like to do
> :close and just be done with it. But... that buffer does not "close".
> What am I doing wrong and what is the purpose of :close?

you are looking for :bd which is short for :bdelete which deletes
buffers from the buffer list

John Beckett

unread,
Jul 31, 2012, 9:55:17 PM7/31/12
to vim...@googlegroups.com
Yves S. Garret wrote:
> How do I turn of _all_ auto-indentation and just
> have me worry about that stuff?

See:
http://vim.wikia.com/wiki/How_to_stop_auto_indenting

> What am I doing wrong and what is the purpose of :close?

The :close command closes the current window, whereas you want
to "close" (that is, delete) the current buffer. There is a
diagram showing what's what here:
http://vim.wikia.com/wiki/Buffers

As well as entering :bd to delete the current buffer (if it has
been saved), you can enter :ls to list buffers then issue a
command like this to delete several of them (the numbers are
read from the :ls list):
:bd 5 13 2

John

Yves S. Garret

unread,
Aug 1, 2012, 1:38:29 PM8/1/12
to vim...@googlegroups.com
Thanks everyone for your help. I think I got most of my issues resolved. I'll hit up the wiki next time I have a problem (I didn't know it existed).
Reply all
Reply to author
Forward
0 new messages