Skip to main content
89 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,232
72 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.9k
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
27 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,116
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,720
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
15 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
  • 26.2k
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,040
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,126
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,750
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
  • 491
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,138
12 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
  • 32k
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
  • 32k
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,746
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.8k
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,720
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,329
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

Pasting text on Vim inside tmux breaks indentation

Manually toggling :set paste/:set nopaste as suggested by francois P is cumbersome, and resetting the TERM variable as evaristegd suggests is a very bad idea as explained in the comments (which hint ...
Dining Philosopher's user avatar
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.6k
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
  • 40.7k
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,232
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,329
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
8 votes

How to change the displayed indentation amount?

As Robert Axelson has already stated, if the file is indented using tabs, this is easily achieved by using :set tabstop, which is designed for this very purpose. A solution for halving space indents ...
Rich's user avatar
  • 32k
7 votes
Accepted

Function to refactor indents and tabs

The problem is that gg, = and G are normal mode commands, as opposed to ex commands which are used within a script. Writing normal gg=G should solve your problem. As @Carpetsmoker has pointed out in ...
Ingo's user avatar
  • 986
7 votes
Accepted

augroup end indentation

You should use END instead of end for the closing augroup statement. Apparently it's a bug (cf Carpetsmoker's comment), it should behave the same but it does not. From the documentation (:h :aug): ...
nobe4's user avatar
  • 16.1k

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