Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. set spellsuggest+=10
  2.  
  3. " Don't hijack the entire screen for spell checking, just show the top 9 results
  4. " in the commandline.
  5. " Press 0 for the full list. Any key press that's not a valid option (1-9) will
  6. " behave as normal.
  7. fun! QuickSpell()
  8. if &spell is 0
  9. echohl Error | echo "Spell checking not enabled" | echohl None
  10. return
  11. endif
  12.  
  13. " Separator between items.
  14. let l:sep = ' | '
  15.  
  16. " Show as many columns as will fit in the window.
  17. let l:sug = spellsuggest(expand('<cword>'), 9)
  18. let l:c = 0
  19. for l:i in range(0, len(l:sug))
  20. let l:c += len(l:sug[l:i - 1]) + len(printf('%d ', l:i + 1))
  21. if l:c + (len(l:sep) * l:i) >= &columns
  22. break
  23. endif
  24. endfor
  25.  
  26. " Show options; make it stand out a bit.
  27. echohl QuickFixLine
  28. echo join(map(l:sug[:l:i - 1], {i, v -> printf('%d %s', l:i+1, l:v)}), l:sep)
  29. echohl None
  30.  
  31. " Get answer.
  32. let l:char = nr2char(getchar())
  33.  
  34. " Display regular spell screen on 0.
  35. if l:char is# '0'
  36. normal! z=
  37. return
  38. endif
  39.  
  40. let l:n = str2nr(l:char)
  41.  
  42. " Feed the character if it's not a number, so it's easier to do e.g. "ciw".
  43. if l:n is 0 || l:n > len(l:sug)
  44. return feedkeys(l:char)
  45. endif
  46.  
  47. " Replace!
  48. exe printf("normal! ciw%s<Esc>", l:sug[l:n-1])
  49. echo
  50. endfun
  51. nnoremap z= :call QuickSpell()<CR>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement