22

我正在尝试创建两个对自己有效的映射:

map X ddp

我会用它来一次性删除和粘贴。

map X "_dw

这将删除一个单词而无需拉入寄存器。

但是我不想破坏任何现有的、有用的快捷方式,所以我想知道我可以使用哪些键 - 有什么建议吗?我是不是太讲究了?

4

5 回答 5

22

vim 帮助有一个部分:he map-which-keys

1.7 WHAT KEYS TO MAP                                    *map-which-keys*

If you are going to map something, you will need to choose which key(s) to use
for the {lhs}.  You will have to avoid keys that are used for Vim commands,
otherwise you would not be able to use those commands anymore.  Here are a few
suggestions:
- Function keys <F2>, <F3>, etc..  Also the shifted function keys <S-F1>,
  <S-F2>, etc.  Note that <F1> is already used for the help command.
- Meta-keys (with the ALT key pressed). |:map-alt-keys|
- Use the '_' or ',' character and then any other character.  The "_" and ","
  commands do exist in Vim (see |_| and |,|), but you probably never use them.
- Use a key that is a synonym for another command.  For example: CTRL-P and
  CTRL-N.  Use an extra character to allow more mappings.

See the file "index" for keys that are not used and thus can be mapped without
losing any builtin function.  You can also use ":help {key}^D" to find out if
a key is used for some command.  ({key} is the specific key you want to find
out about, ^D is CTRL-D).
于 2009-12-11T23:48:31.270 回答
13

许多 Vim 插件使用首字母<Leader>来开始其按键序列;这是用户可配置的(通常情况下)未使用的密钥。

                                        *<Leader>*  *mapleader*
要定义使用“ mapleader ”变量的映射,特殊字符串可以使用
“ <Leader> ”。它被替换为“ mapleader ”的字符串值。
如果“ mapleader ”未设置或为空,则使用反斜杠。例子:
        :map <Leader>另一条线<Esc>
像这样工作:
        :map \A oanother line<Esc>
但是之后:
        :let mapleader = ","
它的工作原理如下:
        :map ,另一行<Esc>

请注意,“ mapleader ”的值是在映射时使用的
定义。之后更改“ mapleader ”对已经定义的没有影响
映射。
于 2009-12-12T15:43:33.137 回答
10

在 Vim 中,每个 ASCII 字符(大写和小写)都用于表示某些内容。所以你最终会覆盖一些东西——只选择你不使用的东西。为您自己的扩展使用常见的习惯用法可能会有所帮助。我使用前导逗号,例如:

map ,w :w!<CR>
map ,e :e #<CR>
imap ,, <ESC>

(最后一个对我来说特别有用,因为我几乎不需要在插入模式下写两个连续的逗号,而且不用一直到 Esc 键也很好。)

于 2009-12-11T17:40:41.690 回答
5

通常我对大多数映射使用 control + [letter] 或 alt + [letter] 并且它是安全的,但要注意“w”,因为它是窗口命令所必需的。您可能还对arpeggio.vim感兴趣,它可以让您创建映射到同时按下的键组 - 它会极大地扩展映射的可能性,而不会出现过度映射的危险。例如,您可以映射“dp”(同时按下)以执行“ddp”以删除和粘贴一个命令。

于 2009-12-12T16:36:53.493 回答
2

嗯,不,不要。创建映射时尽量不要覆盖任何东西......不是因为你不使用你正在过度映射的命令,而是因为你拥有/或将拥有的某些插件可能会使用它。

然后你覆盖它,然后你不得不担心。

就个人而言,对于您作为示例给出的命令,我喜欢 Ctrl+一些组合键。vim 中有很多免费的,而左侧靠近 Ctrl 的字母是一对不错的组合。

顺便说一句,你想用这些映射做什么......我理解第二个(逐字删除),但第一个对我来说没有意义。它应该做什么?转置线?

于 2009-12-12T00:10:14.480 回答