If I wanted to have traditional indentation in vi / vim, I would enter these commands:

:set tabstop=4
:set shiftwidth=4
:set expandtab

It is tedious to type those commands every time I open a file. How do I permanently store those settings?

3 Answers 3


Create a file in your home directory called .vimrc, and put your commands in there:

set tabstop=4
set shiftwidth=4
set expandtab

Ubuntu's Vim Howto has a few pointers to basic customisation, if you want to dig deeper there's the Vim Book and the FAQ as well.

vi-improved.org also has a nice, big example of one person's .vimrc for you to rummage around in.



set tabstop=4
set shiftwidth=4
set expandtab


set ts=4 sw=4 
set expandtab

In your ~/.vimrc file. E.G. /home/user/.vimrc or /home/$(whoami)/.vimrc. You can use your other settings in .vimrc as well, the ones you regularly use, for example syntax on if you use the full version of VIM.


Once you open the terminal in \home\user\exampleuser\, (the default directory), create the file .vimrc. If you really like vim, you can type vim .vimrc into the command line, or you can use nano. This file will control vim. Then type your code you want to set here like this: set expandtab (notice no colons (:)) Then, save the file and you're done!

  • 1
    A : before a command in vimrc is harmless. :set is the same as set in vimrc. See :h script.
    – muru
    Dec 17, 2017 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.