DEV Community

panmanio
panmanio

Posted on • Edited on • Originally published at burnicki.pl

Setting up VIM for blogging

VIM is the editor I use for programming. It is known for it's power at writing code thanks to it's built in features and numerous plugins, but how does it serve for blogging? Let's investigate on how to improve it's default behavior.

Spellcheck

Spell checking is built in feature of VIM, but it is disabled by default. I've enabled it with:

set spell spelllang=en_us
Enter fullscreen mode Exit fullscreen mode

That made VIM highlight my spelling errors. I can jump between misspelled words with ]s and [s. With the cursor located on a misspelled word I can type z= to get a list of possible fixes. When VIM is wrong I can tell it to accept a word with zg (undo with zw).

Abbreviations

VIM supports expansion of user defined abbreviations. For instance, if you define "utl" as an abbreviation of "utility", VIM automatically replaces "utl" with "utility" when typing. This feature can be used for auto correction. Just define:

:iabbrev veiw view
Enter fullscreen mode Exit fullscreen mode

to make VIM replace each "veiw" with "view" on the fly (in insert mode). Vim-autocorrect is one of the plugins that come with predefined useful abbreviations.

Dictionary

Next feature is auto completion. It is also supported by default but you may need to provide the dictionary and that was my case. Check if you have /usr/share/dict/words. I use Slackware and Ubuntu on daily basis; Slackware happened to have the dictionary installed, but on Ubuntu it was not there. Managed to provide the dict with sudo apt install wamerican. That tells VIM to use the dictionary file:

set dictionary=/usr/share/dict/words
Enter fullscreen mode Exit fullscreen mode

Now that the dictionary is set up, it can be used with <C-x><C-k> in insert mode.

Thesaurus

Looking for synonyms? VIM supports thesaurus, however it has to be configured. I was able to configure the built in feature but it needed a hack to handle multi word synonyms and I didn't like that. I've decided to install vim-lexical plugin. Just as the built in feature, the plugin needs a synonyms file to work: grabbed one from Project Gutenberg. Tell vim-lexical where the file is and initialize the plugin:

let g:lexical#thesaurus = ['~/.vim/mthesaur.txt']
call lexical#init()
Enter fullscreen mode Exit fullscreen mode

This plugin also handles dictionary and spell check features, I gave it a try. Here are some settings to set it up:

let g:lexical#spelllang = ['en_us']
let g:lexical#dictionary = ['/usr/share/dict/words']
" normal mode key mappings:
let g:lexical#spell_key = '<leader>s'
let g:lexical#thesaurus_key = '<leader>th'
let g:lexical#dictionary_key = '<leader>k'
Enter fullscreen mode Exit fullscreen mode

In insert mode, we can use <C-x><C-t> for thesaurus.

Other plugins

There are more plugins that support the writers work, I present few that I have found particularly useful.

textobj-sentence

This plugin provides motion commands based on full sentence detection. You can switch around sentences with ( and ) and use it just as any other motion commands. Depends on vim-textobj-user plugin.

wordy

Wordy lets you identify phrases that are overused, misused, abused, colloquial, idiomatic etc. It's a nice lightweight tool that operates on higher level than just single words. Definitely worth checking out.

ditto

Struggling with word repetitions? Ditto is there to localize & highlight them for you.

LSP + proselint

Proselint is not a VIM plugin. It is a separate tool described as a linter of English prose. Here are some of its features:

  • Avoiding archaic forms
  • Avoiding needless backformations
  • Avoiding redundant currency symbols
  • Avoiding false plurals
  • Avoiding illogical forms
  • Avoiding the word suddenly
  • Avoiding oxymorons
  • Calling jobs by the right name
  • Not comparing uncomparables
  • Using dïacríticâl marks
  • Linking only to existing sites

Full list here. Since the tool is a linter, it sounds like it should work with language servers. I use CoC.nvim for LSP features. Thankfully some smart guys have figured out how to make proselint work with coc.nvim & coc-diagnostic (see here). Now it works for my blog posts just like clangd does for my C++ code.

Let's see how it works

All these solutions look promising. I've already benefited from including them in my VIM configuration while writing this blog post. Will do further testing and investigation in next days. Haven't yet tried plugins like vim-pencil or vim-abolish.

Further reading:

Top comments (0)