88 votes
Accepted

What is the difference between `filetype plugin indent on` and `filetype indent on`?

filetype plugin indent on is like a combination of these commands: filetype on filetype plugin on filetype indent on It turns on "detection", "plugin" and "indent" at once. You can check for ...
Flimm's user avatar
  • 2,182
73 votes
Accepted

How can I change the indent size?

Several settings controls the behavior: First set expandtab allows to replace the tabs by white spaces characters :h 'expandtab'. Then set shiftwidth=4 makes the tabulations be 4 white spaces :h '...
statox's user avatar
  • 49.3k
55 votes

How to add indentation guides/lines?

Another option I use, which isn't exactly what you asked for, but accomplishes the same purpose of making it easier to see what is in the same column, is to set the following in your vimrc: set ...
Karl Bielefeldt's user avatar
48 votes
Accepted

What is the difference between autoindent and smartindent in vimrc?

autoindent essentially tells vim to apply the indentation of the current line to the next (created by pressing enter in insert mode or with O or o in normal mode. smartindent reacts to the syntax/...
guntbert's user avatar
  • 1,245
26 votes

How can I change the indent size?

In fact, aside from other answers, it is also possible to use autoindent (to automatically indent newlines) and smartindent (which works with C-like braces languages less strictly than cindent). Then ...
J. Chomel's user avatar
  • 1,096
26 votes
Accepted

How do you indent > < without leaving visual mode and losing your current selection?

I have this in my vimrc: "keep visual mode after indent vnoremap > >gv vnoremap < <gv Note that you could also simply use . (dot) to repeat the last indent action.
VanLaser's user avatar
  • 9,620
21 votes
Accepted

How to move the cursor to the correct indentation level without quiting insert mode?

As @jamessan mentioned, <C-f> will indent to the correct place from insert mode. You can also use <C-t> and <C-d> to increase or decrease the indention level from insert mode. ...
Peter Rincker's user avatar
19 votes
Accepted

Unexplained gq indentation issue

The problem is that you have set smartindent in your ~/.vimrc. The smartindent options causes Vim to assume that your text is some C-like programming language when indenting. Among other things, it ...
garyjohn's user avatar
  • 6,284
17 votes
Accepted

Vim doesn't use the correct indentation in Python files

It gets reset by the Python filetype plugin; from /usr/share/vim/vim74/ftplugin/python.vim: " As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 This file is loaded ...
Martin Tournoij's user avatar
13 votes

How can I stop vim automatically inserting a tab in CSS files?

I found a couple of ways to solve the problem. 1. reload the buffer after running :filetype indent off Vim's docs (:help :filetype-indent-off) provided an explanation: You can disable :filetype ...
the_velour_fog's user avatar
13 votes
Accepted

Why does >3k move the cursor up when >3j does not move it down?

Yes, Vim automatically moves to the top most indented line. To see this, position the cursor in the middle of a paragraph and use >ap to indent the whole paragraph. Note that this is not specific ...
Lithis's user avatar
  • 1,030
13 votes
Accepted

Why is "set noexpandtab" in my ~/.vimrc ignored when I open a file?

It is not ignored, it is overwritten by your filetype plugin. In this case the python plugin. You can verify that like Marth said, with the :verbose command: :verbose set expandtab? If you want to ...
B.G.'s user avatar
  • 1,116
13 votes
Accepted

How to visually select based on indentation?

I've used vim-indent-object for a while with some success. It provides text objects like ii, ai, iI, and aI, each with slightly different semantics. For your sample code def some_method if @foo ...
D. Ben Knoble's user avatar
  • 25.3k
13 votes
Accepted

Why does vim still auto-indent LaTeX after I set noai noci nosi?

'indentexpr' has the highest priority of how vim can automatically indent lines. :h 'indentexpr': When this option is not empty, it overrules the 'cindent' and 'smartindent' indenting. Your ...
Hotschke's user avatar
  • 4,640
12 votes
Accepted

Toggling Tabs and Spaces

Generally the retab command and the expandtab option can accomplish what you're talking about without plugins if that's what you want. Do :set expandtab to set vim to prefer spaces to tabs, :set ...
ZeroG's user avatar
  • 461
12 votes
Accepted

Indent to next indentation level with >>

When you use one of the commands {count}>>, {count}<<, >{motion} or <{motion}, on some lines which have already been indented, and you want their new indentation level to be a ...
user9433424's user avatar
  • 6,118
11 votes
Accepted

How to unindent code blocks?

You don't need to enter insert mode via visual-block mode to indent/outdent multiple lines: you can do it directly from visual mode by pressing > for indent and < for outdent. (See :help v_< ...
Rich's user avatar
  • 31.3k
10 votes

How do you indent > < without leaving visual mode and losing your current selection?

I know this isn't an automatic solution, but you can accomplish this by using gv after the visual indent. This will go into visual mode with the previous selection selected, and your cursor at the ...
Tumbler41's user avatar
  • 7,706
10 votes
Accepted

Vim plugin where the first lines in the editor show the first line(s) with less indendation that are not visible

There's plug-in wellle/context.vim which seems to implement what you requested. (Perhaps it's the one D. Ben Knoble was trying to recall?) It will try to show context (if, for or while block, function/...
filbranden's user avatar
  • 28.4k
9 votes
Accepted

How to override the '=' command?

If you have nothing against a plugin install, Rhysd's vim-clang-format may be a valid solution, instead of a custom equalprg. As the documentation states, with Kana's vim-operator-user dependency ...
VanLaser's user avatar
  • 9,620
9 votes
Accepted

Vim indent using "=" inserts 2 tabs

Your 'shiftwidth' appears to still be set to the default value of 8. Try changing that to 4 to match your 'tabstop' setting: :set shiftwidth=4 See :help 'shiftwidth'
garyjohn's user avatar
  • 6,284
9 votes
Accepted

expandtab not replacing tabs after space separated characters

This is how tabs work. Pressing the Tab doesn't mean "insert n spaces", but rather "go to the next tabstop". Every line is divided in "cells" of n spaces, for example four: ---->--->--->---&...
Martin Tournoij's user avatar
9 votes

Can vimwiki be made to treat list indentation the way vim-notes does?

I'm going to ignore the majority of your question (perhaps someone will be along later to provide more specifically what you're asking for) and instead suggest that you just use insert mode's indent ...
Rich's user avatar
  • 31.3k
8 votes
Accepted

Incorrect auto-indent in python code

In this case, the auto-indentation seems confused because the def __init__() is indented by four spaces, while the others are indented by two spaces. This is valid Python, but the Vim Python ...
Martin Tournoij's user avatar
8 votes
Accepted

How do I comment out lines without changing indentation?

Alternatively, you could use the :g command. I would do: :g/\s*#pdb.set_trace()/normal ^x to uncomment and :g/\s*pdb.set_trace()/normal I# to comment. This is nice because it's more readable (and ...
DJMcMayhem's user avatar
  • 17.4k
8 votes

How can you indent your current file without losing your cursor position?

You could define a custom command using :help winsaveview(): command! -range=% Equal let b:wv = winsaveview() | silent execute <line1> . ',' . <line2> . 'normal! ==' | call winrestview(b:...
romainl's user avatar
  • 39.1k
8 votes
Accepted

How do I disable intelligent indentation in HTML files?

It turns out that Vim ships with a bunch of indent.vim files (enabled with :filetype indent on), including one for HTML. You can read help for it at :help html-indenting. This HTML indent file sets ...
Flimm's user avatar
  • 2,182
8 votes

Why is line continuation is indented with 12 spaces in vimscript?

You can change the amount of that indentation by setting the variable g:vim_indent_cont, e.g., :let g:vim_indent_cont = &sw See :help ft-vim-indent
garyjohn's user avatar
  • 6,284
8 votes
Accepted

Automatic whitespace in python

You want to have this setting: " ---- Minimal configuration: set smartindent " Do smart autoindenting when starting a new line set shiftwidth=4 " Set number of spaces per auto indentation set ...
Nales's user avatar
  • 198

Only top scored, non community-wiki answers of a minimum length are eligible