Tip 522 Printable Monobook Previous Next
created 2003 · complexity basic · author Breadman · version 5.7
When splitting a line in two, I sometimes insert a return before a space. Unfortunately, this mangles the autoindentation: the last tab turns into spaces. The following map fixes that problem:
"Fixes a rare autoindent error
inoremap <CR> <C-R>=ReturnWrapper()<CR>
function ReturnWrapper()
if strpart(getline('.'), col('.') - 1) =~ '^\s*\S'
return "\<Esc>wi\<CR>"
else
return "\<CR>"
endif
endf