简体   繁体   English

开始新的会话时,Vim为什么不使用我的密钥映射?

[英]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: 按照以下顺序映射Vim中的F2键后,它在新的Vim会话中不起作用:

:map <F2> :ls<CR>

Pressing F2 here displays the files. 在此处按F2键显示文件。

:mkexrc!

Close Vim. 关闭Vim。

Reopen Vim. 重新打开Vim。

Pressing F2 now does nothing. 现在按F2键不执行任何操作。

The mapping is visible in the _exrc file as: 映射在_exrc文件中显示为:

map <F2> :ls

What am I missing? 我想念什么?

I think that you are simply missing a literal <CR> . 我认为您只是缺少文字<CR> Type this command in the command line followed by Enter. 在命令行中键入此命令,然后按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. 看看_exrc文件是否由Vim执行:scriptnames应该在顶部附近显示它。

  2. If it is executed, see if <F2> is mapped elsewhere: :verbose map <F2> . 如果执行,请查看<F2>是否映射到其他地方:verbose map <F2>

Anyway, Vim is not Vi. 无论如何,Vim不是Vi。 You should use :mkvimrc! 您应该使用:mkvimrc! . Or a normal $HOME/_vimrc . 或正常的$HOME/_vimrc

edit 编辑

FYI I just created a ~/.exrc file using :mkexrc! 仅供参考,我刚刚使用:mkexrc!创建了~/.exrc文件:mkexrc! and it's not executed by Vim at startup. 而且它不是由Vim在启动时执行的。 You should definitely use a normal $HOME/_vimrc . 您绝对应该使用普通的$HOME/_vimrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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