Skip to content

Instantly share code, notes, and snippets.

@Ram-Z
Last active July 4, 2016 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-Z/7c974aafb4c1d59a062eb64255ce80a0 to your computer and use it in GitHub Desktop.
Save Ram-Z/7c974aafb4c1d59a062eb64255ce80a0 to your computer and use it in GitHub Desktop.
nnoremap <leader>f :call someFunction()<CR>
let map = "\<leader>f"
let save_map = maparg(map)
" save_map == ':call someFunction()<CR>'
nnoremap <leader>f :call someOtherFunction()<CR>
" I'd like to execute the previous mapping of <leader>f
" doesn't work because '<CR>' is not escaped in save_map
exe "normal!" save_map
if !exists('g:switch_mapping')
let g:switch_mapping = 'gs'
endif
let g:switch_mapping_fallback = 1
command! Switch call s:Switch()
function! s:Switch()
let definitions = s:GetDefinitions()
" returns either 0 or 1
let retval = switch#Switch(definitions, {})
if g:switch_mapping_fallback && !retval
exe 'normal!' s:orig_mapping
endif
endfunction
if g:switch_mapping != ''
let s:orig_mapping = maparg(g:switch_mapping, 'n')
if empty(s:orig_mapping)
let s:orig_mapping = g:switch_mapping
endif
exe 'nnoremap' g:switch_mapping ':Switch<cr>'
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment