Last active
May 25, 2016 20:20
-
-
Save louwers/7ab67f35d5161b23b1d45c622e9f6f53 to your computer and use it in GitHub Desktop.
Window-specific keybindings in vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! SetWindowMap(map) | |
exe "noremap <silent> " . a:map . " :call ExecuteWindowMap('" . a:map . "')<CR>" | |
endfunction | |
function! ExecuteWindowMap(map) | |
if exists("w:winMaps") && has_key(w:winMaps, a:map) | |
call feedkeys(w:winMaps[a:map]) | |
else | |
exe "unmap " . a:map | |
let escaped = escape(a:map, "<") "may cause unexpected behavior when mapping "<" | |
silent call feedkeys(escaped) | |
call SetWindowMap(a:map) | |
endif | |
endfunction | |
"Usage: | |
":call WindowMap("<F2>", ":echo \"test\"<CR>") | |
function! WindowMap(map, cmd) | |
if !exists("w:winMaps") | |
let w:winMaps = {} | |
endif | |
let w:winMaps[a:map] = a:cmd | |
call SetWindowMap(a:map) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment