VIM:可映射(未使用)的快捷方式字母?

时间:2009-12-11 17:29:06

标签: vim shortcuts

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

map X ddp

我将其用于一次删除和粘贴。

map X "_dw

哪会删除一个单词而不会进入寄存器。

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

5 个答案:

答案 0 :(得分:19)

vim help有一个部分: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).

答案 1 :(得分:13)

许多Vim插件使用初始<Leader>来启动其键序列;这是一个(通常是)通常未使用的密钥,可由用户配置。

                                        *<Leader>* *mapleader*
To define a mapping which uses the "mapleader" variable, the special string
"<Leader>" can be used.  It is replaced with the string value of "mapleader".
If "mapleader" is not set or empty, a backslash is used instead.  Example:
        :map <Leader>A  oanother line<Esc>
Works like:
        :map \A  oanother line<Esc>
But after:
        :let mapleader = ","
It works like:
        :map ,A  oanother line<Esc>

Note that the value of "mapleader" is used at the moment the mapping is
defined.  Changing "mapleader" after that has no effect for already defined
mappings.

答案 2 :(得分:10)

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

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

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

答案 3 :(得分:5)

通常我对大多数映射使用control + [letter]或alt + [letter]并且它是安全的,但要小心'w',因为窗口命令需要它。您可能也对arpeggio.vim感兴趣,它允许您为同时按下的键组创建映射 - 它将大量扩展映射的可能性,而不会有过度映射的危险。例如,您可以映射“dp”(同时按下)执行“ddp”以删除并粘贴一个命令。

答案 4 :(得分:2)

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

然后你覆盖它,然后你必须担心。

就个人而言,就你所提供的命令而言,我喜欢Ctrl +一些键组合。 vim中有很多免费的,而Ctrl附近左侧的字母则是一对很好的。

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