The .vimrc file can be used to set some persistent options for Vim. Using this file, you can customize your Vim experience. There are many possibilities for customization: popular examples include setting the color scheme, converting between tabs and spaces, and setting search options.
To create a .vimrc file that will be used when starting Vim, do the following:
$ cd
$ vim .vimrc
The first command places you in your home directory (don't worry, this will be explained in greater detail later in this book). The second starts a Vim editor for the .vimrc file. Don't forget the dot in front, as this is how Linux deals with hidden files (again, more on this later on). We're using the following configuration in our .vimrc file:
set expandtab
set tabstop=2
syntax on
colo peachpuff
set ignorecase
set smartcase
set number
In order, the following things are achieved with this configuration:
- set expandtab: Converts tabs to spaces.
- set tabstop=2: Each tab is converted to two spaces.
- syntax on: Turns on syntax highlighting (by using different colors).
- colorscheme peachpuff: Uses the peachpuff color scheme.
- set ignorecase: Ignores case when searching.
- set smartcase: Doesn't ignore case when searching with one or more uppercase letters.
- set number: shows line numbers.