4

I'm using vim to write some long text documents in French and in English.

I know how to enable spell check to check the words against a dictionary and verify than I don't misspell a word.

My question is: Is it possible to use Vim to check grammar and syntax error as an editor like LibreOffice Writer or Microsoft Word would do?

Verifications should include checks like conjugations or masculine/feminine singular/plural accords. And ideally some commands similar to spell check like ]s or z= should be available.

My searches often leads to programming language grammar check but not actual human languages. I have found this plugin which integrates languageTool into vim but it use an external tool and requires to use Java which is something that I would really like to avoid. I was wondering if there would be a tool using more built-in features to do that.

11
  • 2
    This seems great : afterthedeadline.com Do you think it could suits you needs ? There is a python cli program here : github.com/lpenz/atdtool
    – nobe4
    Commented Aug 18, 2015 at 15:06
  • I think you are bound to use an external tool. If you manage to make it work for you, LanguageTool could still be the solution.
    – VanLaser
    Commented Aug 18, 2015 at 16:04
  • Another plugin, based also on LanguageTool: github.com/rhysd/vim-grammarous
    – VanLaser
    Commented Aug 18, 2015 at 16:10
  • @VanLaser thanks for your plugin, the problem of LanguageTool is that it requires Java which is a really turn off for me. Also (excepted the probably huge amout of work it represent) what would be the limitations which would prevent someone to do a native grammar checker in Vim?
    – statox
    Commented Aug 18, 2015 at 16:13
  • 2
    @statox - "native" complicate stuff would better suit Emacs; with Vim, re-using external tools is usually the best approach. And Java is not necessarily evil (example: ditaa.sourceforge.net)
    – VanLaser
    Commented Aug 18, 2015 at 16:15

1 Answer 1

1

TL;DR

You'll have to rely on some external tool. So either build a wrapper that support multi-language or use an existing one that may not support multi language.

The problem

I think the main problem around multi-language syntax and grammar (iabbrev S/G syntax and grammar) correcting is that you always have to rely on some external tools that may not work for all languages. I'm thinking about afterthedeadline that has a convenient vim plugin but (from what I found) only correct english. So if you want only english, you can settle with this one but, as you specified, you want to correct french too (and maybe one day spanish or german, ... ). So a common multi-language S/G checker should achieve this.

The Research

We're on internet ! So you can find anything that can help you. And there are a LOT of S/G you can use freely. e.g.:

And one in particular: reverso.

I first used this website because as a non-english native I did a lot of translation from this site (where the quality of translation impressed me). And I just found out that they also so a syntax checker for English and French. So basically what you are searching for.

The Digging

To use this from Vim I wanted to have a curl-only interface with the website, so I started analysing the request to narrow my search to :

curl -X "POST" "http://www.reverso.net/spell-checker/french-spelling-grammar/SpellerRequests.aspx" \
    --data-urlencode "language=fr" \
    --data-urlencode "interfLang=en" \
    --data-urlencode "passPhrase=a long passphrase" \
    --data-urlencode "dictionary=both" \
    --data-urlencode "lang=en " \
    --data-urlencode "inputstring=Bnjour tout le monde"

And the result was:

 <CheckSpellingResult>
    <document xmlns="">
      <sentences nb="1">
        <sentence id="0" start="0" length="20" language="Fr">
          <inputText> Bnjour tout le monde</inputText>
          <errors nb="1">
            <error id="0" type="spell" substitution="" start="0" end="6" proba="100">
              <message> #!Bnjour#$ : mot inconnu de nos dictionnaires, il pourrait être remplacé par: #!Bonjour#$,#! BN jour#$.</message>
              <alternatives nb="3">
                <alternative id="0"> Bnjour</alternative>
                <alternative id="1"> Bonjour</alternative>
                <alternative id="2"> BN jour</alternative>
              </alternatives>
            </error>
          </errors>
        </sentence>
      </sentences>
    </document>
    <newPassPhrase> WQ+MApSbF9X29BEr7nyIBn6iQQa3MnBKS9KYc6QkhXU=</newPassPhrase>
    <textreplaced> Bnjour tout le monde</textreplaced>
    <noreplace> 0</noreplace>
  </CheckSpellingResult>

From this result you can parse the XML string and get the informations you want, building it in the quick fix list or trying to inject it in a plugin (syntastic for example).

Side Note : For this solution, you'll have to ask for the website 2 times : one for fetching the passphrase and the second for correcting your text. It's kind of hacky but it'll work.

The Conclusion

(spoiler alert : no script, just a general conclusion)

I think most of the tool you can use to check you grammar/syntax will work the same as reverso. The only thing that change will be the output that you'll have to parse each time. And having to handle all the cases can be a really consuming task when some tools already exists that works out-of-the-box.

I think you can write some script that will do one of the following :

  • Prepare the texte to be verified in an external tool (Microsoft Word, Google Doc, ... ) and re-inserted inside Vim afterward. Easy
  • Try to use an external tool directly from Vim with the requests and the parsing, ... Hard

But eventually you'll learn a lot on choosing the hard solution.

NOTE :

While trying to verify this text from reverso, I saw that the text should have a size of 600 characters max ... And I think this can be found on other online-free-to-use tools like this one.

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.