如何更快地纠正 Vim 拼写错误?
我通常的 Vim 工作流程是:
在插入模式下,拼写错误。
按
^X s
获取一些建议。按 Esc 接受第一个。
之后,我处于行中间的命令模式,而不是之前的插入模式。我可以使用 A
,但只有当我在行尾键入时才有效。还有其他方法吗?最理想的是,我想要一个命令,可以在不移动光标的情况下将最后一个错误纠正为第一个建议。
My usual Vim work flow is:
In insert mode, spell something wrong.
Press
^X s
to get some suggestions.Press Esc to accept the first one.
After this, I'm in command mode in the middle of the line, instead of insert mode of where I was before. I could use A
, but that only works if I was typing on the end of the line. Is there an alternative way? Optimally, I'd like a command that corrects the last mistake to the first suggestion without moving the cursor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
对 PDug 答案的改进:要使拼写更正与插入分开可撤消,请使用以下命令:
u
inserts an undo-break其余的都是一样的。
这样,如果您不喜欢所选的更正,可以使用
u
撤消它。如果没有撤消中断,这将撤消整个插入。请注意,映射末尾的撤消中断可确保在更正后添加的文本可以与更正本身分开撤消。另外,我发现在插入和正常模式下将其映射到 CTRL+F (很容易到达)很方便,如下所示:
这样,您可以快速修复最后一个错误(相对于光标)。
An improvement to PDug's answer: To make the spelling correction undoable separately from the insertions, use this:
<c-g>u
inserts an undo-breakThe rest is the same.
This way, if you don't like the chosen correction, you can undo it using
<Esc>u
. Without the undo-breaks, this would undo the complete insertion. Note that the undo-break at the end of the mapping ensures that text added after the correction can be undone separately from the correction itself.Also, I found it convenient to map this to CTRL+F (which is easy to reach) in both insert and normal mode like this:
This way, you can quickly fix the last error (relative to the cursor).
这效果相当好:
[s
移动到最后一个拼写错误1z=
选择第一个建议`]
移动到最后一个插入点a
附加文本This works fairly well:
[s
moves to the last spelling mistake1z=
chooses the first suggestion`]
move to the last insert pointa
append text我无法提供“最佳”解决方案(尽管我怀疑有办法)。
但是,您可以使用 gi 在文件中上次留下的位置进入插入模式。 (
help gi
更雄辩地解释了这一点)。I can't offer an 'optimal' solution (although I suspect there is a way).
However, you can use gi to enter insert mode at the place in the file where you last left it. (
help gi
explains this more eloquently).我通过
.vimrc
中的以下重新映射修复了它。在插入模式下按 F2 可更正上一个错误并返回到原来的插入模式。它会覆盖
t
标记。I fixed it with the following remap in my
.vimrc
.Press F2 in insert mode to correct the last mistake and go back to insert mode where you were. It overwrites the
t
marker.您可以使用 Ctrl + Y 接受弹出菜单中的元素。请参阅
:helpcomplete_CTRL-Y
。You can use Ctrl + Y to accept an element in a popup menu. See
:help complete_CTRL-Y
.我专门为此用例创建了一个插件 https://github.com/arecarn/vim-spell -utils
它提供插入模式映射 CTRL-A,它完全按照要求执行操作,并使用第一个建议更正最后一个拼写错误,然后返回到上次离开的插入模式。它还会考虑由于拼写更正而导致的行长度变化,而 gi 和 `] 则不会。
I created a plugin just for this use case https://github.com/arecarn/vim-spell-utils
It provides the insert mode mapping CTRL-A that does exactly what was asked and corrects last misspelling with 1st suggestion then returns to insert mode where you you last left off. It also accounts for changes to the line lengths due to spelling corrections while gi and `] do not.
您可以按
]s
和[s
在缓冲区中向前和向后循环拼写错误的单词。如果您在正常模式下遇到拼写错误的单词,可以按z=
查看拼写建议列表。zonker 在 linux.com
You can press
]s
and[s
to cycle forward and back misspelled words in a buffer. If you are over a misspelled word in normal mode, you can pressz=
to see a list of spelling suggestions.answer suggested by zonker on linux.com