Vim
by Željko Filipin
TLDR
Vim is one of the two most popular text editors, the other one being Emacs.
The story
Before getting involved in the editor war, let me tell you a story.
As everybody else that writes code for living, I have used a lot of editors and IDEs. I liked some more than others. What was always intriguing to me was the fanaticism of Vim and Emacs users. I have tried both. For a minute. My first impression was what is this I don’t even…?!
I remember the times when I would type git commit
and end up in Vim by mistake. The only thing I knew was to very carefully close it with :q
.
The only command-line editor that I was able to use was nano.
Then, last year, while taking a look at the Ruby survey results I was surprised to see replies to the text editor of preference question. To summarize:
- Vim has gone from 17% in 2008 to 38% in 2015.
- Emacs varies around 5-8%.
- Textmate has gone from 57% in 2008 to 6% in 2015.
- Sublime has gone from 18% in 2012 to 36% in 2015.
Emacs being in single digit percentage did not surprise me. Texmate going down or Sublime going up did not surprise me. What did surprise me was Vim going up from year to year. What?! I have decided to spend some time and learn the basics. A few months ago I have carefully replaced editor in my .gitconfig
from nano
to vim
.
vimtutor
All I know about Vim I have learned from vimtutor
. I can not remember how I have stumbled upon it. Just start it from the command line:
The first page says:
The approximate time required to complete the tutor is 25-30 minutes
but that is a lie. You will need more time. As far as I remember, an hour or two. This blog post will cover just a few things from vimtutor.
Modes
What you will notice, if you end up in Vim by mistake, is that nothing works. You start typing. In best case, nothing happens. In worst case, you mess up the file entirely, or delete it. That is because by default you are in “normal” mode. Yeah, right, normal. Anyway, you want the other mode, insert. To change from normal to insert mode, press i. That is all. You will notice -- INSERT --
text at the bottom of the screen.
To change from insert to normal mode, press escape. If you are not sure what to do, press escape. That will get you to normal mode. Fortunately, there are no other modes.
Starting
It is simple: $ vim file-name
. If file-name
exists, you will start editing it. If it does not exist, you will get an empty screen.
Navigation
While in normal mode, you can move around with cursor keys and with h
j
k
l
keys. h
is left, j
is down, k
is up, l
is right. While in insert mode you can navigate only with cursor keys, of course. h
j
k
l
keys will type respective letters.
Exiting
If you have had enough, it is important to know how to exit. The usual things do not work. If you are in normal mode and you have not edited the file, just type :q
. If you are in insert mode, press escape to get to normal mode.
If you have made some changes, Vim will ask you what to do when you type :q
If you have made some changes, and you want to save them, exit with :wq
Also, how to exit vim: pic.twitter.com/ZneC27EYfw
— Nick Craver (@Nick_Craver) August 21, 2016
I've been using Vim for about 2 years now, mostly because I can't figure out how to exit it.
— I Am Devloper (@iamdevloper) February 17, 2014
.vimrc
You will probably want to tweak your Vim configuration file, .vimrc
. A good starting point is .vimrc at Vim Tips wiki. Also, feel free to take a look at my .vimrc.
More information
vimtutor
:help user-manual
- Vim Tips wiki
- Vimcasts (screencasts)
- Practical Vim (book)
Misc
- VIM Adventures (game)
- I will give a talk titled Vim for beginners or What is this I don’t even…?! at Terminal Zagreb Meetup #5 so now is a perfect time to put my thoughts on paper. I mean… You know what I mean.
- Prince (yes, that Prince) became a member of Jehovah’s Witnesses and occasionally knocks on people’s doors to discuss his faith.
- I gave a short overview of this post at Testival Meetup #29.
tags: code - event - featured - speaker - twitter - vim"How do you generate a random string? Put a web designer in front of VIM and tell him to save and exit." https://t.co/BH6lFNCCZl #dorscluc
— Željko Filipin (@zeljkofilipin) May 12, 2016