Question

After mapping the F2 key in Vim in the following sequence, it does not work in a new Vim session:

:map <F2> :ls<CR>

Pressing F2 here displays the files.

:mkexrc!

Close Vim.

Reopen Vim.

Pressing F2 now does nothing.

The mapping is visible in the _exrc file as:

map <F2> :ls

What am I missing?

Was it helpful?

Solution

I think that you are simply missing a literal <CR>. Type this command in the command line followed by Enter.

:map <F2> :ls<CR>

If it doesn't work…

  1. See if that _exrc file is executed by Vim: :scriptnames should display it near the top.

  2. If it is executed, see if <F2> is mapped elsewhere: :verbose map <F2>.

Anyway, Vim is not Vi. You should use :mkvimrc!. Or a normal $HOME/_vimrc.

edit

FYI I just created a ~/.exrc file using :mkexrc! and it's not executed by Vim at startup. You should definitely use a normal $HOME/_vimrc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top