阻止vim删除空行上的缩进 [英] stopping vim from removing indentation on empty lines
问题描述
当光标放在带有空格字符的一行的末尾时,当我按Enter键时,vim将删除该空格.我觉得这很烦人,因为它破坏了我选择缩进相同级别代码的脚本.如何防止vim执行此操作?
When the cursor is placed at the end of a line containing nothing but withspace characters, vim will, when i press enter, remove that whitespace. I find this irritating, as it breaks my script for selecting code that are indented to the same level. How can I prevent vim from doing this?
在我的.vimrc( http://bjuhn.com/randomstuff/vimrc )中,我有以下内容:
In my .vimrc (http://bjuhn.com/randomstuff/vimrc) I have the following:
filetype plugin on
set copyindent
也就是说,我没有使用任何可识别语法的自动缩进,因为我还没有找到可以自动完成所有功能的缩进.
that is, I am not using any syntax-aware auto-indention, as I have yet to find one that does everything to my liking.
推荐答案
Vim Wiki 建议这个:
inoremap <CR> <CR>x<BS>
因为即使在行中输入了一些文本,即使删除了缩进,也不会删除缩进.
because the indenting is not removed if some text has been entered on the line, even if it has been deleted.
完整解决方案中仅缺少几处.您还需要重新映射o和O以及用于添加线的其他任何内容:
Just a couple of pieces missing from a full solution. You also need remaps for o and O and whatever else you use to add lines:
inoremap <CR> <CR>x<BS>
nnoremap o ox<BS>
nnoremap O Ox<BS>
相同的想法,但是刚接触vim的人可能不会很快发现它.
Same idea but people newer to vim might not figure it out quickly.
这篇关于阻止vim删除空行上的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!