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 ...
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 '...
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 ...
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/...
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 ...
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.
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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 ...
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_< ...
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 ...
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/...
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 ...
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'
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:
---->--->--->---&...
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 ...
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 ...
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 ...
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:...
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 ...
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
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
indentation × 415vimrc × 44
formatting × 26
tab-characters × 21
key-bindings × 19
filetype-html × 18
vimscript × 17
neovim × 16
filetype × 16
whitespace × 13
cut-copy-paste × 12
filetype-python × 11
cursor-movement × 9
filetype-tex × 9
filetype-c × 9
syntax-highlighting × 8
wrapping × 8
filetype-c++ × 8
alignment × 8
visual-mode × 7
comments × 7
filetype-javascript × 7
folding × 6
filetype-php × 6
insert-mode × 5