I know I can write a buffer to an external program with :w !<command>, but is there a way to pipe the contents of the spelling correction list I get with z= into an external program (i.e. dmenu)? If the function(s) behind z= are written in vimscript, can I modify them or is it hard coded ?

2 Answers 2


I don't have dmenu installed, but I tried with zenity:

:echo system("zenity --list --column=Suggestions 2>/dev/null", spellsuggest(expand("<cword>")))
  • expand("<cword>") expands to the word under the cursor.
  • spellsuggest(...) returns a list of spelling suggestions
  • system("zenity...", ...) calls zenity and pipes the the list from spellsuggest(...) as input.

If I then select one of the suggestions, it is echoed by Vim.

See the help for spellsuggest (:h spellsuggest()), as it can take additional parameters.

  • Using this I get a list but can this replace the word?
    – Galilean
    Commented May 16, 2019 at 5:43
  • @Galilean Well, that was not the question :-). You would need additional scripting. Or maybe another question.
    – Ralf
    Commented May 16, 2019 at 6:35

My solution (as per the answer @Ralf gave) is this:

" Dmenu integration for searching spelling correction. Replaces `z=`.
function DmenuCorrect()
    let word=system("$HOME/.bin/dmenuw -i -l 8 2>/dev/null", spellsuggest(expand("<cword>")))
    if len(word) != 0 
        exe "normal ciw". word[0:-2]
nnoremap <silent>z= :call DmenuCorrect()<Cr>

Replacing the word under the cursor is done with exe "normal ciw" . word [0:-2]. ciw puts vim into replace mode within the current word boundaries. word [0:-2] is just to account for the newline dmenu prints, and inserts the chosen solution into the buffer in place of the now deleted misspelt word.

Your Answer

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

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