Skip to content
Advertisement

How to make z= look like ctrl-x s in vim spell check

So in insert mode if you hit ctrlx s on a misspelled word you get a nicely formatted popup menu of spelling suggestions. This is awesome.

The comparable command in normal mode (z=), however, gives a bland plain-text list that eats the whole screen.

I’ve partially solved this by adding the following keybinding in my .vimrc:

nnoremap <Leader>s ea<C-X><C-S>

This works perfectly and hitting s in normal mode gives me the same drop down… The only problem is I’m now left in insert mode at the end of everything. Is there some way to get the drop down style selection and end up in normal mode after the replace is all said and done?

Advertisement

Answer

You can’t do it directly. The popup menu you’re thinking of is specifically referred to as “insert mode completion”.

However, you’re halfway there, by mapping a key that enters insert mode and starts the completion. Now all you need is to map a key that selects the entry (like the ‘enter’ key) to also exit insert mode.

You should test the return value of pumvisible() in your mapping, to prevent it firing when you don’t want. Example (from comments):

inoremap <expr> <CR> pumvisible() ? "<C-y><Esc>" : "<CR>"

Perhaps you could also set a variable or something, or use a key you won’t use to end actual insert mode completion.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement