0

I was editing my vimrc, and decided to remove a mapping based on some information I found on <cr>. So I deleted the mapping and called my :SourceVimrc command (command SourceVimrc source $MYVIMRC). To my surprise, when I pressed enter, it still performed the deleted mapping. I had to open a new session for the mapping to disappear.

I found the :scriptnames command, and that indicated to me that it was correctly loading the vimrc:

  1: ~/.config/nvim/init.vim                                                                    
  2: ~/.vimrc

So I added a new mapping for <cr> to make sure that sourcing works: nnoremap <cr> <cr><cr>, and that was loaded correctly.

I checked "Learn Vimscript the Hard Way", because I thought I remembered something there, but didn't find it if it is. On StackOverflow and here I didn't see this mentioned, although I'm surprised because I'm sure this is a question someone has asked before.

  1. Is this correct? Does :source $MYVIMRC not remove mappings?
  2. If this is true, can I change my command to remove all old mappings?

1 Answer 1

1

source command executes ex-commands from the file being sourced. This implies nothing is removed unless you explicitly didn't add unlet, unmap and other commands to remove specific things.

Thus,

  1. :source $MYVIMRC doesn't remove mappings
  2. execute :unmap <cr>, do it for each mapping you want to "remove".

If you want to remove all mappings use :h :mapclear. Bear in mind that it would also remove mappings introduced by plugins and simple :source $MYVIMRC would not restore them.

2
  • Sorry, I wasn't specific in my question (I updated it now), is it possible to remove all old mappings? For instance removing all custom mappings before loading the vimrc? Dec 22, 2021 at 9:38
  • 1
    @jeffrey.d.m updated
    – Maxim Kim
    Dec 22, 2021 at 9:47

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.