Difference between revisions of "Vim for Writers"

 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[File:Vim_workflow.png]]
  
 
== Introduction ==
 
== Introduction ==
 
[http://www.vim.org/ vim] is a very powerful [http://www.viemu.com/a-why-vi-vim.html modal text editor] with a large system of plugins. You may have heard of the infamous [https://www.udemy.com/blog/vim-vs-emacs/ vim vs. emacs] wars that have existed from the time of usenet and persist till today. [http://net.tutsplus.com/articles/web-roundups/25-vim-tutorials-screencasts-and-resources/ vim does have a learning curve] but it is very worthwhile to learn because your fingers never leave the keyboard as you are writing and editing. ViM = Vi Improved; it is a superset of the original vi editor.
 
[http://www.vim.org/ vim] is a very powerful [http://www.viemu.com/a-why-vi-vim.html modal text editor] with a large system of plugins. You may have heard of the infamous [https://www.udemy.com/blog/vim-vs-emacs/ vim vs. emacs] wars that have existed from the time of usenet and persist till today. [http://net.tutsplus.com/articles/web-roundups/25-vim-tutorials-screencasts-and-resources/ vim does have a learning curve] but it is very worthwhile to learn because your fingers never leave the keyboard as you are writing and editing. ViM = Vi Improved; it is a superset of the original vi editor.
 +
 +
[https://webdevchallenges.com/table-of-contents/a-brief-introduction-to-vim/ This series of articles introduces vim].
 +
 +
== Quick Vim Cheatsheet(s) ==
 +
* See [this excellent vim cheatsheet of commands you should know](https://github.com/LeCoupa/awesome-cheatsheets/blob/master/tools/vim.txt) (''github'')
 +
 +
== A great example vimrc (WurdBender) ==
 +
[http://nanowrimo.org/participants/wurdbender WurdBender] writes:
 +
I noticed most of the Vim community seems to prefer the Solarized theme, but I really can't stand it myself. I've been using Tomorrow Night from the repository you linked, except I run in 256 color mode (set t_Co=256) to subdue the colors a bit. I'm still trying out fonts. At the moment I'm liking Input Mono.
 +
 +
Below is what my setup looks like with some code to show off the colors. I wasn't sure I'd get much use out of the Airline bar, but it comes in handy. I've also created a [https://github.com/WurdBendur/vimrc/blob/master/.vimrc repository for my .vimrc on GitHub], which I'm told is a good idea in case you need to quickly set up Vim on a new system. It's there if anybody wants to see it, though it's maybe a bit cluttered and noobish.
 +
 +
=== A derivative vimrc (NewMexicoKid) ===
 +
[http://nanowrimo.org/participants/newmexicokid NewMexicoKid] writes:
 +
I made a (slightly modified) [https://github.com/NewMexicoKid/vimrc vimrc] based on WurdBender's. I turned off numbers (too technical for NaNo), added autoindent and shift width/expand tab (which I find more useful for doing sub-bullets in markdown).
 +
 +
==== A more-efficient wordcount algorithm for writers (vithic) ====
 +
* From vithic
 +
* To NewMexicoKid
 +
* Sent at October 21, 2018 16:28
 +
* Subject Vim.
 +
 +
I just noticed that my Vim configuration is based yours that is referenced at http://www.naperwrimo.org/wiki/index.php?title=Vim_for_Writers. :)
 +
 +
I managed to decrease the word count overhead quite a bit somehow by copy/pasting a function from somewhere that made it only update it on every line break (at 20k words it's still painful when inserting a line break though).
 +
 +
Just replace your ~/.vim/plugged/vim-markdown-folding/after/ftplugin/markdown/folding.vim with this:
 +
 +
https://pastebin.com/A291j9Fc
 +
 +
Just to add some clarification - the original setup provides a line count that is mostly useless to authors. The suggested folding.vim file changes that into a word count and nothing else (at a slight resource expense, most likely - especially if folds grow into 1k+ words).
 +
 +
=== Tips from reddit ===
 +
[https://www.reddit.com/r/vim/comments/8m88kg/do_you_use_vim_for_writing_if_so_whats_your/ This reddit post and answer has some interesting starting points to explore]:
 +
 +
  Plug 'reedes/vim-pencil' " Super-powered writing things
 +
  Plug 'tpope/vim-abolish' " Fancy abbreviation replacements
 +
  Plug 'junegunn/limelight.vim' " Highlights only active paragraph
 +
  Plug 'junegunn/goyo.vim' " Full screen writing mode
 +
  Plug 'reedes/vim-lexical' " Better spellcheck mappings
 +
  Plug 'reedes/vim-litecorrect' " Better autocorrections
 +
  Plug 'reedes/vim-textobj-sentence' " Treat sentences as text objects
 +
  Plug 'reedes/vim-wordy' " Weasel words and passive voice
 +
 +
 +
  augroup pencil
 +
    autocmd!
 +
    autocmd filetype markdown,mkd call pencil#init()
 +
        \ | call lexical#init()
 +
        \ | call litecorrect#init()
 +
        \ | setl spell spl=en_us fdl=4 noru nonu nornu
 +
        \ | setl fdo+=search
 +
  augroup END
 +
 +
  " Pencil / Writing Controls {{{
 +
    let g:pencil#wrapModeDefault = 'soft'
 +
    let g:pencil#textwidth = 74
 +
    let g:pencil#joinspaces = 0
 +
    let g:pencil#cursorwrap = 1
 +
    let g:pencil#conceallevel = 3
 +
    let g:pencil#concealcursor = 'c'
 +
    let g:pencil#softDetectSample = 20
 +
    let g:pencil#softDetectThreshold = 130
 +
  " }}}
 +
 +
And finally: https://labs.tomasino.org/vim-in-context/
 +
 +
Also see [https://old.reddit.com/r/vim/comments/byuuu3/vim_for_novel_writing/ this reddit thread from 2019-06-12] about how to use ViM for novel writing.
 +
 +
* See [https://old.reddit.com/r/vim/comments/ckyspu/heres_how_to_create_custom_workspaces_to_switch/ how to create custom workspaces to switch from coding to writing prose] (added 2019-08-02)
 +
image: https://preview.redd.it/gcks770ugyd31.png?width=1024&auto=webp&s=47a01d0fea2c0bf9675689a769938cfdf31c1bb7
 +
 +
=== Tips from [https://nanowrimo.org/participants/pingouin Pingouin] ===
 +
I have a dozen plugins in my .vimrc, but the only ones I couldn't live without for prose are Goyo (distraction-free), vim-peekaboo (show registers while yanking/pasting) and vim-Grammalecte (a french grammar/spelling checker). I've added a live word count to my status bar and a feature I haven't seen elsewhere but which I now find mandatory: something to hide what I'm writing but still provide me with some context.
 +
 +
It serves two purposes: to protect my kids or other prying eyes from reading my "rated" stuff, and to help me resist my inner editor (can't correct what I don't see!). I can still read some of it with a little effort if I typed it not too long ago, and see the overall structure so I don't get lost. It's a single key toggle, so I can quickly hide or reveal the whole window.
 +
 +
Another "can't live without it" setting is the one to return to last edit position when opening files.
 +
 +
I also have a shortcut to navigate to the previous or next scene/chapter/book:
 +
 +
map <leader>n /^[#*]<cr>:nohl<cr>
 +
 +
map <leader>p k?^[#*]<cr>:nohl<cr>
 +
 +
 +
Edit: I can't embed an image… so go to https://imgur.com/a/H4oNuZD to see my "incognito/censored/kill-the-inner-editor" mode
 +
 +
Update: Well, it was coded within my .vimrc, but it's now a plugin: https://github.com/swordguin/vim-veil
 +
 +
Thanks for your interest! I hope it will be useful to you or to other people.
 +
 +
Here's the relevant section of my .vimrc for the word count: https://pastebin.com/t07PRJYC
 +
 +
Both work flawlessly even with a 200'000 words markdown novel (no lag at all)
 +
 +
=== vimrc generator ===
 +
See [https://arp242.net/my-first-vimrc/#options=1111111111011100111110001111010 this great vimrc generator to get a decent starter vimrc].
 +
 +
== How to manage long .vimrcs ==
 +
* See [https://vimways.org/2018/from-vimrc-to-vim/ from .vimrc to .vim]
 +
 +
== How to learn how to use vim ==
 +
* [https://www.quora.com/What-is-the-best-way-to-learn-Vim quora answers on the best ways to learn vim]
 +
 +
== vimrc tips ==
 +
HBBisenieks writes:
 +
Most of my vimrc is set for the benefit of my dayjob as a sysadmin, but one line I always make sure is in my vimrc is
 +
 +
  set title
 +
 +
That way I rarely forget what file I'm editing.
 +
 +
== ViM Prose Mode ==
 +
[https://old.reddit.com/r/vim/comments/q03mqa/my_setup_for_prose/ Posted] by [https://old.reddit.com/user/Urist321 Urist321] on reddit.
 +
 +
=== Prose Mode Features: ===
 +
 +
* Prose Mode can be toggled with :ToggleProse, turned on with :Prose, and turned off with :UnProse.
 +
* Enables spell checking (en_us by default.)
 +
* Turns on the Goyo plugin with a line width of 66 (considered the optimal width by typographers.)
 +
* Turns on the VimPencil plugin in soft linewrap mode.
 +
 +
=== Other Features: ===
 +
 +
* <Leader>d opens a scratchpad with a definition of the word under the cursor.
 +
* <Leader>t open a scratchpad with synonyms of the word under the cursor.
 +
 +
=== Requirements: ===
 +
 +
The provided vimrc has the following dependencies:
 +
 +
* The [https://vimawesome.com/plugin/goyo-vim Goyo plugin].
 +
* The [https://vimawesome.com/plugin/vim-pencil VimPencil] plugin.
 +
* [https://github.com/Dushistov/sdcv SDCV]. Good installation instructions can be found [https://askubuntu.com/questions/191125/is-there-an-offline-command-line-dictionary here].
 +
* [https://github.com/words/moby#readme Moby Thesaurus CLI].
 +
 +
=== vimrc: ===
 +
 +
    let w:ProseModeOn = 0
 +
 +
    function EnableProseMode()
 +
        setlocal spell spelllang=en_us
 +
        Goyo 66
 +
        SoftPencil
 +
        echo "Prose Mode On"
 +
    endfu
 +
 +
    function DisableProseMode()
 +
        Goyo!
 +
        NoPencil
 +
        setlocal nospell
 +
        echo "Prose Mode Off"
 +
    endfu
 +
 +
    function ToggleProseMode()
 +
        if w:ProseModeOn == 0
 +
            call EnableProseMode()
 +
            let w:ProseModeOn = 1
 +
        else
 +
            call DisableProseMode()
 +
        endif
 +
    endfu
 +
 +
    command Prose call EnableProseMode()
 +
    command UnProse call DisableProseMode()
 +
    command ToggleProse call ToggleProseMode()
 +
 +
    function ScratchBufferize()
 +
        setlocal buftype=nofile
 +
        setlocal bufhidden=hide
 +
        setlocal noswapfile
 +
    endfu
 +
 +
    nnoremap <Leader>d :new \| read ! sdcv <C-R><C-W> <CR>:call ScratchBufferize() <CR>:normal gg<CR>
 +
    nnoremap <Leader>t :new \| read ! moby <C-R><C-W> \| tr , '\n' <CR>:call ScratchBufferize() <CR>:normal gg2dd <CR>
  
 
== ViM Folding ==
 
== ViM Folding ==
Line 28: Line 205:
 
== Beautiful colors ==
 
== Beautiful colors ==
 
Check out the beauty of [https://github.com/altercation/vim-colors-solarized vim-colors-solarized] that "''is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several [https://github.com/altercation/solarized#features unique properties]. I designed this colorscheme with both precise [http://en.wikipedia.org/wiki/Lab_color_space CIELAB] lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions.''" ([http://ethanschoonover.com/solarized ethanschoonover.com])
 
Check out the beauty of [https://github.com/altercation/vim-colors-solarized vim-colors-solarized] that "''is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several [https://github.com/altercation/solarized#features unique properties]. I designed this colorscheme with both precise [http://en.wikipedia.org/wiki/Lab_color_space CIELAB] lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions.''" ([http://ethanschoonover.com/solarized ethanschoonover.com])
 +
 +
Also see [https://www.quora.com/What-are-some-of-the-best-Vim-color-schemes this quora question with plenty of answers that recommend different color schemes].
 +
 +
Another couple of references that show you color samples:
 +
* http://vimcolors.com/
 +
*
  
 
== Notes for Planning ==
 
== Notes for Planning ==
Line 127: Line 310:
  
 
== Related Articles of Interest ==
 
== Related Articles of Interest ==
 +
* [https://old.reddit.com/r/vim/comments/qqgbrb/your_most_favoriteuseful_vim_command/ reddit list of favorite/most useful ViM commands] - added 2021-11-10
 +
* [https://old.reddit.com/r/vim/comments/qq2td8/writing_editing_and_worldbuilding_on_vim_a/ Workshop presentation by DevMahasen at #VimConf2021: Writing, Editing, and World-building on Vim] (link to the reddit post with a subsequent link to youtube) - added 2021-11-08
 +
* [https://hackernoon.com/learning-vim-what-i-wish-i-knew-b5dca186bef7 Learning ViM - what I wish I knew] -- added 2019-10-20
 +
* [http://learnvimscriptthehardway.stevelosh.com/ Learn vim script the hard way] - added 2019-01-22
 +
* [https://www.barbarianmeetscoding.com/blog/2019/01/06/exploring-vim-6-great-books-to-improve-your-vim-fu/ Exploring vim - 6 great books to improve your vim-fu] - added 2019-01-22
 +
* [https://opensource.com/article/17/2/vim-plugins-writers Awesome vim plugins for writers] - Posted 08 Feb 2017 by Zsolt Szakács
 
* [http://wynnnetherland.com/journal/reed-esau-s-growing-list-of-vim-plugins-for-writers ViM Plugins For Writers] - [https://github.com/reedes Reed Esau]'s growing list of ViM plugins for writers. Includes [https://github.com/reedes/vim-colors-pencil vim colors pencil] (pretty theme for writers), [http://github.com/reedes/vim-thematic vim thematic] (theme manager), [http://github.com/reedes/vim-pencil vim-pencil] (handles wrap modes for writers)
 
* [http://wynnnetherland.com/journal/reed-esau-s-growing-list-of-vim-plugins-for-writers ViM Plugins For Writers] - [https://github.com/reedes Reed Esau]'s growing list of ViM plugins for writers. Includes [https://github.com/reedes/vim-colors-pencil vim colors pencil] (pretty theme for writers), [http://github.com/reedes/vim-thematic vim thematic] (theme manager), [http://github.com/reedes/vim-pencil vim-pencil] (handles wrap modes for writers)
 
* [http://chrismdp.com/2010/11/how-im-writing-my-book-using-git-and-ruby/ an article of a guy who wants to devise a ruby gem for handling novel writing/formatting tasks] (okay, not really a vim resource; but something that looked interesting to those of us writing text files)  
 
* [http://chrismdp.com/2010/11/how-im-writing-my-book-using-git-and-ruby/ an article of a guy who wants to devise a ruby gem for handling novel writing/formatting tasks] (okay, not really a vim resource; but something that looked interesting to those of us writing text files)  
Line 141: Line 330:
 
* One user uses ViM together with git (flashbake), vimroom, onlinethesaurus, vim-abolish, vim-repeat and vim-outline. Vimroom does not always work as well, and there's little support for it, but it's still usable with a bit of tinkering.  Of all the plugins vim-outline is the most useful. She recommends it to everyone planning to use vim. It allows you to easily structure your text, and makes for easy folding/expanding.
 
* One user uses ViM together with git (flashbake), vimroom, onlinethesaurus, vim-abolish, vim-repeat and vim-outline. Vimroom does not always work as well, and there's little support for it, but it's still usable with a bit of tinkering.  Of all the plugins vim-outline is the most useful. She recommends it to everyone planning to use vim. It allows you to easily structure your text, and makes for easy folding/expanding.
 
* [https://github.com/tpope/vim-repeat vim-repeat] looks interesting for better repetition with: .
 
* [https://github.com/tpope/vim-repeat vim-repeat] looks interesting for better repetition with: .
* Seth Brown wrote: [http://www.drbunsen.org/the-text-triumvirate/ The Text Triumvirate] (zsh, vim and tmux) -- in this article, Seth mentions [https://github.com/Lokaltog/powerline vim-powerline], a python-powered status line plugin. The author of that plugin then points to [https://github.com/bling/vim-airline vim-airline] as a lighter-weight but still featureful status line plugin.  
+
* Seth Brown wrote: [https://web.archive.org/web/20200414221857/https://www.drbunsen.org/the-text-triumvirate/ The Text Triumvirate] (zsh, vim and tmux) -- in this article, Seth mentions [https://github.com/Lokaltog/powerline vim-powerline], a python-powered status line plugin. The author of that plugin then points to [https://github.com/bling/vim-airline vim-airline] as a lighter-weight but still featureful status line plugin.  
 
* [http://www.reddit.com/r/vim/comments/142zn7/are_you_interested_in_a_vim_for_writers_book/ one redditor has plans to write a book on Vim for Writers]<nowiki>; there are some interesting chapter titles in this reddit.</nowiki>
 
* [http://www.reddit.com/r/vim/comments/142zn7/are_you_interested_in_a_vim_for_writers_book/ one redditor has plans to write a book on Vim for Writers]<nowiki>; there are some interesting chapter titles in this reddit.</nowiki>
 
* Here is a [https://www.youtube.com/watch?v=p6K4iIMlouI&noredirect=1 nifty Google tech talk by vim creator Bram Moolenaar] with useful tips for productive vim; and [http://connermcd.com/blog/2011/10/21/notetaking-with-vim/ a blog post] about how to use vim and ack for notetaking.
 
* Here is a [https://www.youtube.com/watch?v=p6K4iIMlouI&noredirect=1 nifty Google tech talk by vim creator Bram Moolenaar] with useful tips for productive vim; and [http://connermcd.com/blog/2011/10/21/notetaking-with-vim/ a blog post] about how to use vim and ack for notetaking.
 +
* [https://nickjanetakis.com/blog/vim-is-saving-me-hours-of-work-when-writing-books-and-courses How vim is saving me hours of work when writing books and courses] - [https://nickjanetakis.com/about Nick Janetakis]
  
 
== Annotations ==
 
== Annotations ==
Line 186: Line 376:
 
* because of [http://www.makeuseof.com/tag/top-7-reasons-to-give-the-vim-text-editor-a-chance/ these seven reasons] (well, the last is a bit facetious, but the other six are spot on: it's mature and people who learn it generally swear by it, it's free and has a vibrant community, it's customizable and extensible, it works over ssh connections, its configuration is extremely portable, and it is very thoroughly documented)  
 
* because of [http://www.makeuseof.com/tag/top-7-reasons-to-give-the-vim-text-editor-a-chance/ these seven reasons] (well, the last is a bit facetious, but the other six are spot on: it's mature and people who learn it generally swear by it, it's free and has a vibrant community, it's customizable and extensible, it works over ssh connections, its configuration is extremely portable, and it is very thoroughly documented)  
 
* "[http://protoiyer.github.io/blog/2011/11/04/vim-at-20-simply-the-best-text-editor/ If you are someone who writes text or code for a number of hours every day, learning Vim would be a gamechanger for you.] "
 
* "[http://protoiyer.github.io/blog/2011/11/04/vim-at-20-simply-the-best-text-editor/ If you are someone who writes text or code for a number of hours every day, learning Vim would be a gamechanger for you.] "
 +
 +
== ViM color schemes ==
 +
* See http://vimcolors.com/
  
 
== Other references ==
 
== Other references ==
Line 191: Line 384:
 
* [http://benmccormick.org/2014/07/02/learning-vim-in-2014-vim-as-language/ Learning ViM as a language]
 
* [http://benmccormick.org/2014/07/02/learning-vim-in-2014-vim-as-language/ Learning ViM as a language]
 
* [http://timotheepoisot.fr/2014/01/01/vim-writing-environment/ Using ViM as a writing environment]
 
* [http://timotheepoisot.fr/2014/01/01/vim-writing-environment/ Using ViM as a writing environment]
 +
 +
== What about Emacs? ==
 +
[https://nanowrimo.org/participants/brookter brookter] wrote:
 +
 +
If you like the general approach of Scrivener but want to stay in plain text with keybindings like they are meant to be used (ie Vim...), you may want to check this out: it's basically an attempt to reproduce some of Scrivener's features using Vim. https://vimvalley.com/replacing-scrivener-with-emacs-and-vim/ Actually, it uses Evil mode within Emacs — this is a VERY GOOD THING. Evil mode (Vim emulation) gives Emacs the one thing it lacks, a decent text editor. (Ahem.)

Latest revision as of 20:52, 10 December 2021

Vim workflow.png

Introduction

vim is a very powerful modal text editor with a large system of plugins. You may have heard of the infamous vim vs. emacs wars that have existed from the time of usenet and persist till today. vim does have a learning curve but it is very worthwhile to learn because your fingers never leave the keyboard as you are writing and editing. ViM = Vi Improved; it is a superset of the original vi editor.

This series of articles introduces vim.

Quick Vim Cheatsheet(s)

A great example vimrc (WurdBender)

WurdBender writes: I noticed most of the Vim community seems to prefer the Solarized theme, but I really can't stand it myself. I've been using Tomorrow Night from the repository you linked, except I run in 256 color mode (set t_Co=256) to subdue the colors a bit. I'm still trying out fonts. At the moment I'm liking Input Mono.

Below is what my setup looks like with some code to show off the colors. I wasn't sure I'd get much use out of the Airline bar, but it comes in handy. I've also created a repository for my .vimrc on GitHub, which I'm told is a good idea in case you need to quickly set up Vim on a new system. It's there if anybody wants to see it, though it's maybe a bit cluttered and noobish.

A derivative vimrc (NewMexicoKid)

NewMexicoKid writes: I made a (slightly modified) vimrc based on WurdBender's. I turned off numbers (too technical for NaNo), added autoindent and shift width/expand tab (which I find more useful for doing sub-bullets in markdown).

A more-efficient wordcount algorithm for writers (vithic)

  • From vithic
  • To NewMexicoKid
  • Sent at October 21, 2018 16:28
  • Subject Vim.

I just noticed that my Vim configuration is based yours that is referenced at http://www.naperwrimo.org/wiki/index.php?title=Vim_for_Writers. :)

I managed to decrease the word count overhead quite a bit somehow by copy/pasting a function from somewhere that made it only update it on every line break (at 20k words it's still painful when inserting a line break though).

Just replace your ~/.vim/plugged/vim-markdown-folding/after/ftplugin/markdown/folding.vim with this:

https://pastebin.com/A291j9Fc

Just to add some clarification - the original setup provides a line count that is mostly useless to authors. The suggested folding.vim file changes that into a word count and nothing else (at a slight resource expense, most likely - especially if folds grow into 1k+ words).

Tips from reddit

This reddit post and answer has some interesting starting points to explore:

  Plug 'reedes/vim-pencil' " Super-powered writing things
  Plug 'tpope/vim-abolish' " Fancy abbreviation replacements
  Plug 'junegunn/limelight.vim' " Highlights only active paragraph
  Plug 'junegunn/goyo.vim' " Full screen writing mode
  Plug 'reedes/vim-lexical' " Better spellcheck mappings
  Plug 'reedes/vim-litecorrect' " Better autocorrections
  Plug 'reedes/vim-textobj-sentence' " Treat sentences as text objects
  Plug 'reedes/vim-wordy' " Weasel words and passive voice


  augroup pencil
   autocmd!
   autocmd filetype markdown,mkd call pencil#init()
       \ | call lexical#init()
       \ | call litecorrect#init()
       \ | setl spell spl=en_us fdl=4 noru nonu nornu
       \ | setl fdo+=search
  augroup END
 " Pencil / Writing Controls {{{
   let g:pencil#wrapModeDefault = 'soft'
   let g:pencil#textwidth = 74
   let g:pencil#joinspaces = 0
   let g:pencil#cursorwrap = 1
   let g:pencil#conceallevel = 3
   let g:pencil#concealcursor = 'c'
   let g:pencil#softDetectSample = 20
   let g:pencil#softDetectThreshold = 130
 " }}}

And finally: https://labs.tomasino.org/vim-in-context/

Also see this reddit thread from 2019-06-12 about how to use ViM for novel writing.

image: https://preview.redd.it/gcks770ugyd31.png?width=1024&auto=webp&s=47a01d0fea2c0bf9675689a769938cfdf31c1bb7

Tips from Pingouin

I have a dozen plugins in my .vimrc, but the only ones I couldn't live without for prose are Goyo (distraction-free), vim-peekaboo (show registers while yanking/pasting) and vim-Grammalecte (a french grammar/spelling checker). I've added a live word count to my status bar and a feature I haven't seen elsewhere but which I now find mandatory: something to hide what I'm writing but still provide me with some context.

It serves two purposes: to protect my kids or other prying eyes from reading my "rated" stuff, and to help me resist my inner editor (can't correct what I don't see!). I can still read some of it with a little effort if I typed it not too long ago, and see the overall structure so I don't get lost. It's a single key toggle, so I can quickly hide or reveal the whole window.

Another "can't live without it" setting is the one to return to last edit position when opening files.

I also have a shortcut to navigate to the previous or next scene/chapter/book:

map <leader>n /^[#*]<cr>:nohl<cr>

map <leader>p k?^[#*]<cr>:nohl<cr>


Edit: I can't embed an image… so go to https://imgur.com/a/H4oNuZD to see my "incognito/censored/kill-the-inner-editor" mode

Update: Well, it was coded within my .vimrc, but it's now a plugin: https://github.com/swordguin/vim-veil

Thanks for your interest! I hope it will be useful to you or to other people.

Here's the relevant section of my .vimrc for the word count: https://pastebin.com/t07PRJYC

Both work flawlessly even with a 200'000 words markdown novel (no lag at all)

vimrc generator

See this great vimrc generator to get a decent starter vimrc.

How to manage long .vimrcs

How to learn how to use vim

vimrc tips

HBBisenieks writes: Most of my vimrc is set for the benefit of my dayjob as a sysadmin, but one line I always make sure is in my vimrc is

  set title

That way I rarely forget what file I'm editing.

ViM Prose Mode

Posted by Urist321 on reddit.

Prose Mode Features:

  • Prose Mode can be toggled with :ToggleProse, turned on with :Prose, and turned off with :UnProse.
  • Enables spell checking (en_us by default.)
  • Turns on the Goyo plugin with a line width of 66 (considered the optimal width by typographers.)
  • Turns on the VimPencil plugin in soft linewrap mode.

Other Features:

  • <Leader>d opens a scratchpad with a definition of the word under the cursor.
  • <Leader>t open a scratchpad with synonyms of the word under the cursor.

Requirements:

The provided vimrc has the following dependencies:

vimrc:

   let w:ProseModeOn = 0
   function EnableProseMode()
       setlocal spell spelllang=en_us
       Goyo 66
       SoftPencil
       echo "Prose Mode On"
   endfu
   function DisableProseMode()
       Goyo!
       NoPencil
       setlocal nospell
       echo "Prose Mode Off"
   endfu
   function ToggleProseMode()
       if w:ProseModeOn == 0
           call EnableProseMode()
           let w:ProseModeOn = 1
       else
           call DisableProseMode()
       endif
   endfu
   command Prose call EnableProseMode()
   command UnProse call DisableProseMode()
   command ToggleProse call ToggleProseMode()
   function ScratchBufferize()
       setlocal buftype=nofile
       setlocal bufhidden=hide
       setlocal noswapfile
   endfu
   nnoremap <Leader>d :new \| read ! sdcv <C-R><C-W> <CR>:call ScratchBufferize() <CR>:normal gg<CR>
   nnoremap <Leader>t :new \| read ! moby <C-R><C-W> \| tr , '\n' <CR>:call ScratchBufferize() <CR>:normal gg2dd <CR>

ViM Folding

Here is a must-see video that makes vim folding look utterly simple.

Also see this plugin: vim-outliner

ViM plugins

There are several ViM plugin managers. One of them is: vundle, a vim bundle manager that lets you EASILY install other vim plugins/bundles.

Markdown

Markdown is a very simple mark-up language that encourages writers to focus on their content rather than on presentation. It can handle bolding, italics, bullet lists, section headings, hypertext links, etc. and you can use utilities like pandoc to transform your markdown text to many, many different formats, including:

ViM has plugins for better markdown syntax highlighting (vim-markdown) and vim-markdown-folding. With the latter, you can:

  • add the spacebar mapping to your .vimrc:
    nnoremap <Space> za

Some use gnu make to automatically generate everything from the markdown source.

Beautiful colors

Check out the beauty of vim-colors-solarized that "is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several unique properties. I designed this colorscheme with both precise CIELAB lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions." (ethanschoonover.com)

Also see this quora question with plenty of answers that recommend different color schemes.

Another couple of references that show you color samples:

Notes for Planning

See the vim script called nvim to build piles of random little notes during novel planning.

Movement

Vim can be more or less as powerful as you want it. It's really worth the time spent learning how to jump around ( using '(' and ')' to jump to the start of the previous / next sentence in particular).

Help

  • You can get help on just about any vim feature by entering the command ':help SOMETHING', e.g. ':help spell'
  • This might be useful: Vim Commands Cheat Sheet

Autosave

  • 'set autowriteall' - autosave your current document whenever you change away from the current buffer. You can just do 'set autowrite', which will save in *most* situations (the main exemption being quitting).
  • There is also a vim plugin: https://github.com/907th/vim-auto-save. It apparently turns on auto save and saves every time a buffer is modified.

Spell Checking

  • it supports a personal word list (very useful for fantasy authors ;-) )
  • some useful keys for spellchecking:
    • ]s - forward to misspelled/rare/wrong cap word
    • [s - backwards ]
    • S - only stop at misspellings
    • [S - in other direction
    • zG - accept spelling for this session
    • zg - accept spelling and add to personal dictionary
    • zW - treat as misspelling for this session
    • zw - treat as misspelling and add to personal dictionary
    • z= - show spelling suggestions
    • :spellr - repeat last spell replacement for all words in window

Thesaurus

WriteRoom / DarkRoom simulator

There apparently are many writeroom/darkroom vim plugins and configurations for "distraction free writing". Of the three I tried, I think I like this plugin (vimroom) the best. For installation using vundle, see https://github.com/mikewest/vimroom (Bundle 'mikewest/vimroom'). A rival noted that on Windows, VimTweak yields transparent gvim windows.

Sessions

Sessions can be used to save window configurations

You can use vundle to load both of these and then :SaveSession to save the session. Put

  let g:session_autosave = 'no'

at the end of your vimrc so you don't get prompted to save sessions when you close files. A session will preserve your layout and place in the file--very cool!

Wordcount

   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   " Here begins my automated wordcount addition.
   " This combines several ideas from:
   " http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim
   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   let g:word_count="<unknown>"
   function WordCount()
       return g:word_count
   endfunction
   function UpdateWordCount()
       let lnum = 1
       let n = 0
       while lnum <= line('$')
           let n = n + len(split(getline(lnum)))
           let lnum = lnum + 1
       endwhile
       let g:word_count = n
   endfunction
   " Update the count when cursor is idle in command or insert mode.
   " Update when idle for 1000 msec (default is 4000 msec).
   set updatetime=1000
   augroup WordCounter
       au! CursorHold,CursorHoldI * call UpdateWordCount()
   augroup END
   " Set statusline, shown here a piece at a time
   highlight User1 ctermbg=green guibg=green ctermfg=black guifg=black
   set statusline=%1*            " Switch to User1 color highlight
   set statusline+=%<%F            " file name, cut if needed at start
   set statusline+=%M            " modified flag
   set statusline+=%y            " file type
   set statusline+=%=            " separator from left to right justified
   set statusline+=\ %{WordCount()}\ words,
   set statusline+=\ %l/%L\ lines,\ %P    " percentage through the file

Vim Wiki

The vim wiki plugin is surprisingly powerful. I've noticed quite a few people advocating the use of the zim desktop wiki tool (but, of course, it isn't edited in vim, even though there is a vim zim syntax support); I regularly use Mediawiki instances (and once played with tiddlywiki). The vim wiki plugin looks interesting; and, since I now use the vundle plugin manager, I may give it a try.

Some reviews I've seen for vim wiki:

Related Articles of Interest

Annotations

Question: What's a good way to 'highlight' bits of text that you know you need to fact-check/add to/etc. so that it's easily seen upon a reread? I've just changed the text color in programs I've used previously...but how to best do that in vim?

One answer: I first thought about using vim tags -- I have never used them before, but I've heard of them and it sounds like they do some things that might be useful.

In Vim the quickfix commands are used more generally to find a list of positions in files. For example, |:vimgrep| finds pattern matches. You can use the positions in a script with the |getqflist()| function. Thus you can do a lot more than the edit/compile/fix cycle!

  • But this vim-notebook plugin sounds much more straightforward and easy-to-use right off the bat:

This plugin has been created to annotate and aggregate key aspects, such as source code, documentation, notes etc, relative to tasks to be done. Annotations with referenced resources are stored into text files called notebooks under the folder $HOME/.notebook.

A typical usage scenario is:

  1. create a new notebook called issue_missing_refresh_of referenced_line
  2. open the text file containing key information
  3. select text of interest
  4. annotate selecting proper category and description
  5. repeat annotation for other interesting text
  6. open the notebook to have an overview of interesting information
  7. go to an entry of interest
  8. jump to the referenced text file
  9. repeat the exploration with other entries

Traditionally, I've just made my notes directly in the text, marking it with NOTES ;-)

This year, though, writing in Markdown, I might take the HTML commenting approach (as suggested in this pandoc google group). On the other hand, the vim-notebook plugin sounds pretty cool--being able to annotate things in a separate file and yet jump to them at will... neat!

Why use ViM?

Question: Is there a portable OFFLINE text editor that could be run from a USB drive? If so, would such a thing be safe for use on public computers or able to be secured? It doesn't need to be anything fancy.

One Answer: A very good text editor with a PortableApps version, lots of available, easily-manageable plugins and extremely good ergonomics is ViM (vi improved).

I would encourage you to see this summary of this year's nano-technology thread on ViM (that focuses on how ViM can be used for writing).

Why should you give this modal ASCII editor a try?

ViM color schemes

Other references

What about Emacs?

brookter wrote:

If you like the general approach of Scrivener but want to stay in plain text with keybindings like they are meant to be used (ie Vim...), you may want to check this out: it's basically an attempt to reproduce some of Scrivener's features using Vim. https://vimvalley.com/replacing-scrivener-with-emacs-and-vim/ Actually, it uses Evil mode within Emacs — this is a VERY GOOD THING. Evil mode (Vim emulation) gives Emacs the one thing it lacks, a decent text editor. (Ahem.)