updated vim solarized togglebg plugin to fix silent error on unique remapping

This commit is contained in:
Ethan Schoonover 2011-04-12 16:17:59 -07:00
parent 4727d3afd6
commit 4a9b7ecc66
4 changed files with 68 additions and 48 deletions

View file

@ -1,3 +1,13 @@
---
Title: Solarized Colorscheme for Vim
Description: Precision colors for machines and people
Author: Ethan Schoonover
Colors: light yellow
Created: 2011 Mar 15
Modified: 2011 Apr 12
---
Solarized Colorscheme for Vim Solarized Colorscheme for Vim
============================= =============================
@ -185,15 +195,19 @@ Toggle Background Function
Solarized comes with a Toggle Background plugin that by default will map to Solarized comes with a Toggle Background plugin that by default will map to
<F5> if that mapping is available. If it is not available you will need to <F5> if that mapping is available. If it is not available you will need to
either map the function manually or change your current <F5> mapping to either map the function manually or change your current <F5> mapping to
something else. If you wish to map the function manually, enter the following something else.
lines in your .vimrc:
nmap <unique> <F5> <Plug>ToggleBackground To set your own mapping in your .vimrc file, simply add the following three
imap <unique> <F5> <Plug>ToggleBackground lines to support normal, insert and visual mode usage, changing the "<F5>"
vmap <unique> <F5> <Plug>ToggleBackground value to the key or key combination you wish to use:
Note that it is important to *not* use the noremap map variants. The plugin call togglebg#map("<F5>")
uses noremap internally. You may run `:help togglebg` for more information.
Note that you'll want to use a single function key or equivalent if you want
the plugin to work in all modes (normal, insert, visual).
Note also that it is important to NOT use the noremap map variants. The plugin
uses noremap internally.
Code Notes Code Notes
---------- ----------
@ -254,4 +268,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.

View file

@ -3,21 +3,10 @@
" Maintainer: Ethan Schoonover " Maintainer: Ethan Schoonover
" License: OSI approved MIT license " License: OSI approved MIT license
if exists("g:loaded_ToggleBackground") if exists("g:loaded_togglebg")
finish finish
endif endif
let g:loaded_ToggleBackground = 1 let g:loaded_togglebg = 1
if !exists("no_plugin_maps") && !hasmapto('<Plug>ToggleBackground')
" map alone won't work here as it doesn't
try
silent! nmap <unique> <F5> <Plug>ToggleBackground
silent! imap <unique> <F5> <Plug>ToggleBackground
silent! vmap <unique> <F5> <Plug>ToggleBackground
finally
let g:test_val = "checked"
endtry
endif
" noremap is a bit misleading here if you are unused to vim mapping. " noremap is a bit misleading here if you are unused to vim mapping.
" in fact, there is remapping, but only of script locally defined remaps, in " in fact, there is remapping, but only of script locally defined remaps, in
@ -43,3 +32,16 @@ function! ToggleBackground()
echo "Please update your ToggleBackground mapping. ':help togglebg' for information." echo "Please update your ToggleBackground mapping. ':help togglebg' for information."
endfunction endfunction
function! togglebg#map(mapActivation)
try
exe "silent! nmap <unique> ".a:mapActivation." <Plug>ToggleBackground"
exe "silent! imap <unique> ".a:mapActivation." <Plug>ToggleBackground"
exe "silent! vmap <unique> ".a:mapActivation." <Plug>ToggleBackground"
finally
return 0
endtry
endfunction
if !exists("no_plugin_maps") && !hasmapto('<Plug>ToggleBackground')
call togglebg#map("<F5>")
endif

View file

@ -1,9 +1,11 @@
togbg togglebackground.txt /*togbg* tog-bg togglebg.txt /*tog-bg*
togbg-default togglebackground.txt /*togbg-default* togbg togglebg.txt /*togbg*
togbg-issues togglebackground.txt /*togbg-issues* toggle-background togglebg.txt /*toggle-background*
togbg-newmap togglebackground.txt /*togbg-newmap* toggle-bg togglebg.txt /*toggle-bg*
togbg-usage togglebackground.txt /*togbg-usage* togglebackground togglebg.txt /*togglebackground*
toggle-background togglebackground.txt /*toggle-background* togglebg togglebg.txt /*togglebg*
togglebackground togglebackground.txt /*togglebackground* togglebg-default togglebg.txt /*togglebg-default*
togglebackground.txt togglebackground.txt /*togglebackground.txt* togglebg-issues togglebg.txt /*togglebg-issues*
togglebg togglebackground.txt /*togglebg* togglebg-newmap togglebg.txt /*togglebg-newmap*
togglebg-usage togglebg.txt /*togglebg-usage*
togglebg.vim togglebg.txt /*togglebg.vim*

View file

@ -1,30 +1,31 @@
*togglebackground.txt* For Vim version 7.3. or newer Last change: 2011 Apr 7 *togglebg.vim* For Vim version 7.3. or newer Modified: 2011 Apr 12
TOGGLE BACKGROUND PLUGIN by Ethan Schoonover ~ TOGGLE BACKGROUND PLUGIN by Ethan Schoonover ~
Toggle Background *toggle-background* Toggle Background *togglebackground*
*togglebackground* *toggle-background*
*togglebg* *togbg* *togglebg* *toggle-bg*
*togbg* *tog-bg*
Toggle Background is a simple plugin to switch between light and dark Toggle Background is a simple plugin to switch between light and dark
background modes and reset the colorscheme. This is most useful for background modes and reset the colorscheme. This is most useful for
colorschemes that support both light and dark modes and in terminals or gui colorschemes that support both light and dark modes and in terminals or gui
vim windows where the background will be properly set. vim windows where the background will be properly set.
0. Usage |togbg-usage| 0. Usage |togglebg-usage|
1. Default Mapping |togbg-default| 1. Default Mapping |togglebg-default|
2. Changing the Mapping |togbg-newmap| 2. Changing the Mapping |togglebg-newmap|
3. Issues |togbg-issues| 3. Issues |togglebg-issues|
============================================================================== ==============================================================================
0. Usage *togbg-usage* 0. Usage *togglebg-usage*
Press your map key(s) to activate Toggle Background, or select "Toggle Press your map key(s) to activate Toggle Background, or select "Toggle
Background" from the 'Window' menu while in gui mode. Background" from the 'Window' menu while in gui mode.
============================================================================== ==============================================================================
1. Default Mapping *togbg-default* 1. Default Mapping *togglebg-default*
Toggle Background starts with a default mapping to function key <F5>. If you Toggle Background starts with a default mapping to function key <F5>. If you
are already using this in a mapping, Toggle Background will not map itself to are already using this in a mapping, Toggle Background will not map itself to
@ -32,20 +33,22 @@ a default and you will have to map it manually in your .vimrc file, or
remove/change your existing <F5> mapping to another value. remove/change your existing <F5> mapping to another value.
============================================================================== ==============================================================================
2. Changing the Mapping *togbg-newmap* 2. Changing the Mapping *togglebg-newmap*
To set your own mapping in your .vimrc file, simply add the following three To set your own mapping in your .vimrc file, simply add the following three
lines to support normal, insert and visual mode usage: lines to support normal, insert and visual mode usage, changing the "<F5>"
value to the key or key combination you wish to use:
nmap <unique> <F5> <Plug>ToggleBackground call togglebg#map("<F5>")
imap <unique> <F5> <Plug>ToggleBackground
vmap <unique> <F5> <Plug>ToggleBackground
Note that it is important to NOT use the noremap map variants. The plugin uses Note that you'll want to use a single function key or equivalent if you want
noremap internally. the plugin to work in all modes (normal, insert, visual).
Note also that it is important to NOT use the noremap map variants. The plugin
uses noremap internally.
============================================================================== ==============================================================================
3. Issues *togbg-issues* 3. Issues *togglebg-issues*
When using the plugin during insert mode, there should be no interruption in When using the plugin during insert mode, there should be no interruption in
workflow. However, if you activate the plugin during REPLACE mode, you will workflow. However, if you activate the plugin during REPLACE mode, you will