Hacker News new | comments | show | ask | jobs | submit login
Using Vim as a writing environment (timotheepoisot.fr)
101 points by edwintorok 1305 days ago | hide | past | web | 41 comments | favorite

I'm working on a book talking about how to write effectively using Vim ("Writing With Vim"), sign up for updates at: https://leanpub.com/vim-for-writers. I need a few more weekends and it should be good to go. It's at about fifty pages right now and covers philosophy, basic customizations, things that are built into Vim as well as plugins, and will cover some publishing workflows.

50 pages? Ship it already!

Seriously, though, if you think it'll save someone some time or effort, it may be worthwhile to hit the publish button instead of waiting.

(I'm a cofounder of Leanpub, so I'm kind of biased, and being flippant here. Feel free to ignore me if it's not ready)

Actually, I appreciate your comment. I (tell myself I) was not able to commit to publishing previously because I could not make much time to provide updates. However, I think 1) this was probably a cop-out 2) the next couple of months will be more open. I am going to remove some interim text and/or comment it out and then publish for half price or something like that. Thanks for the push!

I think I've written far more ordinary prose in Vim than I have code: two books, a dissertation, a dozen articles, probably sixty talks, letters, notes, thousands of email messages . . . you name it.

I mainly use it, though, as an editor for LaTeX which, I think, is really using Vim precisely as it was intended (that is, as a code editor).

Although I write all of my code in Vim, I have always found it to not be great environment for text. The main annoyance comes from dealing with long lines or automatic line wrapping that never seems to do what I want it to.

Does anyone have other plugins that they find useful when writing in vim?

Reed Esau creates a bunch of vim plugins for writing, I've found them to work very nice:


Thank you for this link. vim-wheel is just pure gold, I needed that for a long time...

What I do is 1) use LaTeX so that I don't have to worry about lines and how they effect the final product, 2) :set wrap 3) map j and k to gj and gk, so that I can go up and down softwrapped lines like normal.

I really don't get why the behavior of gj/gk isn't the default.

I've written a lot of LaTeX and ConTeXt in Vim with one sentence per line without any problems.

I also follow this convention. One sentence, then new line. It looks a little janky, but when you run it through pandoc or whatever, it yields the way you would want.

Well since you mentioned long lines let me plug my own, because I find it a genuinely elegant solution to one related problem: http://github.com/goldfeld/vim-seek, it's a motion I created mostly to move around long lines, which were a major pain point for me especially when writing prose (and even more acutely painful back when I used soft-wrapped lines, though I still get a lot of mileage from it while using hard-wrap at 80 columns, RMS/Linus-style.)

I did not know job `gj` and `gk` for line navigation. That will definitely be useful!

Also try simply "gq" + down arrow or "gq" + up arrow to realign line lengths to the paragraph length in the up or down direction. Or you can do "gqap" to do the whole paragraph regardless or where you are located. This helps me keep pretty 80char paragraphs when writing latex or .rst or .md files, and the separate lines get merged to a single line by the text processor.

edit: To explain better, it basically re-wraps text in the optimal way into a paragraph. So you can not worry about spacing while typing and editing, and then when you are finally done you can just select the text and fix the wrapping really easily.

I find par to be very useful. http://www.nicemice.net/par/

Works great for re-wrapping code comments too.

It's been packaged in Debian for ages.

par is one of the handiest text tools around. I often use it to reformat longer quotes for HN. I just wish the documentation was a little better. I can only tell you about the two or three options that i use. I do not understand all of the other possible formatting commands and I definitely have no idea why I always set

  PARINIT="rTbgqR B=.,?_A_a Q=_s>"
The first version of par was released in 1993 and the first Debian package was in 1996. The latest release will be 13 years old on Tuesday.

gq for reflowing.

The main problem I have is when I'm authoring in vim and pasting to another editor which interprets hard returns as, well, hard returns.

Mostly I play games with piping through a formatting tool or join up lines manually before pasting them. Hrm. Now you've got me wondering if there's a good way to do that generically.

And here's what I've come up with, as ~/bin/unwrap:

    #!/usr/bin/perl -p
    use strict;
    { s/(?<!\n)\n(?!\n)//sg; }
    END {print"\n"}

> annoyance comes from dealing with long lines or automatic line wrapping

You have to set 'formatoptions' depending on what you're doing. I have a keymapping to set/unset fo+=a/fo-=a.

Author mentions having vim display greek letters and math symbols to replace the TeX input: other plugins supply the highlighting commands to do this as well, but I prefer setting LaTeX up to deal with Unicode symbols directly. I just like having actual integral signs, etc. in my source. Mainly because it freaks people out when you send them the source to your paper.

how do you input those symbols efficiently? (without using a character map)

LaTeX is ASCII, so no need to enter unusual characters. But LaTeX notation seems like a convenient way to enter mathematical characters even when not creating a LaTeX document. There are LaTeX input methods for Mac OS X, Emacs, and X Windows here:


vim has good support through digraphs, :digraphs will list them, and then to enter, either C-K <char1> <char2>, or <char1> <BS> <char2>

for example ö is C-K o : or o <BS> :

see http://vimdoc.sourceforge.net/htmldoc/digraph.html for more details

Despite knowing vim digraphs I personally use XCompose for that these days. It's easier to configure and I can use the same shortcut for every program, wich makes memorizing vim digraphs useless.

I'd mostly agree, but vim's digraphs are kind of essential when using gvim, since GTK+ seems to have an inexplicable vendetta against custom .XCompose files.

I don't know what to say. I am using gvim and my .XCompose settings seem to be fine. And I don't remember me having any troubles with that so I would have to fix something ever…

As it turns out, you're completely right. Oops.

In case anyone else happens to have the same issue, I solved it by sticking

  export GTK_IM_MODULE=xim
in /etc/environment .

Thanks, I can't believe I've been using Vim without knowing about this. The mappings for greek letters are particularly easy to remember.

Slightly less relevant, but if you use Mac OS X, this type of support is also available generally. For instance, Option+E then E results in é.

But isn't that extremely limited? Does Mac OS X have keyboard shortcuts for entering greek letters or the infinity symbol.

It's absolutely very limited. It has a shortcut for ∞ (Option+5), but "Greek letters" is too large of a set for the space provided.

But being able to do that let me do data entry on documents written in Swedish (which has the additional characters of é, å, ä, ö, and à) after about 10 seconds of ramping up figuring out where the desired keys were.

I'm sure there's a summary somewhere on the interwebz.

For any other Vim & reStructuredText users out there, I wrote a plugin to improve the reST writing experience:



That's precisely what vim-pandoc-syntax (the newest version of vim-pandoc's syntax file) + vim-latex use.

Sublime Text 2 + Vim mode + Markdown Plugin is amazing. It's like iA Writer except with VIM and all the fun Sublime Texyness.

vimroom (mentioned in the article) is really great.

How about navigating filesystem in Vim? NerdTree ?

I generally use NerdTree or Ctrl+P[1]. It's nice to be able to hit Ctrl+P and then type 3-5 chars + enter and be exactly where I want.

[1]: http://kien.github.io/ctrlp.vim/

I use :Ex(plore) It's not great but it gets the job done.

tpope's vinegar is great

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact