sponsor Vim development Vim logo Vim Book Ad

GlobalOptions : Turn global options into buffer- or window-local ones.

 script karma  Rating 1/1, Downloaded by 1181  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
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.)
 
install details
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim GlobalOptions*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
GlobalOptions-1.00.vmb.gz 1.00 2013-01-25 7.0 Ingo Karkat Initial upload
ip used for rating: 18.97.14.85

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github