This vim binding will make <C-l>
correct the previous spelling mistake:
inoremap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u
How do I modify it to make it correct the previous mistake on the current line only?
inoremap <C-l> <c-g>u<Esc>:call <sid>fixLineSpellError()<cr>`]a<c-g>u
function! s:fixLineSpellError()
" get current line number
let lnum = line('.')
" find last misspelled word before cursor
normal! [s
" do nothing if line changed
if lnum != line('.') | return | endif
" fix spell error if line doesn't change
normal! 1z=
endfunction
Map break down:
<c-g>u<Esc>
break undo sequence, switch to normal mode.:call <sid>fixLineSpellError()<cr>
call a script scope function to fix current line spell error.`]a
move cursor back to the end of last change, start to append.<c-g>u
break undo sequence.