0

I am looking at a scenario where in order to keep track of changes to my setup, rather than delete functions and keymaps defined in vimrc or other plugin I add commands which disable those functions and keymaps further down the execution sequence.

For example in the example below how would undo the mapping of the <cr> key and undefine the function like it was never created in the first place?

cnoremap <silent> <cr> <cr>:call <SID>CommandCallback()<cr>

function! s:CommandCallback()
  let last_command = @:

  if last_command =~ 'tabnew'
    echomsg "Tabnew was called"
  endif
endfunction
  • 1
    I think your best option is to try Tim Pope's vim-scriptease which provides a :Disarm function which try to do what you're looking for. – statox May 5 '17 at 7:24
  • 1
    I'd heartily recommend storing your vim config in source control, which adds many other advantages in addition to making it easy to track changes. ...alternatively, you could always just comment out the parts you no longer want to use! – Rich May 5 '17 at 13:30
3

To remove a command-line mapping, use:

:cunmap {lhs}

Similar commands exist for the other mapping modes. See :help :unmap

To remove a function, use:

:delfunction {name}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.