This content originally appeared on DEV Community and was authored by Siddharth
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?
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
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>
Also, I've set up vim to insert a space after a comma:
inoremap , ,<space>
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>
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)
This content originally appeared on DEV Community and was authored by Siddharth
Siddharth | Sciencx (2021-09-11T04:22:46+00:00) A Quickstart guide to setting up Vim for blogging. Retrieved from https://www.scien.cx/2021/09/11/a-quickstart-guide-to-setting-up-vim-for-blogging/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.