Ⅰ. 插件描述
Turn global options into buffer- or window-local ones.Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin '/globaloptions'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle '/globaloptions'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug '/globaloptions'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/vim-scripts/GlobalOptions
Ⅳ. 文档说明
DESCRIPTION
For some Vim options, it may be helpful to make a particular setting only for
certain buffers or windows. Some options offer this, but when the option is
only globally scoped, this cannot be easily done.
For example, the 'scrolloff' option can be set to a high value to effectively
center the current line in the middle of the window. But one may only want
this for certain filetypes, or only in a particular window.
HOW IT WORKS
When a buffer- or window-local global option is set, autocmds are set up that
modify the global option depending on the currently active buffer / window.
Because there can be buffer-local autocmds, but not window-local ones, the
approach taken is slightly different.
USAGE
:SetBufferLocal
Show all global options made buffer-local.
:SetBufferLocal {option}?
Show the buffer-local value of global {option} (if
set).
:SetBufferLocal {option}={value}
Set the global {option} to {value}, but only in the
current buffer. Effectively turns {option} into a
buffer-local option.
:SetBufferLocal {option}<
Remove the buffer-local value of {option}, so that the
global value will be used. Like :setlocal {option}<
:SetWindowLocal
Show all global options made window-local.
:SetWindowLocal {option}?
Show the window-local value of global {option} (if
set).
:SetWindowLocal {option}={value}
Set the global {option} to {value}, but only in the
current window. Effectively turns {option} into a
window-local option.
:SetWindowLocal {option}<
Remove the window-local value of {option}, so that the
global value will be used. Like :setlocal {option}<
Alternatively, you can also directly use the following API functions.
Note that these do less error checking than above commands.
GlobalOptions#SetBufferLocal({option}, {value})
GlobalOptions#ClearBufferLocal({option})
GlobalOptions#SetWindowLocal({option}, {value})
GlobalOptions#ClearWindowLocal({option})
EXAMPLE
Place the current line in the middle of the window by setting 'scrolloff' (a
global option) to a large value, but only for the current window:
:SetWindowLocal scrolloff=999
Place the current line in the middle of the window by setting 'scrolloff' (a
global option) to a large value, but only for a certain filetype (best placed
into ~/.vim/ftplugin/{filetype}.vim):
:call GlobalOptions#SetBufferLocal('scrolloff', 999)
:let b:undo_ftplugin = 'call GlobalOptions#ClearBufferLocal("scrolloff")'
Note that we use the API function in the undo command to avoid an error when
the buffer-local option has already been unset. (And also for setting it, to
be consistent and because it's slightly more efficient.)