阻止 vim 删除空行上的缩进 [英] stopping vim from removing indentation on empty lines

查看:23
本文介绍了阻止 vim 删除空行上的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当光标放在一行的末尾时,只包含空格字符,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆