简体   繁体   中英

Why won't Vim use my key mapping when I start a new session?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM