More specific Mapping().
authorIain Patterson <me@iain.cx>
Wed, 26 Feb 2014 10:54:35 +0000 (10:54 +0000)
committerIain Patterson <me@iain.cx>
Wed, 26 Feb 2014 10:57:37 +0000 (10:57 +0000)
Add an extra argument to Mapping() to define the specific modes which it
should affect.

.vimrc

diff --git a/.vimrc b/.vimrc
index 8c8f8f9..f572ab2 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -425,11 +425,23 @@ fun! MakeMode_unmap() "{{{2
 endfun "}}}2
 
 " Function to create mappings with either a hardcoded \ or <Leader>.
 endfun "}}}2
 
 " Function to create mappings with either a hardcoded \ or <Leader>.
-fun! Mapping(keysequence,mapping) "{{{2
+fun! Mapping(keysequence, mapping, ...) "{{{2
   if version < "600"
   if version < "600"
-    exec "map \\" . a:keysequence . " " . a:mapping . ":<CR>"
+    let l:args = "\\" . a:keysequence . " " . a:mapping . ":<CR>"
   else
   else
-    exec "map <silent> <Leader>" . a:keysequence . " " . a:mapping
+    let l:args = "<silent> <Leader>" . a:keysequence . " " . a:mapping
+  endif
+  if a:0 == 0
+    " General mapping.
+    exec "map " . l:args
+  else
+    " Specific mapping(s).
+    let l:i = 1
+    while l:i <= a:0
+      exec "let l:map = a:" . l:i . " . \"map\""
+      exec l:map . " " . l:args
+      let l:i = l:i + 1
+    endwhile
   endif
 endfun "}}}2
 
   endif
 endfun "}}}2
 
@@ -1265,9 +1277,9 @@ if version >= "700" "{{{1
 version 7.0
 
 " Narrow buffer with \w.
 version 7.0
 
 " Narrow buffer with \w.
-call Mapping("w", ":NarrowRegion<CR>")
+call Mapping("w", ":NarrowRegion<CR>", "n", "v")
 " Narrow window with \W.
 " Narrow window with \W.
-call Mapping("W", ":NarrowWindow<CR>")
+call Mapping("W", ":NarrowWindow<CR>", "n", "v")
 
 " Helper to show tab name.
 fun! <SID>TabName(label, gui) "{{{2
 
 " Helper to show tab name.
 fun! <SID>TabName(label, gui) "{{{2