在 vim 中更改默认键绑定 [英] Changing default key bindings in vim

查看:47
本文介绍了在 vim 中更改默认键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多次尝试使用 vim 之后,我总是被它的默认键绑定推迟.经过一些研究,我决定将默认键重新映射为更合理的键(至少对于我的口味).我有几个关于更改绑定的问题,但我无法通过 Google 找到答案.

  1. 有没有办法将一个键映射到一个动作而不是而不是另一个键.例如:
    :noremap a h
    将绑定 a 键将光标向左移动.是否有类似
    的内容:noremap a move-cursor-left

    :noremap a :move-cursor-left
    所以我可以在之后读取我的配置文件?

  2. 有没有办法解除所有默认键绑定?我试过 :mapclear 但它似乎不起作用,尽管它可能只是清除非默认绑定.手动取消每个键的映射不是一种选择.如果可能,我想将默认值导出到文件中,以便我可以根据需要对其进行编辑.

  3. 除了 vim-script 之外,还有其他语言可以用来为 vim 编写自己的命令吗?不过,我实际上并没有仔细研究过这个.如果我可以将外部可执行文件绑定到命令,那就足够了.

  4. 我还没有放弃 vim,尽管我想问一下是否有任何类似 vim 的替代品.我的谷歌搜索没有积极开发.如果无法完成上述操作,或者可以合理地将其合并,我想找到一个完全可配置的、模态的、命令行文本编辑器.

解决方案

vi/Vim 的命令集已经编码了 40 年的智慧;完全改变它是一个坏主意.我只能从评论中重复引用这个答案;这应该能说服您(接受这一点,或选择其他编辑器).

再试一次默认命令.需要一些时间来习惯,但大多数 Vim 用户都对这些发誓.对个人风格"进行细微调整是可以的:小心进化,但不是革命.此外,一些键盘布局很奇怪的人(如 DvorakColemak)为了方便会交换几个键.

move-cursor-left 就是 h;借助出色的 :help,您应该能够阅读"您的重映射就好了.

一般来说,即使可以用 Perl、Python、Ruby 等集成语言编写扩展/插件(基于对它们编译成 Vim 二进制文件的支持),你也不会绕过学习一些关键的 VimVimscript 的内部和部分.如果您对此感到不舒服,我建议您使用其他编辑器.不幸的是,根据您对完全可扩展性(可能还有广泛接受和平台支持)的要求,只有一个严肃的选择:Emacs(它不仅可以变成厨房水槽之外的所有东西,还可以变成模态编辑器).

After attempting to use vim a number of times, I'm always been put off by its default key bindings. After some research, I decided to remap the default keys to more sane ones (at least for my tastes). I have a few questions about changing bindings that I could not find answers to through Google.

  1. Is there a way to map a key to an action rather than another key. For example:
    :noremap a h
    will bind the a key to move the cursor left. Is there something along the lines of
    :noremap a move-cursor-left
    or
    :noremap a :move-cursor-left<Enter>
    so I can read my config file afterwards?

  2. Is there a way to unbind all of the default key bindings? I've tried :mapclear but it doesn't seem to work, although it might just be clearing non-default bindings. Unmapping every key manually is not an option. If possible, I would like to export the defaults to a file so I can edit them as I need.

  3. Is there another language I can use to write my own commands for vim other than vim-script? I haven't actually looked into this one so much though. If I can bind an external executable to a command, that would be good enough.

  4. I haven't given up on vim although I would like to ask if there are any vim-like alternatives out there. My Google searches came up with nothing actively developed. If the above cannot be done, or reasonably hacked together, I would like to find a fully configurable, modal, command line text editor that can.

解决方案

The command set of vi / Vim has 40 years of wisdom encoded into it; completely changing it is a bad idea. I can only repeat the reference to this answer from the comments; that should convince you (to accept this, or choose another editor).

Give the default commands another try. It'll take some time to get used to, but most Vim users swear by these. It's fine to make minor adjustments "for personal style": careful evolution, but not revolution. Also, some people with odd keyboard layouts (like Dvorak or Colemak) swap several keys for convenience.

The move-cursor-left is just h; aided by the excellent :help, you should be able to "read" your remappings just fine.

In general, even though it's possible to write extensions / plugins in integrated languages like Perl, Python, Ruby, etc. (based on support for them compiled into the Vim binary), you won't get around learning some key Vim internals and parts of Vimscript. If you don't feel comfortable at all about this, I'd suggest to use another editor. Unfortunately, with your requirements of full extensibility (and probably broad acceptance and platform support), there's only one serious alternative: Emacs (which cannot only be turned into everything but a kitchen sink, but also into a modal editor, too).

这篇关于在 vim 中更改默认键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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