如果只有空格,vim 中的自动缩进总是清空该行,我可以更改吗? [英] Autoindent in vim always empty the line if there are only whitespace in it, can I change that?
问题描述
例如我通常先输入大括号,然后在块内移动光标,我期望应该是这样的:
For example I usually type paired braces first then move the cursor inside the block, what I expect should be like this:
....{
....█
....}
但是vim会自动清空第二行,因为里面只有空格字符,所以出来的结果是这样的:
But vim automatically empty the second line since there are only whitespace characters in it, so the result coming out is like this:
....{
█
....}
我该如何解决这个问题?
How do I fix this?
(点是空格字符,█ 表示我的光标位置.)
(The dots are for space characters, and █ shows the location of my cursor.)
推荐答案
不要担心 Vim 会在您离开插入模式时从原本为空的行中去除空格这一事实.正如这里的其他人所评论的那样,这是一件好事.相反,当您在该行调用插入模式时,寻找一种方法来自动恢复缩进级别.
Don't worry about the fact that Vim strips spaces from an otherwise empty line when you leave insert mode. As others here have commented, this is a good thing. Instead, look for a way to automatically restore the indentation level when you invoke insert mode on that line.
i
、I
、a
和 A
命令都在插入时保留光标位置模式.但是请查看 :help cc
的文档:
The i
, I
, a
and A
commands all preserve the cursor position when putting you into insert mode. But check the documentation for :help cc
:
["x]cc Delete [count] lines [into register x] and start
insert linewise. If 'autoindent' is on, preserve
the indent of the first line.
如果 autoindent
选项打开,那么在空白行上运行 cc
将切换到插入模式并恢复适当的缩进级别,就像你一样设置你想要:
If the autoindent
option is on, then running cc
on the blank line will switch to insert mode and restore the appropriate level of indentation, setting you up just as you want:
....{
|
....}
注意 S
键是 cc
的同义词 (:help S
).
Note that the S
key is a synonym for cc
(:help S
).
这篇关于如果只有空格,vim 中的自动缩进总是清空该行,我可以更改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!