stopping vim from removing indentation on empty lines

让人想犯罪 __ 提交于 2019-12-17 16:06:43

问题


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.


回答1:


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.




回答2:


For me this code works:

inoremap <silent> <Esc> <C-O>:stopinsert<CR>


来源:https://stackoverflow.com/questions/7413036/stopping-vim-from-removing-indentation-on-empty-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!