I am using vim as a note-taking app.

Following an earlier answer here , I have the following mappings which allow me to quickly correct earlier spelling mistakes:

" spelling

imap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u
nmap <C-l> [s1z=<c-o>

This works really well, however sometimes my notes contains acronyms etc which are marked as spelling mistakes but are not, and would ideally be skipped

Is there a way of modifying the command to tell vim : "skip the first n spelling mistakes , counting backwards from here" , eg by typing something like 2<C-L> to correct only from the 2nd spelling mistake backwards (ie skipping the first one). I would then hope to be able to repeat that command to continue correcting from there on.

Currently I move the cursor to just before where I want the correction to apply, but maybe there is a better way.

  • It's possible to come up with a (complicated) mapping to take care of the nth previous spelling mistake... But is that really a good idea? The <C-L> mapping is a nice shortcut to quickly fix the last one as you notice it... But beyond that, doesn't that justify actually going back to Normal mode, moving to the one you want to fix, fixing it and then going back to insertion? Yeah that's quite a few keystrokes, but it should be rare enough that you don't need to resort to it that often... – filbranden Jan 4 at 17:47
  • 1
    What @filbranden is describing is basically inoremap <C-L> <C-g>u<Esc>:execute 'normal!' v:count1."[s"<CR>1z=`]a<C-g>u, maybe? EDIT that won't work becuase insert-mode maps can't get counts… – D. Ben Knoble Jan 4 at 19:56
  • @Ben Yeah that's why it gets complicated... It would actually need to be something that looks for numbers inserted right before the cursor, parses them, then erases them and does the count."[s" part... Not only it's pretty complicated to do right, it's also a somewhat clunky user interface. Which begs the question: Is it worth it? If you're doing this often, maybe you should update your dictionary? If you're not, then maybe switching to Normal mode isn't too bad? – filbranden Jan 4 at 21:07

You can use zg (or maybe zG) and zw (zW resp.) to mark words as good / wrong, so that Vim will highlight them or not. Maybe you just want to let Vim know that your acronyms are written correctly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.