DEV Community

Thomas Alcala Schneider
Thomas Alcala Schneider

Posted on

Authoring with Vim

The REAL writing, not code writing πŸ˜†.

This post reflects only the thoughts of its author, Thomas Alcala.

If you don't know vim, I recommend trying Vim
Adventures
, a game-like vim tutorial.

Introduction

It was already the case before with tools like WordPress, but with the surge of headless CMS, serverless platforms, JAMstack, Wix, writing and
publishing your own blog is easier than ever.

There's a lot of value in browser editors too (the famous WYSIWYG, What
You See Is What You Get) that let users click text formatting buttons,
and the HTML code is generated for them. No need to learn web design,
and with browser plugins like the Grammarly plugin, you also get the
spelling, grammar corrections you'd get in office software.

So you ask "is there a reason to try and write with vim?"

Vim is not the most beginner-friendly editor, so this is mostly for
people already familiar with vim, but the answer is YES!

Let's try to get some cool writing features, to prove it!

Requisites

As you may know, the vim configuration is located in ~/.vimrc.
Technically, you can call vi -u /path/to/some/other/vimrc to use
another configuration file, so it should be possible to use different
configurations for code and writing. I prefer to maintain only one file, so I use a plugin manager for vim.

  1. vim-plug
  2. Go for some plugins

Formatting

For text formatting, I use
vim-pencil. It automatically
breaks lines in Markdown files, hides formatting code, etc. It helps
keeping the paragraphs clean.

I use the basic implementation with no configuration, the only trick
I made is with vim-plug to conditionally import it, so it doesn't break
lines and stuff when I write code:

Plug 'reedes/vim-pencil', { 'for': ['text', 'notes', 'markdown', 'mkd'] }
Enter fullscreen mode Exit fullscreen mode

Spell Check

For spell checking, I use another excellent plugin by reedes:
vim-lexical. You can also
configure a dictionary and a thesaurus, for completion, for technical
terms, etc. Very powerful.

Quality Assurance

Last but not least, by reedes, there's a plugin for writing quality,
called vim-wordy.

It's got a bunch of dictionary rings for the English language, and you
can switch between them. For example, it detects

  • redundant words
  • jargon
  • problematic terms
  • lazy or passive voice
  • manipulative (weasel) language
  • colloquialisms and idioms
  • etc...

I'll run it for fun after a first draft of this post, this should be
somewhat of an eye opener πŸ˜†.

Completion

Completion is kind of done by the lexical plugin, this is more about
prediction of the next word in a sentence!

Would you like an example?

Text prediction

For a non-native English speaker like me, this is very useful, most of
all for some idiomatic expressions.

This is done by combining some data, scripts and vim plugins:

  1. Get the data from the nextword dataset release page, there's a small and a large dataset, pick the one you like
  2. Define an environment variable in your shell for the dataset location
export NEXTWORD_DATA_PATH=/path/to/nextword-data
Enter fullscreen mode Exit fullscreen mode
  1. Get the nextword script (you must have installed Go before, as mentioned in the prerequisites)
go get -u github.com/high-moctane/nextword
Enter fullscreen mode Exit fullscreen mode
  1. Install asyncomplete-nextword, that means adding the asyncomplete and async vim plugins too, it's all in the plugin installation instructions Here I use the same trick as for the pencil plugin, and write
   Plug 'high-moctane/asyncomplete-nextword.vim', { 'for': ['text', 'notes', 'markdown', 'mkd'] }
Enter fullscreen mode Exit fullscreen mode

in my .vimrc file, so this plugin doesn't try to complete code
with grammarily correct words

Emojis

With very technical or outlandish posts, like one trying to sell writing
blog posts with vim, it's almost mandatory to put
some emojis to lighten the tone. I use a couple of plugins for that:
vim-emoji and
asyncomplete-emoji, that takes advantage of the asyncomplete plugin already installed in the completion segment of this post.

The asyncomplete plugin autocompletes stuff starting with colon, like
:thumbsup:, then I mapped a vim-emoji command in my .vimrc file that uses sed to translate all emojis
to unicode πŸ‘!

nnoremap <Leader>e :s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g<CR>  
nnoremap <Leader>E :%s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g<CR>  
Enter fullscreen mode Exit fullscreen mode

So now, <Leader> (comma , in my configuration) + e rewrites all
:emoji: to their symbol, lowercase e for the current line, uppercase
for the whole buffer.

Distraction-free Mode

I also use goyo.vim and
limelight.vim, even though
it may be even more distracting until you get used to it! πŸ˜†

Goyo

Bonus

Not for vim but for screen recording and making gifs out of videos, I
use:

  • simplescreenrecorder to record the screen or part of it
  • ffmpeg to make a gif out of the mkv video
ffmpeg -i ~/Videos/simplescreenrecorder-2020-03-29_19.22.57.mkv -r 15 -vf scale=720:-1 uploads/goyo.gif  
Enter fullscreen mode Exit fullscreen mode

Conclusion

Turns out it's not completely crazy to author stuff in vim! πŸ˜‰

Top comments (1)

Collapse
 
iggredible profile image
Igor Irianto

I write with vim too. There are some good plugins mentioned in this article that I need to check out. Great write!! :D