Ⅰ. 插件描述
This plugin allows to define vim configuration settings per directoryⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'mantiz/vim-plugin-dirsettings'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'mantiz/vim-plugin-dirsettings'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'mantiz/vim-plugin-dirsettings'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/mantiz/vim-plugin-dirsettings
Ⅳ. 文档说明
==========================
VIM - Plugin - dirsettings
Description
This is a simple plugin that allows per directory settings for your favourite
editor VIM. This plugin is mainly inspired by the already existing plugin named
dirsettings, see:
http://www.vim.org/scripts/script.php?script_id=1860
But this plugin goes a little step further. It walks the whole directory tree
up to the root and on its way back it sources each found ".vimrc". This allows
to overwrite specific settings even in subdirectories which inherit the
settings of each parent directory. Furthermore if a .vim folder is found in one
of the parent directories it is added to the runtime path and therefore treated
as the .vim folder inside the home dir.
Additionally it checks for a ".vim/tags" file and appends it to the tag
- This is better than a "tags" file in the current working directory
- source control reasons.
The plugin uses four autocommands (``BufNewFile, BufReadPre, BufWinEnter,
BufEnter`) with the autocommand group dirsettings` (by default). It calls an
internally used function to load directory specific settings, and sets a flag
for the own autocommands so that they are not executed twice which would result
in an endless recursion. After the flag was set, the current event is recalled
which executes all other defined autocommands. This explains why the call todirsettings#Install() should be the very first command in your .vimrc.
Otherwise it could happen that previously defined autocommands are called
twice.
Installation
With pathogen:
This is the tested way to install and use the plugin, however it should work
with every other bundle manager or even without one.
- Change into the directory where pathogen expects your bundles::
git clone <github-url> ./dirsettings.git
- Create a symbolic link to the autoload vimscript provided by this package::
ln -s <path-of-this-package>/autoload/dirsettings.vim ~/.vim/autoload/
Or copy the provided autoload vimscript into your autoload directory::
cp <path-of-this-package>/autoload/dirsettings.vim ~/.vim/autoload/
- Add the following content at the top of your
.vimrc(if you want to be
able to modify the runtimepath before pathogen is invoked, it is important
that this statement is executed before pathogen#infect is executed)::
call dirsettings#Install()
Tips and tricks
- In order to set directory specific settings, try to use always
setlocal
instead ofset. Otherwise these settings will affect other buffers.
Known issues
Global settings affect all buffers
It is perfectly fine to set global options within a per-directory-vimrc-file
but you have to understand that these global options will affect all buffers of
the currently running vim instance. As I know it is not possible to use global
options on a buffer level. Feel free to send me an email if you have any
suggestions to solve this issue.
However, if you want to use this plugin to run a vim instance inside a
directory which uses global per-directory-settings which are fine to affect all
buffers inside this vim instance and you run another vim instance inside
another directory which does not load these directory-settings, it works like a
charm.
Credits
Thanks to Jakob Westhoff_ for adding support for .vim folders.
Thanks to Jakob Westhoff and Tobias Schlitt for adding some tests.
.. _Jakob Westhoff: https://github.com/jakobwesthoff/
.. _Tobias Schlitt: https://github.com/tobys/