不离开主行返回正常模式

发布于 2024-10-15 07:44:19 字数 588 浏览 6 评论 0原文

我一直在尝试 vim,对于经验丰富的程序员来说,强调速度和可访问性是有意义的。我以前使用过 emacs,目前使用 nano,以及诸如 之类的东西geditgeany

我对不断切换模式的需要感到困惑,并且从插入模式返回到正常模式需要离开主行按 Esc。我之前读过,在一些首次使用 vim 的系统上,这个键是 Tab ,这更有意义,但在当前的系统上,在编码时 tab 预计参与智能缩进,则不是这样。

返回正常模式是您始终需要执行的操作。是否有一些替代键映射可以使此操作更快,或者我根本不知道可以执行此操作的映射?

I've been trying out vim, and the emphasis on speed and accessibility makes sense for the veteran programmer. I've previously used emacs, and currently use a combination of nano, and stuff like gedit or geany.

I'm confused by the need to constantly switch modes, and that returning from insert mode to normal mode requires leaving the home row to press Esc. I've read that previously, this key was Tab on some systems where vim was first used, which makes a lot more sense, but not on current systems where tab is expected to participate in smart indenting when coding.

Returning to normal mode is an operation that you need to perform all the time. Is there some alternative key mapping that makes this quicker, or mappings that I simply don't know about that do this?

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

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

发布评论

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

评论(7

街角迷惘 2024-10-22 07:44:19

Ctrl+C 也可让您返回正常模式

Ctrl+C also return you to normal mode

甜点 2024-10-22 07:44:19

您也可以使用 ^[。如果您已将大写锁定键映射到控制(强烈推荐),那么这将变得相当简单。

You can also use ^[. If you've mapped your caps lock key to control (highly recommended), this becomes a rather easy keystroke.

花开柳相依 2024-10-22 07:44:19

你可以映射任何你想转义的内容:

imap kj <Esc>

除了当我谈论这个映射时之外,我还没有遇到过需要在彼此旁边键入 kj 的情况。我见过其他人使用 jk 或 jj,但 kj 最适合我。

You can map whatever you like to escape:

imap kj <Esc>

I haven't yet run across a situation where I need to type kj next to each other, besides when I talk about this mapping. I've seen other people use jk or jj, but kj works best for me.

天赋异禀 2024-10-22 07:44:19

我个人使用Capslock键作为第二个Esc键,所以非常舒服。您可以通过将以下行添加到 .xmodmap 文件中来完成此操作:

remove Lock = Caps_Lock
keysym Caps_Lock = Escape

I personally use the Capslock key as the second Esc key, so it is very comfortable. You can do it by adding the following lines to your .xmodmap file:

remove Lock = Caps_Lock
keysym Caps_Lock = Escape
甜尕妞 2024-10-22 07:44:19

我个人使用 ii 退出插入模式,同时停留在主行,但这只是个人喜好的问题:

inoremap ii

i 进入插入ii 进入退出。这对于您的手指来说很容易记住。 (不过我仍然倾向于使用

I personally use ii to get out of insert mode while staying on the home row, but it is only a matter of personal preference:

inoremap ii <Esc>

i to go in insert and ii to go out. This is easy for your finger to remember. (I tend to still use <Esc> though)

別甾虛僞 2024-10-22 07:44:19

我个人使用 Left Control 作为转义键,使用 Caps Lock 作为 Left Control。它不是 vim 映射,而是

! ~/.Xmodmap
! Control_R
keycode 37 = Escape

X 键盘选项中的 xmodmap+setxkbmap magic: 和 ctrl:nocaps 。不过,您可能有不同的密钥代码。

I personally use Left Control as escape and Caps Lock as Left Control. It is not vim mapping, but some xmodmap+setxkbmap magic:

! ~/.Xmodmap
! Control_R
keycode 37 = Escape

and ctrl:nocaps in X keyboard options. You may have different keycode though.

征棹 2024-10-22 07:44:19

在终端中使用 Alt/Meta

如果您在终端中使用 Vim,只需按 alt/meta+normal_mode_key 即可。大多数终端都会发送一个转义字符,后跟您按下的 normal_mode_key,从而无需自己按转义键。

当您按 alt/meta+normal_mode_key 时,终端 konsole 和 gnome 终端默认发送转义字符。对于 Xterm,您可以按住 Ctrl 键并单击并选择“Meta 发送转义”或“Alt 发送转义”选项。

因此,在插入模式下,按 alt+h alt+j alt+k alt+l 都会带您进入正常模式并按预期方向移动。即使在正常模式下,您也可以在移动时按住 Alt,因为发送的额外 ESC 不会造成任何损害。

使用此方案的优点是您可以将 alt/meta+key 组合与任何普通模式键一起使用,例如

Alt+o opens a new line below the one you are currently editing,
Alt+A appends to the end of the current line,
Alt+p pastes at the current insert location.
Alt+k moves up 

因此,通过终端使用 vim 可以让您在任何库存标准系统上获得这些快捷方式,而无需编辑每个系统的 vim 映射。

Use Alt/Meta In a Terminal

If you use Vim in a terminal, simply press alt/meta+normal_mode_key. Most terminals send an escape character followed by the normal_mode_key that you pressed, removing the need to press escape yourself.

The terminals konsole and gnome terminal send the escape by default when you press alt/meta+normal_mode_key. For Xterm you can ctrl+click and select the option "Meta sends escape" or "Alt sends escape".

Thus in insert mode pressing alt+h alt+j alt+k alt+l all take you to normal mode and move in the expected direction. You can hold down alt when moving even while in normal mode since the additional ESC that is sent does no harm.

The advantage of using this scheme is that you can use the alt/meta+key combination with any normal mode key, e.g.

Alt+o opens a new line below the one you are currently editing,
Alt+A appends to the end of the current line,
Alt+p pastes at the current insert location.
Alt+k moves up 

Thus using vim via a terminal gives you these short cut powers on any stock standard system without the need to edit each systems vim mappings.

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