简体   繁体   English

学习vim时有哪些方法可以减少模式错误?

[英]What are ways to reduce mode errors while learning vim?

I frequently make mode errors while using vim, ie I'll start typing text while in Normal mode, or start typing commands while in Insert mode. 我经常在使用vim时出现模式错误,即我将在正常模式下开始键入文本,或者在插入模式下开始键入命令。 I understand this goes away with time as vim's quirks seep into your bones, but are there any ways to speed the process? 我明白,随着时间的推移,随着时间的推移,vim的怪癖会渗入你的骨头,但有没有办法加快这个过程?

I use these autocmd's to highlight the entire line containing the cursor while in insert mode, and not while in normal mode: 在插入模式下,我使用这些autocmd来突出显示包含光标的整行,而不是在正常模式下:

if v:version >= 700
  autocmd InsertEnter * set cursorline
  autocmd InsertLeave * set nocursorline
endif

This provides a little bit more visual feedback about the mode. 这提供了关于模式的更多视觉反馈。

If you haven't done so already you can display the current mode by using :set showmode . 如果尚未执行此操作,则可以使用:set showmode显示当前模式:set showmode That'll display -- INSERT -- in the status bar when in insert mode. 在插入模式下,状态栏中会显示-- INSERT --

尽量记住始终将vim置于正常模式。

Switch "Esc" and "Caps Lock" keys. 切换“Esc”和“Caps Lock”键。

If you accidentally click on "Caps Lock" you will start inputing commands that has nothing to do with what you like to do. 如果您不小心点击“大写锁定”,您将开始输入与您喜欢的操作无关的命令。 It is annoying if you are an experienced user; 如果您是一位经验丰富的用户,这很烦人; if you are a beginner it may be a hassle to understand what went wrong. 如果你是初学者,那么理解出了什么问题可能会很麻烦。

Every time you need to press the Esc key you have to move you entire hand and to get your pinky finger to touch the Esc key and then replace the entire hand again. 每当你需要按Esc键时,你必须移动整个手,让你的小手指触摸Esc键,然后再次更换整个手。 Some Vim users will tell you that after a while you get used to doing that and it is not a big deal. 一些Vim用户会告诉你,过了一段时间你就习惯了这样做,这不是什么大问题。 I think that argument falls short because you can pretty much get used to mapping any key any where. 我认为这个论点不足,因为你几乎可以习惯在任何地方映射任何键。 It is a matter of efficiency. 这是一个效率问题。

I believe "Esc" is used very frequently and "Caps Lock" is used seldomly if it is used at all. 我相信“Esc”经常被使用,如果它被使用,很少使用“Caps Lock”。

So switching the two makes sense as it prevents errors and increases typing speed. 因此,切换两者是有意义的,因为它可以防止错误并提高打字速度。

With gvim, the cursor changes from a block to a vertical bar when going between modes. 使用gvim,当在模式之间移动时,光标从块变为垂直条。 This at least gives you a little visual feedback. 这至少给你一点视觉反馈。

Insert mode should only be temporary. 插入模式应该只是临时的。 Normal mode is, as its name tells, the favourite mode for edition tasks. 正如其名称所示,正常模式是编辑任务的最爱模式。

Usually, you should spend more time in normal mode, and always hit ESC when you are done inserting something. 通常,您应该在正常模式下花费更多时间,并在插入内容时始终按ESC。

Maybe I speak only for myself, but now I have the habit of assuming that I am in normal mode at all times, and I am almost never wrong. 也许我只为自己说话,但现在我习惯于假设我一直处于正常模式,而且我几乎从不错。

Here is my variant of Ned's Answer. 这是我对Ned的答案的变种。 It toggles on window switches (window focus is another modal behavior that provides little visual feedback). 它在窗口开关上切换(窗口焦点是另一种提供很少视觉反馈的模态行为)。

if v:version >= 700
    set cursorline cursorcolumn
    au WinLeave * set nocursorline nocursorcolumn
    au WinEnter * set cursorline cursorcolumn
    au InsertEnter * set nocursorline nocursorcolumn
    au InsertLeave * set cursorline cursorcolumn
endif

I use it with the zenburn color scheme, and I also turn off cursor blink: 我使用它与zenburn颜色方案,我也关闭光标闪烁:

if has("gui_running")
    colorscheme zenburn
    set guicursor+=a:blinkon0
endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM