So in insert mode if you hit ctrl-x 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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With