Generally on a unix system, there is a global vimrc
file in the directory /etc
or /etc/vim
. You can also have a .vimrc
file in your home directory that can customize your vi session.
Is it possible to have a .vimrc
elsewhere in your directory tree so you can use different vi properties in different directories? This would be convenient because the editor properties that help you edit Python most quickly are different from those for editing, say, HTML.
This sort of thing does not seem to work be default on my mac or linux lappies. Is there a way to make it happen?
On CentOS 7 and RHEL 7, the system wide configuration file for Vim is in /etc/vimrc. You can also do user specific configuration of Vim. All you have to do is to create a . vimrc file in the HOME directory of the user than you want to configure Vim for and add the required Vim configuration options there.
Vim's user-specific configuration file is located in the home directory: ~/. vimrc , and Vim files of current user are located inside ~/. vim/ . The global configuration file is located at /etc/vimrc .
Using file name completion, you could type :e $M then press Tab until you see the desired variable. If you only want to see the path, type :echo $M then press Tab to see the variable, and press Enter. In gvim, the Edit menu includes "Startup Settings" which will use $MYVIMRC to edit your vimrc file.
Vim has built functionality for this:
:se exrc
Enables the reading of .vimrc, .exrc and .gvimrc in the current directory. If you switch this option on you should also consider setting the 'secure' option (see |initialization|). Using a local .exrc, .vimrc or .gvimrc is a potential security leak, use with care! also see |.vimrc| and |gui-init|.
See http://damien.lespiau.name/blog/2009/03/18/per-project-vimrc/
For proper project support, there are several plugins have similar features. (which I don't use, so I can't recommend any).
If this is really a question of having different settings for different filetypes (rather than different locations on disk), then the correct thing to do is to put these files in ~/.vim/ftplugin
. For example, this is the contents of my ~/.vim/ftplugin/haskell.vim
:
setlocal autoindent
setlocal noexpandtab
setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4
To find out the right name for the script, simply open the kind of file you want to edit and use the :set ft?
command (short for :set filetype?
). Much more information is available via :help ftplugin
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With