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

发布于 2024-08-14 04:52:02 字数 213 浏览 8 评论 0原文

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

map X ddp

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

map X "_dw

这将删除一个单词而不用拉入寄存器。

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

I'm trying to create two mappings which are efficient for myself:

map X ddp

Which I'd use to delete and paste in one go.

map X "_dw

Which would delete a word without yanking into a register.

However I don't want to break any existing, useful shortcuts so I'm wondering what keys I could use - any suggestions? Am I being too uptidy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

放肆 2024-08-21 04:52:02

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).

vim help has a section :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).
不如归去 2024-08-21 04:52:02

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

                                        *<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.

Many Vim plugins use an initial <Leader> to start their key sequences; this is an (otherwise normally) unused key that is configurable by the user.

                                        *<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.
人海汹涌 2024-08-21 04:52:02

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

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

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

Every single ASCII character, upper and lower case, is used for something in Vim. So you're going to wind up overwriting something--just pick something that you don't use. It may help to use a common idiom for your own extensions. I use a leading comma, for example:

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

(The last is particularly useful for me, since I pretty much never need to write two consecutive commas in insert mode, and it's nice not to have to go all the way to the Esc key.)

梦里梦着梦中梦 2024-08-21 04:52:02

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

Typically I use control + [letter] or alt + [letter] for most mappings and it's safe, but watch out for 'w' since that's needed for window commands. You might also be interested in arpeggio.vim which lets you create mappings to simultaneously pressed groups of keys - it will massively expand the possibilities for your mappings with no danger of over-mapping something. For example, you could map "dp" (pressed simultaneously) to execute "ddp" to delete and paste in one command.

留蓝 2024-08-21 04:52:02

嗯,不,不要。创建映射时,尽量不要覆盖任何内容……不是因为您没有使用您要过度映射的命令,而是因为您拥有/或将拥有的某些插件可能会使用它。

然后你过度映射它,然后你就不得不担心了。

就我个人而言,对于诸如您给出的示例之类的命令,我喜欢 Ctrl+一些组合键。 vim 中有很多免费的字母,那么左侧靠近 Ctrl 的字母就成了很好的一对。

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

Uhmm, no, don't. When creating your mappings try not to overwrite anything ... not so much because you don't use the command you're overmapping, but because some plugin which you have/or will have maybe using it.

And then you overmap it, and then you have to worry.

Personally, for commands such as you gave as an example, I like Ctrl+some key combinations. There are a lot of free ones in vim, and the letters on the left side near Ctrl make a nice pair then.

Btw, what are you trying to do with those mappings ... I understand the second one (delete word by word), but the first doesn't make sense to me. What is it supposed to do ? Transpose lines ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文