Table of Contents
General
A complete Vim configuration can be installed by running:
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
If you want to add customized configuration, edit:
vim ~/.vim_runtime/my_configs.vim
A basic Vim configuration for consistent indentation is:
set shiftwidth=4 " used by >>, << and tab.
set tabstop=4 " number of space characters used when displaying TAB
set expandtab " replace TAB by spaces
set softtabstop=4 " will erase 4 spaces at once when using BS in the beginning of lines only
These options mean:
shiftwidth=4: use four spaces when indenting with commands such as>>,<<, or auto-indent.tabstop=4: display a literal tab character as four columns wide.expandtab: insert spaces when pressing the Tab key instead of inserting a real tab character.softtabstop=4: make editing feel like one indentation level is four spaces, including when deleting indentation with Backspace.
If this is an existing file and you want to normalize the indentation according to the current settings, run this inside Vim:
:%retab
This converts tab characters to spaces when expandtab is enabled. Before using it on a large file, it is better to check the diff afterward, because changing indentation can be noisy in version control.
Python
For Python, four spaces are the standard indentation width. The same settings work well:
set shiftwidth=4
set tabstop=4
set expandtab
set softtabstop=4
You can also set them only for Python files by adding an autocmd:
autocmd FileType python setlocal shiftwidth=4 tabstop=4 expandtab softtabstop=4
Using setlocal keeps the setting limited to the current buffer, so it will not unexpectedly affect other file types.
C
C projects may use tabs, spaces, or a project-specific mixture. Check the style used by the project before converting indentation.
For a four-space C style using spaces:
autocmd FileType c setlocal shiftwidth=4 tabstop=4 expandtab softtabstop=4
For a tab-based C style where one tab displays as eight columns:
autocmd FileType c setlocal shiftwidth=8 tabstop=8 noexpandtab softtabstop=8
The important point is to keep Vim’s indentation settings aligned with the project’s existing style.
Vim and Notepad++ Inconsistency
The usual inconsistency between Vim and Notepad++ comes from treating tabs differently. One editor may display a real tab as four columns, while another displays it as eight columns. A file can then look aligned in one editor and broken in another.
To inspect whether a file contains real tab characters in Vim, run:
:set list
To hide the markers again:
:set nolist
If the file contains groups of eight spaces and you want to replace each group with four spaces, you can use:
:%s/ / /g
That command replaces eight literal spaces with four literal spaces throughout the file. It does not replace tab characters. If the file contains real tabs and the goal is to convert them according to the current Vim indentation settings, use:
:%retab
A practical workflow is:
:set tabstop=4 shiftwidth=4 expandtab softtabstop=4
:%retab
:w
Then reopen the file in Notepad++ and configure its tab width to match the project style. Consistency matters more than the specific number, so choose the indentation rule once and apply it in every editor used for the file.
