Some questions on .vimrc and vim configuration

可紊 提交于 2019-12-09 15:45:54

问题


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?


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/7541714/some-questions-on-vimrc-and-vim-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!