Mac OS X上的vim功能键映射不起作用 [英] vim on mac os X function key mapping not working

查看:91
本文介绍了Mac OS X上的vim功能键映射不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用Mac OS X Lion系统,并尝试在终端中使用Vim.我以前在Ubuntu系统中有一个.vimrc文件,并且将 F2 F5 键映射到pastetoggle并运行python解释器.这是我要写的两行:

I have recently started using a Mac OS X Lion system and tried to use Vim in terminal. I previously had a .vimrc file in my Ubuntu system and had F2 and F5 keys mapped to pastetoggle and run python interpreter. Here are the two lines I have for it:

set pastetoggle=<F2>
map <buffer> <F5> :wa<CR>:!/usr/bin/env python % <CR>

它在Ubuntu中运行良好,但在Mac中不再运行. (以上两行位于主目录下的.vimrc中.)我已根据自己的喜好关闭了Mac特定功能,因此功能键未用于音量之类的操作.现在按 F5 似乎会将所有字母大写,直到下一个单词为止,而 F2 似乎删除下一行并插入O ...

It's working just fine in Ubuntu but no longer works in Mac. (The above two lines are in .vimrc under my home dir.) I have turned off the Mac specific functions in my preference so the function keys are not been used for things like volume. Right now pressing F5 seems to capitalize all letters until next word, and F2 seems to delete next line and insert O.....

我还需要做其他事情才能使其按预期工作吗?

Is there something else I need to do to have it working as expected?

此外,我一直使用solarized作为我的配色方案,并尝试在Mac中现在使用相同的配色方案.似乎正在从.vimrc中读取scheme命令,但是颜色仍为默认颜色.即使.vim/colors文件与以前一样.这是我需要解决的相关错误吗?也许是在我自己的文件之后读取了另一个设置文件? (我正在寻找_vimrc和.gvimrc,不存在.)

In addition, I had been using solarized as my color scheme and tried to have the same color scheme now in Mac. It seems that the scheme command is being read from .vimrc, but the colors are stil the default colors. Even though the .vim/colors files are just the same as before. Is this a related error that I need to fix? Perhaps another setting file being read after my own? (I looked for _vimrc and .gvimrc, none exists.)

谢谢!

推荐答案

我终于通过添加这样的映射使函数映射起作用:

I finally got my function mappings working by resorting to adding mappings like this:

if has('mac') && ($TERM == 'xterm-256color' || $TERM == 'screen-256color')
  map <Esc>OP <F1>
  map <Esc>OQ <F2>
  map <Esc>OR <F3>
  map <Esc>OS <F4>
  map <Esc>[16~ <F5>
  map <Esc>[17~ <F6>
  map <Esc>[18~ <F7>
  map <Esc>[19~ <F8>
  map <Esc>[20~ <F9>
  map <Esc>[21~ <F10>
  map <Esc>[23~ <F11>
  map <Esc>[24~ <F12>
endif

如果您需要验证这些转义序列是否与您的终端机匹配或设置您自己的转义序列,这些问题的答案将很有帮助.

Answers to these questions were helpful, if you need to verify that these escape sequences match your terminal's or set your own:

在vim中映射功能键
将特殊键绑定为vim快捷键

这可能取决于终端仿真器的行为(干扰),但是@Mark Carey的建议对我来说还不够(我希望它是如此简单).使用OS X上的iTerm2,我已经为xterm-256color和tmux为screen-256color配置了它,并且功能映射仍然不起作用.因此,如果来自iTerm2的这些序列符合xterm,则has('mac')可能是不必要的,我尚未检查,因此暂时将其留在我自己的配置中.

It probably depends on terminal emulators behaving consistently (guffaw), but @Mark Carey's suggestion wasn't enough for me (I wish it was so simple). With iTerm2 on OS X, I'd already configured it for xterm-256color and tmux for screen-256color, and function mappings still wouldn't work. So the has('mac') might be unnecessary if these sequences from iTerm2 are xterm-compliant, I haven't checked yet so left it in my own config for now.

您可能还需要一些imap版本.请注意,您不应该使用noremap变体,因为您要做希望这些映射级联(触发您将<Fx>映射到的任何对象).

You might want some imap versions too. Note that you shouldn't use noremap variants since you do want these mappings to cascade (to trigger whatever you've mapped <Fx> to).

这篇关于Mac OS X上的vim功能键映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆