6

If I type z= on a spelling suggestion it uses the entire screen. Is there any way to disable that?

1 Answer 1

10

There is the 'spellsuggest' option for this, which controls various options for the spelling suggestion. You can add a limit by appending a number (note the +=):

set spellsuggest+=10

Which limits the height of the spell window to ten lines.

It looks like this feature has always been present; I just never knew.


Another option I've been using for the last week is the below script; it will display suggestions in the commandline window, and just pressing a number (1-9) will replace the word while pressing 0 will load original z= screen. Any other keys will be sent to Vim as normal, making it pretty easy to abort the search by just entering Vim commands.

" Don't hijack the entire screen for spell checking, just show the top 9 results
" in the commandline.
" Press 0 for the full list. Any key press that's not a valid option (1-9) will
" behave as normal.
fun! QuickSpell()
    if &spell is 0
        echohl Error | echo "Spell checking not enabled" | echohl None
        return
    endif

    " Separator between items.
    let l:sep = ' | '

    " Show as many columns as will fit in the window.
    let l:sug = spellsuggest(expand('<cword>'), 9)
    let l:c = 0
    for l:i in range(0, len(l:sug))
        let l:c += len(l:sug[l:i - 1]) + len(printf('%d ', l:i + 1))
        " The -5 is needed to prevent some hit-enter prompts, even when there is
        " enough space (bug?)
        if l:c + (len(l:sep) * l:i) >= &columns - 5
            break
        endif
    endfor

    " Show options; make it stand out a bit.
    echohl QuickFixLine
    echo join(map(l:sug[:l:i - 1], {i, v -> printf('%d %s', l:i+1, l:v)}), l:sep)
    echohl None

    " Get answer.
    let l:char = nr2char(getchar())

    " Display regular spell screen on 0.
    if l:char is# '0'
        normal! z=
        return
    endif

    let l:n = str2nr(l:char)

    " Feed the character if it's not a number, so it's easier to do e.g. "ciw".
    if l:n is 0 || l:n > len(l:sug)
        return feedkeys(l:char)
    endif

    " Replace!
    exe printf("normal! ciw%s\<Esc>", l:sug[l:n-1])
    echo
endfun
nnoremap z= :call QuickSpell()<CR>
2
  • 1
    Another option is to use <c-x>s in insert mode to bring up spelling suggestions. It will probably take up the whole screen, but I find insert mode completion to be less jarring than z=. Apr 22, 2019 at 19:22
  • Sounds like that could be posted as an answer @PeterRincker (personally I've never liked using completion for spell checking because it removes the word on the first <C-x>s) Apr 23, 2019 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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