0

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

1

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.

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

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]
    endif
endfunction
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.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .