Editors

Importance of Editors

As programmers, we spend most of our time editing plain-text files. It’s worth investing time learning an editor that fits your needs.

How do you learn a new editor? You force yourself to use that editor for a while, even if it temporarily hampers your productivity. It’ll pay off soon enough (two weeks is enough to learn the basics).

We are going to teach you Vim, but we encourage you to experiment with other editors. It’s a very personal choice, and people have strong opinions.

We can’t teach you how to use a powerful editor in 50 minutes, so we’re going to focus on teaching you the basics, showing you some of the more advanced functionality, and giving you the resources to master the tool. We’ll teach you lessons in the context of Vim, but most ideas will translate to any other powerful editor you use (and if they don’t, then you probably shouldn’t use that editor!).

Editor Learning Curves

The editor learning curves graph is a myth. Learning the basics of a powerful editor is quite easy (even though it might take years to master).

Which editors are popular today? See this Stack Overflow survey (there may be some bias because Stack Overflow users may not be representative of programmers as a whole).

Command-line Editors

Even if you eventually settle on using a GUI editor, it’s worth learning a command-line editor for easily editing files on remote machines.

Nano

Nano is a simple command-line editor.

Vim

Vi/Vim is a powerful text editor. It’s a command-line program that’s usually installed everywhere, which makes it convenient for editing files on a remote machine.

Vim also has graphical versions, such as GVim and MacVim. These provide additional features such as 24-bit color, menus, and popups.

Philosophy of Vim

Introductory Vim

Modes

Vim shows the current mode in the bottom left.

You change modes by pressing <ESC> to switch from any mode back to normal mode. From normal mode, enter insert mode with i, visual mode with v, visual line mode with V, and visual block mode with <C-v>.

You use the <ESC> key a lot when using Vim: consider remapping Caps Lock to Escape.

Basics

Vim ex commands are issued through :{command} in normal mode.

Movement

Vim is all about efficient movement. Navigate the file in Normal mode.

Selection

Visual modes:

Can use movement keys to make selection.

Manipulating text

Everything that you used to do with the mouse, you now do with keyboards (and powerful, composable commands).

Resources

Customizing Vim

Vim is customized through a plain-text configuration file in ~/.vimrc (containing Vimscript commands). There are probably lots of basic settings that you want to turn on.

Look at people’s dotfiles on GitHub for inspiration, but try not to copy-and-paste people’s full configuration. Read it, understand it, and take what you need.

Some customizations to consider:

Advanced Vim

Here are a few examples to show you the power of the editor. We can’t teach you all of these kinds of things, but you’ll learn them as you go. A good heuristic: whenever you’re using your editor and you think “there must be a better way of doing this”, there probably is: look it up online.

Search and replace

:s (substitute) command (documentation).

Multiple windows

Mouse support

Macros

Extending Vim

There are tons of plugins for extending vim.

First, get set up with a plugin manager like vim-plug, Vundle, or pathogen.vim.

Some plugins to consider:

Lists of plugins:

Vim-mode in Other Programs

For many popular editors (e.g. vim and emacs), many other tools support editor emulation.

There are even vim keybinding extensions for web browsers, some popular ones are Vimium for Google Chrome and Tridactyl for Firefox.

Resources

Exercises

  1. Experiment with some editors. Try at least one command-line editor (e.g. Vim) and at least one GUI editor (e.g. Atom). Learn through tutorials like vimtutor (or the equivalents for other editors). To get a real feel for a new editor, commit to using it exclusively for a couple days while going about your work.

  2. Customize your editor. Look through tips and tricks online, and look through other people’s configurations (often, they are well-documented).

  3. Experiment with plugins for your editor.

  4. Commit to using a powerful editor for at least a couple weeks: you should start seeing the benefits by then. At some point, you should be able to get your editor to work as fast as you think.

  5. Install a linter (e.g. pyflakes for python) link it to your editor and test it is working.


Edit this page.

Licensed under CC BY-NC-SA.