Vim For Writers
Vim For Writers
Vim For Writers
Anthony Panozzo
This book is for sale at
http://leanpub.com/vim-for-writers
This version was published on 2015-02-08
Contents
1. Introduction . . . . . . . . . . . . .
Prerequisites / Assumptions . . . . .
Philosophy of Using Vim For Writing
Typeface Conventions . . . . . . . .
Vim Conventions . . . . . . . . . . .
Learning More . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2
2
4
8
10
10
.
.
.
.
.
.
.
.
.
.
11
11
12
13
14
CONTENTS
\pagebreak
1. Introduction
This book aims to quickly get you up and running with
composing and editing long-form and formatted documents with Vim.
I envision this book will be the most useful for programmers or developers who are already familiar with Vim and
who seek to use it for tasks traditionally associated with
word processor applications.
The advantages of Vim may also be a great reason for
technical writers or book authors to learn a new tool. I think
there are advantages to using any text editor for writing,
and the Vim ecosystem has many plugins that can make
your writing experience better.
Whether you are new to Vim or a veteran, try following
along with the examples in this book to get a sense of what
settings you like and will get the most use out of.
Prerequisites / Assumptions
Here are things that you should know or do prior to being
able to get the most out of the book.
Introduction
Introduction
Something to Write
It helps to have something that you want to write in order
to set up and practice the concepts in this book. Maybe
you have some blog posts that you have been thinking of,
or an idea for a manuscript. Having something that keeps
your interest will help make the learning curve easier. I
generally think this is the best way to learn new languages
or frameworks as well.
This entire book was written just using Vim. No other word
processors or text editors were used.
Introduction
Portability
One of the benefits of using a text editor like Vim for
writing is portability. You write documents using simple
text files or lightweight markup. These files can be easily
shared across operating systems and can be read by many
applications. Plain-text files are one of the basic building
components of Unix-like operating systems, and because of
this, there are many tools for manipulating plain-text files.
Vim is open source, which means that anyone can modify
the program and extend it. You dont need to worry about
not being able to read your file when a new version of
Vim comes out, since there are thousands of programs that
need to operate on plain text files. There are no proprietary
formats to worry about, and we will be able to read plaintext files as easily today as we will a hundred years from
now.
Speed
When you compare the time it takes to load up a traditional
word processing program to the time it takes to open a text
file in Vim, Vim wins hands down. My computer typically
gets bogged down for at least thirty seconds when loading
up a Microsoft Word or LibreOffice document, while I can
start editing within seconds with Vim. The cursor does not
skip or lag when I type in Vim, resulting in a feeling of flow
as the words pour smoothly onto the screen.
Introduction
Introduction
Extensibility
Vim has a variety of settings, and can be configured.
Many Vim plugins can be found on vim.org and on code
sharing sites like Github. This book will cover common
configurations and useful plugins for writing.
vim.org
github.com
Introduction
Caveats
Writing with Vim is not necessarily easy, but hopefully we
can mitigate any potential disadvantages with this book.
The flip side of extensibility is that you can spend inordinate amounts of time that would otherwise be spent writing fiddling with Vim configuration or publishing pipeline
scripts. I try to minimize this by focusing on having a writing goal per day. Maybe the goal is a few hundred words
a day. When I get that, then I give myself permission to
fiddle with my build scripts for a little while to streamline
the process.
Vim itself takes a bit of time to learn, so if you need to
brush up, it might diminish your effectiveness for a little
while. However, using Vim for writing is probably slightly
less taxing than using it to edit code since so much time is
spent in insert mode.
Like learning to touch type or other tools and techniques
with a steep learning curve, there is a period of lowered
productivity followed by even higher productivity. Stick
through the learning period and you will emerge with a
powerful writing tool.
Typeface Conventions
Throughout the book I use varying text types to more
clearly delineate some things.
Introduction
of code.
If the monospaced text is preceded by a dollar sign ($), it is
used to show things you would type at the command-line
console window:
1
$ ./run_some_script
:set someVimOption=true
10
Introduction
Vim Conventions
Where possible, I will use the expanded version of any
Vim commands. This should make examples clearer at the
expense of slightly more text. I recommend doing this
throughout your .vimrc file for better documentation. If
you want, you can use the abbreviations of them that Vim
recognizes to reduce the amount of typing you need to do.
Learning More
Whenever you want to learn more about a command, you
can invoke Vims internal help by typing :help <command>
when in normal mode.
2. Setting Up Vim to
Enable Smooth
Writing
Your .vimrc
Vim can be configured through a variety of commands.
You can invoke these commands by entering into command
mode and typing them out. However, once you have done
this a few times, you will probably want to save the
configuration changes somewhere.
At program startup, Vim looks in several files on your
filesystem for configuration settings. The most common
file to edit (and the one I will reference) is called the .vimrc
file. It typically lives in your home or documents directory.
For Linux and Mac OS X systems, it will be located at
/.vimrc. On Windows machines, it will be called _vimrc
and located wherever your HOME environment variable
points at. Of course, you can edit your .vimrc file with Vim.
Vim will not automatically save any configuration settings
you set. It will discard them at the end of each session.
In the .vimrc file you can type any commands you would
normally type in command mode in the Vim window and
12
:set foo=bar
set foo=bar
To test changes, you can source the .vimrc file with :source
/.vimrc to pick up the newly changed function, or close
Vim and start it up again (since Vim loads the .vimrc on
startup.)
If you make a mistake, you can always edit the .vimrc file
and revert the changes you made.
Set nocompatible
By default Vim starts in Vi compatibility mode, which ensures that Vim behaves exactly like the classic Vi. However,
since we are going to be using Vim features that are not
present in Vi to make your writing experience better, you
need turn off this setting. Ensure that your .vimrc contains
the following line near the top:
1
2
13
function! Writing()
" your calls go here
endfunction
14
Reducing distractions
One of the first things I would do to get a finely-tuned
writing program would be to turn off some non-essential
Vim functions to get a cleaner working space.
function! Writing()
set nonumber " Turn off line numbers
endfunction
1
2
3
4
5
6
15
function! Writing()
" Remove right sidebars
set guioptions-=r
" Remove left sidebars
set guioptions-=L
endfunction
This will tell you what file you are in, which line you are
on, what percentage through the document you are, and
what column of the line you are on.
Fullscreen mode
I generally like to have my Vim running in fullscreen mode
to try to get into the zone. Then, I can just focus on
writing.
16
1
2
17
:set guifont
guifont=Inconsolata:h20
or
1
guifont=Inconsolata\ 20
18
set guifont=*
This will open a dialog to select the font or list out the fonts
available.
With all of this information, it should come as no surprise
that you can set the font setting with something like:
1
set guifont=Inconsolata:h20