My workflow, part 1
I keep getting asked how my setup works, how I use tmux and nvim over ssh… all that good stuff. …
In this post I’m going to talk about some old text editors you probably never heard of, what is modal text editing, and why people like it so much.
Like some of you, I got interested in programming fairly young. I started messing around with TurboC1 when I was a teenager, arguably, my first experience with an editor running in a “terminal” (MS-DOS).
I remember it being a really weird experience, as so far I had only used
Notepad.exe
to write some HTML.
Later on, I started learning some Linux, and had my first encounter with Vim (or Vi, can’t remember). I had to search on the internet how to use it, and this was at the time where you would ask pretty much anything and someone would RTFM you. I felt really dumb.
And that was my first experience with a modal text editor.
A modal text editor has multiple modes of operation, and the keys’ functions
change depending on which mode it is in.
While TurboC and nano
aren’t modal text editors, Vi and Vim are.
Without further ado, let’s get into the history.
In 1969, Ken Thompson, co-inventor of Unix, released Ed.
It was a line-oriented text editor, but it didn’t look like a text editor - you couldn’t even read the entire file and scroll it like we can do today:
Not very user-friendly, I agree.
The usage kinda make sense once you know it, though:
You’d type a
to go into insert mode and append some text to the file,
then CTRL+D
followed by Enter
to go back to command mode.
1p
would print the first line, w
would write the file, q
would quit,
and so on.
Still, I find it impressive that people used this to write software for many years.
Derived from Ed, Ex was released, almost 7 years later, in 1976. It was created by Bill Joy, co-founder of Sun Microsystems, you know, that one that created Java and Solaris.
It still had the line-oriented commands like Ed, but it also had an innovative
visual
mode:
Vi was released together with Ex.
Basically, vi
was the :visual
(or simply :vi
) mode within Ex,
and Ex is a mode within vi
as well.
💡 The attentive reader might have noticed that the initial screen of
vi
in the gif above saysVi Improved
. That happens becausevi
is, usually, a symbolic link tovim
:$ ls -lha `which ex` `which vi` `which vim` `which ed` .rwxr-xr-x 235k root 15 Jun 07:08 /bin/ed lrwxr-xr-x 3 root 15 Jun 07:08 /usr/bin/ex -> vim lrwxr-xr-x 3 root 15 Jun 07:08 /usr/bin/vi -> vim .rwxr-xr-x 5.3M root 15 Jun 07:08 /usr/bin/vim
Unfortunately, I couldn’t find a way to run “the actual vi” locally, as there’s no packages on any OS/Docker image I tried.
It lacked a lot of features, though.
For instance, it didn’t had a file tree or explorer.
What if you wanted to see the files in the current directory?
You simply needed to type !!ls .
, and the files will be listed in
that buffer.2
From there, you can search files (using /
) and open them by prefixing the line
with :e
, yanking it with yy
, and typing :@"
to execute the command.
Easy. 😉
In response to the limitations of Vi, in 1991, Bram Moolenaar3 released Vim.
Notice this happened 15 years after Vi was released. Vi was popular for many years, and Vim built on top of that by adding many features: multiple windows, splits, tabs, better syntax highlight, completions, support for customization via Vimscript, plugins, macros, multiple clipboards, a file explorer, and much more.
Nowadays, vim
comes pre-installed in most Linux distributions and in
macOS.4
Usage is basically the same as Vi, but a bit more user user-friendly, since you can install plugins to facilitate common tasks (like a fuzzy finder, for example).
Neovim, the latest of the lineage we’re exploring today, was released in 2014 - more than 2 decades after Vim. It was created by Thiago de Arruda, a fellow Brazilian 🇧🇷.
It is a drop-in replacement of Vim. Most Vim plugins are compatible, and the editing model is the same.
Some of the advantages of Neovim are:
All that makes Neovim feel a bit more modern, while maintaining the performance and features Vim users love.
I think most people would agree that modal editors are harder to use than “normal” text editors.
Vim’s editing model is rather complex, and the learning curve is steep. It’ll probably take you days to get comfortable with the basics5, like the movements, saving, quitting, search, etc. For instance, if you search for “vim cheat sheet”, you’ll find things like this:
Most of the images you’ll find contain tons of information, but are still missing features, as well as pretty much all the configuration options.
Vim is so unintuitive for the non-initiated, that failing to quit it is a running joke in the field, for decades.6
Giving this steep learning curve, and the fact that most professions probably won’t use most of its features, its rare to get recommended Vim if you are not in the software industry.
On the other hand, “regular” text editors are much more intuitive, and the
learning curve is much smoother.
You open them and can immediately do basic text editing:
Select with the mouse (or Shift
and arrows), navigate with the arrows,
and backspace and delete just work as they do outside the editor.
This user-friendliness and lack of surprises is the reason you usually get recommended7 non-modal text editors (say, VS Code) instead of Vim.
Incidentally, you were never recommended Ed, Ex, or Vi because you’re too young, probably.
Once you pass the steep learning curve barrier, you’ll immediately feel more productive than you would in a “normal” text editor.
I think that’s the major reason why people love it: they feel more productive.
But its not just about productivity. Other reasons people usually give include:
All that is why people still use and love Vim, and it’s why it is probably never going away.
I think here there are usually three personas.
If you want to start slow, run vimtutor
, and install a Vim plugin in your
current editor.
You’re probably looking for a distribution, and lucky you, there are many to choose from.
Some examples:
I have never used any of them, so I can’t do any specific recommendation here. Also there are probably more distributions than that.
Start with vimtutor
, then install one of these, learn how the shortcuts
(usually they have them documented), learn how to use marks, quick fix lists,
…
If you want to really learn it the hard way, start with vimtutor
, then open
Vim/Neovim, and start itrying to configure it as you’d like.
You might need to learn some Vimscript/Lua as well.
This is definitely the hardest way to learn Vim, but in my opinion, also the one that will give you more complete understanding of what’s going on.
There is a Neovim subreddit, a lot of dotfiles on GitHub, the sources of the distributions listed above and much more.
This is what I did, and after a couple of months my configuration is pretty much stable now, I find myself removing more things than adding, usually.
A different kind of post, I know.
The full story here is that I took some oratory classes, and in the last day I had to talk about something for ~10 minutes.
They had a preference for it to be something work-related, and since I was the only programmer there, I tried to find something I could explain in in the time I was given and, more importantly, something I wouldn’t have to give a lot of context about first. Bonus points if it was at least mildly interesting for them.
This post is what derived from my first drafts of the talk, adapted to the audience.
Anyway, I hope you enjoyed it, see you in the next one.
Funny side-story: I had no internet at the time, so I downloaded Turboc and a bunch of PDFs using the computers at my school, saved them to floppy disks, printed the PDFs at home and started studying there. Most of them where in English, and I barely knew a few words in English at the time. Still, I remember getting as far as writing a calculator. It was really hard and it would fail constantly. ↩︎
This still works in Vim and Neovim today, and you can use it to quickly add output of commands to the current buffer. ↩︎
Bram passed away recently. Rest in peace, and thank you for all your work. ↩︎
According to the internet, OpenBSD and FreeBSD come with vi
instead
of vim
. ↩︎
I recommend you start with vimtutor
to get a hand of things. ↩︎
I believe a non-zero percentage of people first heard about Vim in these jokes, so… Good job… I guess? ↩︎
Assuming non-programmers people actually recommend text editors to one another. ↩︎