Git Product home page Git Product logo

vim-lexical's Introduction

vim-lexical

Building on Vim’s spell-check and thesaurus/dictionary completion

Features of this plugin:

  • Specify the languages to be used in spell-check
  • Specify a list of thesauruses for synonym completion
  • Specify a list of dictionaries for word completion
  • Specify a list of spellfiles for custom word-check additions
  • Opt-in key mappings for Normal mode thesaurus and dictionary completion
  • Buffer-scoped configuration (leaves your global settings alone)

Though principally used as a editor for code, Vim flirts with those of us editing documentation and prose by providing spell-check as well as completion capabilities using both dictionary and thesaurus files.

While we can configure these settings in our .vimrc files, we often need more granular control, where defaults are leveraged and configuration is applied by file type to the current buffer. This plugin fills that gap.

Installation

You can install using your favorite Vim package manager. (E.g., Pathogen, Vundle, or Plug.) If you are using a recent version of vim or neovim, you can also use native package support. (See :help packages.)

Configuration

Because spell-check, thesaurus, etc. isn’t needed for all file types, you can configure it per file type in your .vimrc:

set nocompatible
filetype plugin on       " may already be in your .vimrc

augroup lexical
  autocmd!
  autocmd FileType markdown,mkd call lexical#init()
  autocmd FileType textile call lexical#init()
  autocmd FileType text call lexical#init({ 'spell': 0 })
augroup END

In the last autocmd statement above, dictionaries and thesauruses are configured for the text file type, but spell-check is disabled by default.

lexical enables spell-check by default for buffers in which it is initialized. You can change that default setting in your .vimrc:

let g:lexical#spell = 1         " 0=disabled, 1=enabled

Spell-check language configuration

Vim’s global spelllang (note three ls) may already specify a default language. You can query it with a simple command:

:echo &spelllang
=> ‘en

If desired, you can be more specific, overriding the global spelllang in your .vimrc:

let g:lexical#spelllang = ['en_us','en_ca',]

Available spell files can be found at ftp.vim.org. Vim will attempt to download those which are not installed locally. For more detail see

:help spellfile.vim

Thesaurus configuration

If you don’t have one already, download a thesaurus, such as Grady Ward’s Moby Thesaurus at Zeke's moby thesaurus, or on Project Gutenberg and extract the mthesaur.txt file. By default lexical will look for it at the following path:

let g:lexical#thesaurus = ['~/.vim/thesaurus/mthesaur.txt',]

You can specify multiple paths to thesauruses in the list.

Dictionary configuration

On Unix-based systems (including OS X) the dictionary will default to:

let g:lexical#dictionary = ['/usr/share/dict/words',]

You can specify multiple paths to dictionaries in the list.

Spellfile configuration

On Unix-based systems (including OS X) the spellfile will default to:

let g:lexical#spellfile = ['~/.vim/spell/en.utf-8.add',]

You can specify a single path for spellfile in the list.

Commands

Vim offers many standard key mappings for spell-checking and completion.

Spell-check

These are the Normal mode commands:

  • ]s - Move to next misspelled word after the cursor.
  • [s - Like ]s but search backwards
  • ]S - Like ]s but only stop at bad words, not at rare words or words for another region.
  • [S - Like ]S but search backwards.

With the following key mappings you can use Visual mode selection to select the characters (including whitespace). Otherwise the word under the cursor is used.

  • zg - Mark as a good word

  • zw - Like zg but mark the word as a wrong (bad) word.

  • zug - Unmark as good word

  • zuw - Unmark as wrong (bad) word

  • z= - For the word under/after the cursor suggest correctly spelled words

  • 1z= - Use the first suggestion, without prompting

  • . - Redo - repeat last word replacement

  • :spellr - Repeat the replacement done by z= for all matches with the replaced word in the current window

For spelling suggestions while in Insert mode:

  • «CTRL-X» «CTRL-S» (or «CTRL-X» «s» for terminal users) - suggest spelling, using «CTRL-P» and «CTRL-N» to navigate.

For a convenient pop-up list of suggestions from Normal mode, you can map an available key of your choice in your .vimrc:

let g:lexical#spell_key = '<leader>s'

This buffer-scoped mapping is strictly opt-in. No key is mapped by default.

Thesaurus lookup

For thesaurus lookup while in Insert mode:

  • «CTRL-X» «CTRL-T» - thesaurus lookup, using «CTRL-P» and «CTRL-N» to navigate.

For convenient Normal mode thesaurus lookup from the cursor position, you can map an available key of your choice in your .vimrc:

let g:lexical#thesaurus_key = '<leader>t'

This buffer-scoped mapping is strictly opt-in. No key is mapped by default.

Dictionary completion

For dictionary completion while in Insert mode:

  • «CTRL-X» «CTRL-K» - dictionary completion, using «CTRL-P» and «CTRL-N» to navigate.

For convenient Normal mode dictionary lookup from the cursor position, you can map an available key of your choice in your .vimrc:

let g:lexical#dictionary_key = '<leader>k'

This buffer-scoped mapping is strictly opt-in. No key is mapped by default.

Define your own commands

Sometimes you need a highly-customized environment for spell-check and completion. You can define your own commands in your .vimrc to meet that need. For example:

command! -nargs=0 LexMed call lexical#init({
                    \ 'spell': 1,
                    \ 'spelllang':  ['en', 'medical'],
                    \ 'dictionary': ['~/.vim/dictionary/medical_terms.txt',
                    \                '/usr/share/dict/words',
                    \               ],
                    \ 'thesaurus':  ['~/.vim/dictionary/medical_synonyms.txt',
                    \                '~/.vim/thesaurus/mthesaur.txt',
                    \               ],
                    \ 'spellfile':  ['~/.vim/spell/en.add'],
                    \ })

Then to quickly configure Vim for the current buffer, enter the command:

:LexMed

Where you are providing an explicit value, it will use that. Where you do not, it will fall back to your specified defaults or global settings.

See also

The ervandew/supertab plugin will make these Insert mode completions available via the «tab» key.

If you find this plugin useful, you may want to check out these others originally by @reedes:

Future development

If you’ve spotted a problem or have an idea on improving this plugin, please post it to the GitHub project issue page.

vim-lexical's People

Contributors

alem0lars avatar alerque avatar reedes avatar somini avatar telemachus avatar wikimatze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-lexical's Issues

autocompletion source for asyncomplete.vim

Prabir Shrestha's asyncomplete.vim is compatible with vim8 and neovim. It would be nice to have a lexical/dictionary source for it. It makes use of vim8's timer feature.

I know I shouldn't be just dropping this in your issues, as if this is on-demand stuff. But I'm excited and can't help it. Thank you for your plugin.

Insert mode spelling suggest key conflicts with terminals

The documentation notes the following:

For spelling suggestions while in Insert mode:

  • «CTRL-X» «CTRL-S» - suggest spelling

This may work from GUI client versions of VIM, but it doesn't work from the terminal where CTRL+S is usually intercepted by the terminal emulator and interpreted as a STOP character.

Is there a way to re-map this and can the documentation be updated to reflect how this is done?

Lags while typing if lexical is active

I have lexical enabled for markdown and text files, along with litecorrect. Everything works as long as I don't pause typing for too long. If I do pause mid-word, lexical will cause a 5-10 second hang.

For example, I can type th<space> quickly with no problems, but if I pause between th and <space>, then vim will hang for about 5 seconds before the space appears. I can reproduce this 100% of the time in that scenario - just pause for a quick 3-count between the th and <space>. The problem will occasionally happen while backspacing over text as well when I have partially deleted a word.

I have NeoComplete installed, and I've seen that issues can arise with that combo, but even after calling NeoCompleteDisable on the buffer I get the above behavior. I have a fairly complex vimrc, so I'm trying to narrow down if it's another interaction between plugins as I get the chance.

Format for dictionaries

I have the following format for German spellchecking:

command -nargs=0 German call lexical#init({
                    \ 'spell': 1,
                    \ 'spelllang':  ['de_20'],
                    \ 'dictionary': ['~/.vim/spell/gerspchk.dict'],
                    \ 'thesaurus':  ['~/.vim/thesaurus/openthesaurus.txt'],
                    \ 'spellfile':  ['~/.vim/spell/de.utf-8.add'],
                    \ })

and somewhere I found a really big dicitionary for german called gerspchk.dict and was wondering why it didn't work.

screenshot - 20 08 2015 - 21 42 28

The issue was, that the whole file was in one big line. Now each word is on one line and it working now

screenshot - 20 08 2015 - 21 55 24

My suggestion: Would it make sense to create a seperate repository or directory, which contains thesaurus and dictionary for other languages? I was searching a while until I found a good German one.

E174: Command already exists: add ! to replace it

Hi Thanks for the work on this, very useful. I'm getting this error when I try to customize with "define your own commands". I'm using the example:

command -nargs=0 LexMed call lexical#init({
                    \ 'spell': 1,
                    \ 'spelllang':  ['en', 'medical'],
                    \ 'dictionary': ['~/.vim/dictionary/medical_terms.txt',
                    \                '/usr/share/dict/words',
                    \               ],
                    \ 'thesaurus':  ['~/.vim/dictionary/medical_synonyms.txt',
                    \                '~/.vim/thesaurus/mthesaur.txt',
                    \               ],
                    \ 'spellfile':  ['~/.vim/spell/en.add'],
                    \ })

But everytime I reload VIM I get:

Error detected while processing /Users/me/.vimrc:
line  518:
E174: Command already exists: add ! to replace it

Any ideas what could be wrong? Thanks

Detecting links?

Ideally it'd be great if the plugin could not have issues with links, is there a way to make sure that it understands what links are and just assume that they are spelled correctly?

Populates list of all entries in thesaurus

I cannot figure out what I am doing wrong. Using the thesaurus command only populates a list of the entire file. It is not suggesting only synonyms of the highlighted word.

Release tag

There is no, can you create one?

Thanks

Matthias

support thesaurus completion with multi-word entries

i get completions for synonyms but they are split by whitespace so that for example a line

foo;foo bar;bar;baz

would produce these completions for foo: ['foo', 'bar', 'bar', 'baz'].

It would be nice to be able to define a separator string which would be used to split the entries.

Provide completion function for emerging 'thesaurusfunc'

I have filed vim/vim#8950 and awesome @yegappan suggested POC implementation in yegappan/vim@949c4f2 Now, in order to test this, I would need a function following API of https://vimhelp.org/insert.txt.html#complete-functions generating a list of synonyms. Would it be possible for your plugin to add such function, which could be used as a value of 'thesaurusfunc' (same API as for 'completefunc' and 'omnifunc').

I hope it would be also help with your issue #9.

Cc: @Ron89 from https://github.com/Ron89/thesaurus_query.vim

Cross-posted with Ron89/thesaurus_query.vim#50

Mark good words for specific files?

Hi! First thank you for this great plugin. It is very useful.

I wonder if it is possible to mark good words for specific files? For example, if there are some abbreviations in some tex files but not others, it'd be useful to mark those abbrs as good words in those tex files only instead of the global vocabulary.

Default mapping for dictionary lookup

The current one if «CTRL-X» «CTRL-K». In my eyes `«CTRL-X» «CTRL-D» (for Dictionary) would be more suitable. What do you think?

Bests from Berlin.

Global-load to benefit users of neocomplete

Related to #10, where neocomplete will process file specified by dictionary at load time, causing a 3-4 second delay per buffer when lexical#init() is called.

Then, global load will have a single delay when starting vim. Buffer-specific calls to lexical#init() will no longer delay.

It seems can't work with neocomplete?

I install neocomplete plugin too, and I find after call lexical#init() vim will freeze about 3~5 seconds when I type something and it will pop up completion menu. If I use :NeoCompleteDisable vim will go well.
But I find I can't disable it with this autocmd FileType text,markdown,mkd,textile NeoCompleteDisable. How can I do?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.