Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

stopping vim from removing indentation on empty lines

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Vim wiki suggests this:

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.

[EDIT - milimetric]

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>

Same idea but people newer to vim might not figure it out quickly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...