Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active January 25, 2026 13:24
Show Gist options
  • Select an option

  • Save Konfekt/9f141a8e21a864d43181dbb712b4ea90 to your computer and use it in GitHub Desktop.

Select an option

Save Konfekt/9f141a8e21a864d43181dbb712b4ea90 to your computer and use it in GitHub Desktop.
fix last spelling mistake by Ctrl-Q; jump to it by Ctrl-X,Q
nnoremap <silent><expr> <plug>(FixLastBadSpell) $"\<Cmd>call <SID>FixLastBadSpell()\<CR>"
nnoremap <silent><expr> <C-q> &l:spell ? "\<plug>(FixLastBadSpell)" : "<C-q>"
inoremap <silent><expr> <plug>(FixLastBadSpell) $"\<Cmd>call <SID>FixLastBadSpell()\<CR>"
inoremap <silent><expr> <C-q> &l:spell ? "\<plug>(FixLastBadSpell)" : "<C-q>"
function! s:FixLastBadSpell() abort
" Save current position to return to later.
let last_changedtick = b:changedtick
let last_line_length = len(getline('.'))
let position = getpos('.')[1:3]
silent! execute $"keepjumps normal! {v:count1}[s1z="
" Restore position.
if line('.') == position[0]
let new_line_length = len(getline('.'))
let offset = new_line_length - last_line_length
let position[1] = max( [ position[1] + offset, 0] )
endif
keepjumps call cursor(position)
if b:changedtick > last_changedtick
silent! call repeat#set("\<plug>(FixLastBadSpell)", v:count1)
endif
endfunction
inoremap <silent><expr> <plug>(JumpLastBadSpell) $"\<Cmd>call <SID>JumpLastBadSpell()\<CR>"
inoremap <silent><expr> <C-x><C-q> &l:spell ? "\<plug>(JumpLastBadSpell)" : "<C-x><C-q>"
function! s:JumpLastBadSpell() abort
" Move to previous misspelling.
silent! execute $"keepjumps normal! [se"
" open the completion menu for spelling suggestions
startinsert
call feedkeys("\<C-x>\<C-s>", 'n')
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment