I have been using Vim, and I would really like to save my settings. The problem I am having is that I cannot find my .vimrc file, and it is not in the standard /home/user/.vimrc
location. How might I find this file?
17 Answers
Short answer:
To create your vimrc, start up Vim and do one of the following:
:e $HOME/.vimrc " on Unix, Mac or OS/2
:e $HOME/_vimrc " on Windows
:e s:.vimrc " on Amiga
Insert the settings you want, and save the file.
Note that exisitence of this file will disable the compatible
option. See below for details.
Long answer:
There are two kinds of vimrc:
- the user vimrc in
$HOME
- the system vimrc in
$VIM
(on Amiga systems,s:.vimrc
is considered a user vimrc)
The user vimrc file often does not exist until created by the user. If you cannot find $HOME/.vimrc
(or $HOME/_vimrc
on Windows) then you can, and probably should, just create it.
The system vimrc should normally be left unmodified and is located in the $VIM
* directory. The system vimrc is not a good place you keep your personal settings. If you modify this file your changes may be overwritten if you ever upgrade Vim. Also, changes here will affect other users on a multi-user system. In most cases, settings in the user vimrc will override settings in the system vimrc.
From :help vimrc
:
A file that contains initialization commands is called a "vimrc" file. Each line in a vimrc file is executed as an Ex command line. It is sometimes also referred to as "exrc" file. They are the same type of file, but "exrc" is what Vi always used, "vimrc" is a Vim specific name. Also see |vimrc-intro|.
Places for your personal initializations:
Unix $HOME/.vimrc or $HOME/.vim/vimrc OS/2 $HOME/.vimrc, $HOME/vimfiles/vimrc or $VIM/.vimrc (or _vimrc) MS-Windows $HOME/_vimrc, $HOME/vimfiles/vimrc or $VIM/_vimrc Amiga s:.vimrc, home:.vimrc, home:vimfiles:vimrc or $VIM/.vimrc
The files are searched in the order specified above and only the first one that is found is read.
(MacOS counts as Unix for the above.)
Note that the mere existence of a user vimrc will change Vim's behavior by turning off the compatible
option. From :help compatible-default
:
When Vim starts, the 'compatible' option is on. This will be used when Vim starts its initializations. But as soon as a user vimrc file is found, or a vimrc file in the current directory, or the "VIMINIT" environment variable is set, it will be set to 'nocompatible'. This has the side effect of setting or resetting other options (see 'compatible'). But only the options that have not been set or reset will be changed.
* $VIM
may not be set in your shell, but is always set inside Vim. If you want to see what it's set to, start up Vim and use the command :echo $VIM
For whatever reason, these answers didn't quite work for me. This is what worked for me instead:
In Vim, the :version
command gives you the paths of system and user vimrc and gvimrc files (among other things), and the output looks something like this:
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
The one you want is user vimrc file: "$HOME/.vimrc"
So to edit the file: vim $HOME/.vimrc
Source: Open vimrc file
I'd like to share how I set showing the line number as the default on Mac.
- In a terminal, type
cd
. This will help you go to the home folder. - In the terminal, type
vi .vimrc
. This will create an empty vimrc system file which you want to use. - In the file, type
set number
, and then hit Esc on the keyboard and type in:wq
. This will set the line number shown in the default setting filevimrc
and save it. vi something
to see if this works. If not, try to restart the terminal completely.
If in a terminal, type in cd /usr/share/vim/
, go to that folder, and type in ls
. You can directly see a file named vimrc. But it's a system file that says read only. I feel it's not a good idea to try modify it. So following the above steps to create a vimrc by yourself is better. It worked for me.
Here are a few more tips:
In Arch Linux the global one is at
/etc/vimrc
. There are some comments in there with helpful details.Since the filename starts with a
.
, it's hidden unless you usels -a
to show ALL files.Typing
:version
while in Vim will show you a bunch of interesting information including the file location.If you're not sure what
~/.vimrc
means look at this question.
Useful Information can be obtained using the find
command
find / -iname "*vimrc*" -type f 2>/dev/null
There are many answers already, but it can sometimes be useful to simply run a "find" for anything containing the name "vimrc".
The reason is that this will show you what files you actualy have available on the system currently, rather than what you might put on your system. (The information for which you would obtain from :version
as explained in other answers.)
Example result on my system
On my system this produces
/usr/share/vim/vim82/vimrc_example.vim
/usr/share/vim/vim82/gvimrc_example.vim
/etc/vim/gvimrc
/etc/vim/vimrc
/etc/vim/vimrc.tiny
Which is quite useful because it tells us that there are 2 example files installed in the share directorys for both gvim and vim, and that there are also some system-wide config files below /etc/
.
On my system, I also have a file at ~/.vimrc
but this does not appear in this list because it is a link to another file, stored under ~/Linux-Config
. But you won't have this directory, it's specific to machines I use on my own network.
Detailed Explanation of find
syntax used
Explanation:
- find starting at the root directory
/
(find works recursively) - anything containing the case insensitive regex
*vimrc*
which means any name withvimrc
(case insensitive) in it somewhere, can be preceeded or followed by anything or nothing (*
) - type = files (not directory/symlink etc)
- throw all errors to
/dev/null
otherwise the output is spammed with unreadable errors from/proc
I tried everything in the previous answer and couldn't find a .vimrc
file, so I had to make one.
I copied the example file, cp vimrc_example.vim ~/.vimrc
.
I had to create the file, copying from /usr/share/vim/vim74/vimrc_example.vim
to ~/.vimrc
. Those were the instructions in the vimrc_example
file.
My solution is for Unix for other operating systems. According to the Vim documentation, your destination path should be as follows:
For Unix and OS/2 : ~/.vimrc
For Amiga : s:.vimrc
For MS-DOS and Win32: $VIM\_vimrc
For OpenVMS : sys$login:.vimrc
The vimrc file in Ubuntu (12.04 (Precise Pangolin)): I tried :scriptnames
in Vim, and it shows both /usr/share/vim/vimrc
and ~/.vimrc
.
But I had manually created ~/.vimrc
.
In SUSE Linux Enterprise Server (SLES) and openSUSE the global one is located at /etc/vimrc
.
To edit it, simply do vi /etc/vimrc
.
Where is the .vimrc
file? It depends on the OS. As you can see, you were looking for /home/$user/.vimrc
, which probably means you are using BSD / Linux. Here are the locations for each OS...
- BSD / Linux :
/home/$user/.vimrc
- SunOS / Solaris :
/export/home/$user/.vimrc
- MacOS :
/Users/$user/.vimrc
- Android :
/data/media/$userid/.vimrc
- Unix :
$root/home/$user/.vimrc
- AT&T Unix :
$root/usr/$user/.vimrc
- Unix-Derived :
/var/users/$user/.vimrc
/u01/$user/.vimrc
/usr/$user/.vimrc
/user/$user/.vimrc
/users/$user/.vimrc
(Source: Wikipedia: Default home directory per operating system.)
If it doesn't exist, create it with ~/.vimrc
.
In addition, the root
user has their own special .vimrc
file, which can be found in /root/.vimrc
on BSD / Linux (and in equivalent locations for the other OS's).
The location is set in the $HOME
variable, which is always set in Linux environments. (Source: StackExchange->Unix & Linux.)
/usr/share/vim/vimrc
. – ckjbgames