Wikia

Vim Tips Wiki

Fix an autoindent error

Talk0
1,610pages on
this wiki
Revision as of 08:52, September 29, 2008 by JohnBot (Talk | contribs)

Tip 522 Printable Monobook Previous Next

created July 31, 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

Comments

Around Wikia's network

Random Wiki