DEV Community

Cover image for A Quickstart guide to setting up Vim for blogging
Siddharth
Siddharth

Posted on • Updated on • Originally published at siddharthshyniben.hashnode.dev

A Quickstart guide to setting up Vim for blogging

Vim is an extremely powerful editor.

But coding is not the only thing I use vim for (Guess where I'm writing this post?) Vim understands the structure of natural language, and you can jump between paragraphs, change words, delete sentences – With Vim you can edit at the speed of thought.

But writing in Vim won't be that smooth with your coding setup – you'll need a few plugins and mappings to make it better. Here, I'll show you how to quickly get started in blogging with Vim without going into too much detail.

I'm going to assume you know basic Vim stuff, so if you don't, go learn the basics first!

Screenshot, please!

Here's me editing this post in Vim. So meta, don't you think?

Screenshot of vim editing

General settings

I've set all the "good" stuff which we should set anyways, like syntax, spell, cursorline, and cursorcolumn. Set those for the best effect.

Mappings

Moving lines is one common thing I usually do while writing posts, so I've mapped this:

noremap + ddp
noremap - ddkkp
Enter fullscreen mode Exit fullscreen mode

I've also made my scroll "smooth" XD:

noremap <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y>
noremap <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
Enter fullscreen mode Exit fullscreen mode

Also, I've set up vim to insert a space after a comma:

inoremap , ,<space>
Enter fullscreen mode Exit fullscreen mode

I also added a bunch of operator pending mappings to make editing in quotes and braces easier:

onoremap in( :<c-u>normal! f(vi(<cr>
onoremap in{ :<c-u>normal! f{vi{<cr>
onoremap in" :<c-u>normal! f"vi"<cr>
onoremap in' :<c-u>normal! f'vi'<cr>
onoremap in` :<c-u>normal! f`vi`<cr>

onoremap il( :<c-u>normal! F(vi(<cr>
onoremap il{ :<c-u>normal! F{vi{<cr>
onoremap il" :<c-u>normal! F"vi"<cr>
onoremap il' :<c-u>normal! F'vi'<cr>
onoremap il` :<c-u>normal! F`vi`<cr>
Enter fullscreen mode Exit fullscreen mode

This lets you do stuff like change the text in the next (s using cin( or yanking (copying in vim is called yanking) in the last (last because previous would conflict with vim mappings) code in `s by running cil".

The next is a mapping to change the text in the current heading:

vim
augroup header
autocmd FileType markdown :onoremap ih :<c-u>execute "normal! ?^#\\+.*$\r:nohlsearch\rwv$"<cr>
autocmd FileType markdown :onoremap ah :<c-u>execute "normal! ?^#\\+.*$\r:nohlsearch\rv$"<cr>
augroup END

This way you can cih to change in the header and cah to change in the next header.

Another important mapping is to change a word:

vim
nnoremap <Leader>c *
cgn
nnoremap <Leader>C #
cgn

If you run <leader>c, the current word will be deleted and you can type anything instead of that. Hit . and the same will happen to the next matching word! <leader>C does the same, but goes backward.

Plugins!

I use a lot of plugins, and I'll show you my vim markdown ones here.

Looks

For the centered editing and focus mode, I use Goyo and Limelight. There are alternatives, but these are the ones I use.

For the syntax highlighting, I use Tim Pope's markdown runtime. Tim Pope is a magician at these things.

Lexical stuff

For grammar and spellchecking, I use many plugins. The main one is Pencil. I also use Vim Ditto, Lexical, and Wordy

I also use autopairs to get nicely autoclosed quotes.

That's just about it. There is more stuff I use, but these are the main ones.

Thanks for reading! If you like this stuff, check out my Twitter or Tweet this post (Yeah, I've gotten a bit self promotion-ey)

Screenshot of vim editing

Top comments (2)

Collapse
 
miketalbot profile image
Mike Talbot ⭐

I love to watch people who know how to use VIM well write. It's like watching the movies, they type seemingly 100s of characters and stuff that seems unrelated but magical happens on the screen!

cat typing fast!

I've tried. At a push, on a server that has nothing else I can make vi just about update a line. I got bought a book by a former colleague, it just never stuck for me. My brain is not wired for it, and I really do regret that lol.

Collapse
 
siddharthshyniben profile image
Siddharth

Even my brain wasn't wired for Vim, but it is possible to learn it. The first day you'll hate it. In a week you'll understand it and by a month you'll never go back.

If you get some time you should try learning it. Just run $ vimtutor (in the terminal) for a quick 30-min intro.