I struggled with vim a bit tonight. I wanted to set it up to edit markdown files and have it behave like a word processor, where at a certain point on a line the text would automatically wrap. After googling for, well, hours, I found out that vim is not a word processor and word wrap simply isn’t in its genes.
Well, kind of.
The first thing I did was install the markdown file type plugin. There are a few and I think I like this one the best: https://github.com/tpope/vim-markdown. Not sure why, it just seems to do the most stuff.
Then I set a few options in .vimrc, specific to markdown filetypes:
autocmd Filetype markdown setlocal wrap autocmd Filetype markdown setlocal linebreak autocmd Filetype markdown setlocal nolist autocmd Filetype markdown setlocal columns=80
The columns=80 actually sets the width of the vim application to 80 columns, which sets he size of the terminal window to 80-columns on my Mac’s iTerm. This is a bit annoying. What I really wanted was for vim to be wide, like the terminal, but for the text to wrap at 80 characters.
Alternatively, if I could live with line breaks, I could set up vim so hitting gq would force a paragraph to wordwrap, or gggqG to format the entire document. That config looks like this:
autocmd Filetype markdown setlocal tw=80 autocmd Filetype markdown setlocal wm=4 autocmd Filetype markdown setlocal fo=cat
But I can’t live with line breaks. This markdown editing is what I do all of my writing in…, it’s simple. I can strip it out if necessary, or I could go the other way and generate html, pdf’s, etc. More on that in another post.