Files
hpr-knowledge-base/hpr_transcripts/hpr1737.txt

218 lines
14 KiB
Plaintext
Raw Normal View History

Episode: 1737
Title: HPR1737: Five Steps to Vim
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1737/hpr1737.mp3
Transcribed: 2025-10-18 08:26:43
---
This is HPR episode 1,737 entitled Five Steps to Vim.
It is hosted by Frank Mel and is about 22 minutes long.
The summary is, Frank Mel discusses how he learned to stop worrying and love the Vim.
This episode of HPR is brought to you by An Honesthost.com.
Get 15% discount on all shared hosting with the offer code HPR15, that's HPR15.
Better web hosting that's Honest and Fair at An Honesthost.com.
Hello, this is Frank Mel again, and today I want to talk about my five steps for getting
comfortable with Vim.
Vim stands for Vi Improved.
Vi is one of the oldest editors in the next world.
According to an interview I read at one time, it was composed over a time share, over a
300-bar modem, and some of the things that people find intimidating about Vi and Vim come
from that.
It has an extremely terse command set.
Once you understand it, the command set makes sense, but the command set is also very
different from those of editors that came later, and certainly different from GUI editors
where everything is done from the menu.
Plus, it has no menu, so you have to know or have a good reference to the commands.
If you want to learn how to use, and I'm going to focus on Vim, so I'm going to save
Vim from now on.
If you want to learn how to use Vim, you pretty much have to have a cheat sheet.
Whether it's a printed cheat sheet or one on your display, you need a cheat sheet.
If you go to a web search for Vim cheat sheets, you will get overwhelmed.
I've got one in my hand that is three pages long of densely packed commands.
If I try to consult that cheat sheet for every single thing I want to do in Vim, I don't
get anything done because I'm spending all my time in the cheat sheet.
Why should you learn Vim?
Well for one thing, Vim or Vi is everywhere in the next world.
If you install a distro, the Izar is going to have the Vi text editor or the Vim text
editor, or as the case with Slackware, both of them.
In fact, I think Slackware has every text editor known to Linux in it.
Others such as Magia, the Vim has Vim, and if you type in the command Vi for Vi, it's
aliased to Vim and Vim starts.
But the people who package Magia know that Linux users expect to find Vi.
So they made a provision to give them an editor when they type the Vi command.
Also, it's just a really, really geeky thing to do to be able to edit and compose text
in Vim.
It's very satisfying bit of learning once you get there.
But again, going back to the cheat sheets, you look at these cheat sheets.
There are so many trees you can't see the forest.
So I'm going to try to demystify this by saying, by mastering a few simple commands,
you can become comfortable using Vim.
And once you become comfortable, if you remind you, you can go on to be proficient.
I certainly hope that this podcast will supplement the excellent series that Dave Morris is doing
called Vim Hints, and I'll have a link to that series in the show notes.
I've already learned stuff that in 10 years of using Linux, I didn't know about Vim
just from his first, and particularly his second episode of that series.
I also want to say that I'm heavily indebted to Linux Voice for getting me onto the road
of becoming comfortable using Vim.
There was a tutorial in issue 1 of Linux Voice, which is now available under CC by SA.
And I will link to where you can download issue 1 of Linux Voice.
And also, the Linux Voice staff did a video available on YouTube and on the Linux Voice
site, which although not by any means intended to be a tutorial, showed me some of the things
that you can do with Vim and Vim and spurred me to come up with a strategy for getting
better at it.
I shared that strategy in my previous podcast, and that was to use MUT for my email with
Vim as the editor for composing and replying to emails.
I didn't do that on all my machines, but I did it on a couple of them, and it put me
in the position where, instead of using Vim, once or twice in a blue moon to say, for
example, edit my FCF staff file, or put a new line in RC.local.
I was using it every day, almost every day, usually several times a day.
And simply by having that opportunity forced onto me, I got better at using it.
So here are my five steps to being comfortable, not proficient, but comfortable with them,
or subtitled how I learned to stop worrying and love the Vim.
Just create a dot Vim RC file, and you can use the dot Vim RC file to manage the start
up options that are displayed when you start Vim.
I stole mine quite unashamedly right from Linux Voice.
And what mine does is it using the Vim set command, it displays a ruler, showing the
position of the cursor, line numbers, a status line, ensures that when I search for something,
the search results are highlighted.
I'm not going to bother to parse the syntax, you can watch the Linux Voice tutorial, and
see that file created.
And again, I said, I just stole it, I have not gotten into changing it any, but if you
do a web search for dot Vim RC files or Vim RC files, you will find many persons who
have posted their RC files to the internet.
So that's step one.
Step two is understand and learn how to change modes in Vim, and Dave Morris gave an excellent
explanation of this in the first podcast of his Vim Hint series.
Vim is a modal editor, it has two modes, what's called normal, or sometimes called command
mode, Vim starts in command mode, and in command mode, you can pretty much do everything
you need to do to manipulate text, except type text into the file.
You can delete text, you can copy text, all kinds of stuff like that, you just can't
type it.
To go into insert mode, you press the escape key, and then the letter I, lowercase I on
the keyboard, you're in insert mode, and then you can start typing text from whatever position
the cursor is at at the time.
To go back into command mode, say you want to save the file, or you want to copy some
text and paste it somewhere else, just hit the escape key.
Now for step three, some of the tutorials that you will see about using Vim will say
that you really should learn how to move the cursor about using the HJK and L keys.
H for one space to the left, J for I think up a line, K for down a line, and L for one
space to the right.
Don't worry about that.
If you don't feel comfortable trying to learn a new way of navigating the cursor when
you're also trying to learn a whole bunch of other new stuff, just use the arrow keys.
One of the most proficient Linux users I know, a fellow who administers a complex Linux
network, who has been using Unix and Linux for 25 years, at least maybe longer.
I'm not exactly sure when he started, was saying the last time we were discussing Vim,
that he never was able to get used to using the letter keys to move the cursor.
We just used the arrow keys.
I figure if it's okay with him, as I say, the most proficient Linux user I know, it's
okay for me and it's okay for you all.
Don't add one more thing to try to train your fingers to do when you're trying to grapple
with this much larger thing.
Step three, don't try to learn all the commands.
There are approximately ten or twelve commands for deleting text.
There are two X commands, lowercase X and uppercase X, and a whole bunch of commands that include
the letter D for delete, plus a modifier to modify what gets deleted.
The ones I find that I use most commonly are X to delete one character.
So if I'm in typing mode and I instead of typing HPR, I type HPRY, I can press escape,
then position the cursor over the letter Y, and then press the X key and make the Y go
away, then I press escape I, and you can go back to whatever I was typing.
When you get to the D commands, all the permutations on the D commands have to do with what's
your deleting.
Are you deleting a word?
Are you deleting from the cursor to the end of the line, from the cursor to the beginning
of the line, stuff like that?
You don't have to learn all that stuff.
You can do quite well, and again, this is to get comfortable, not proficient, with DD
for delete this here line that the cursor's on, and DW, which means to delete this here
word the cursor's on.
If you can use X, DD, and DW, you can do all the deleting that is necessary in a typical
look text file, such as the body of an email or a draft for a letter to the editor of
your local rag.
I write letters to the editor of my local rag occasionally, occasionally they even get
printed, although I'm not really as crazy as some of the letters they do print.
So that's three commands to delete text.
There's also a whole range of commands that include the letter C for change.
There's only one you need to worry about to become comfortable using them, and that
is CW, which means change word.
So you hit escape, so you're in command mode, position the cursor at the word you want
to change, type CW, that will delete the word that's on the line and puts you in insert
mode so you can type your new word.
Similarly for copying, and copying in them is referred to as Y, which stands for yank,
you yank the line to the clipboard.
There's the whole raft of the Y commands for copy this word, copy this line into this
line from here to there, up and down and so on, and copy and dance and spirals, all kinds
of permutation to the Y command.
The one that I have found sufficient to my needs as a VIM GINNER is YY, which means copy
this line to the clipboard.
I'll tell you how I commonly use it.
One of the things I'm frequently editing in VIM is my fluxbox menu, and if you've ever
used fluxbox or a similar window manager, you know that there are no GUI tools for editing
the configuration files.
You edit the configuration files with a text editor.
Say I'm installed a new program, I want to add it to the menu, I open up the menu file
in the editor, position the keyboard, position the cursor where I want it to be, and type
the command for starting that program from the menu.
Then I save the file I test it.
Now I have all the way I arrange my fluxbox menu as I have categories such as multimedia,
cyberspace, office, games, stuff like that.
Then down below those, I have a list of my 8 or 9 most frequently used programs.
So after I make sure the line is working, and under the appropriate category, I will
type escapeYY and copy that line to the clipboard, then navigate down to where I want it
in my most frequently used programs list, and I will paste it.
And for pasting one of two commands, lowercaseP to paste below the line you're on, uppercaseP
to paste above the line you're on.
There are many other commands you can use for various copy and paste routines.
You can copy a word, you can copy from here to the end of the sentence, and so on and
so forth.
So day to day writing, I found that YY, combined with the 2P commands for pasting, is enough
to feel comfortable.
It's also nice to know the undo command.
It's not really essential because with the delete commands and the insert text command,
you can do it undo in that way, but sometimes what you've done is so grievous you want to
use the undo command, and again, there are permutations on it, but the one I find is adequate
for normal use is escape, and then colon to open the command line at the bottom of the
Vim window, the Vim command line, not the Linux command line, and then you lowercase
you, and that will undo your last change.
If you find yourself doing a lot of unused undo last changes usually enough for the typical
email and stuff of that nature, and finally saving quit.
To save a file, after you've made changes, you hit escape, colon, the little Vim command
line opens at the bottom, and type W for write.
You're writing the file, and I do remember, although I was not using computers back in
the early days, I knew some of the folks who worked in the Unix test center at my first
major employer, and they used to talk about writing files.
They didn't talk about saving files.
To quit, if you just want to quit, you've saved the file, and you want to quit, it's escape
colon Q for quit.
If you want to save in quit, it's escape colon WQ.
You can combine the commands, escape colon WQ for write and quit.
If you want to quit without saving, it's escape colon Q exclamation mark.
So that's what I've got here, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 commands, and one command
that combines two of those, the WQ.
You don't have to go out and learn, though, those hundreds of different permutations on
these commands.
I find with these 11 commands, I'm comfortable using them.
And once you get comfortable using them, you can then learn the other commands as you
need to.
I've finally gotten used to using for delete DW.
I'm sorry, D dollar sign was the least to end of line, and because I wasn't overwhelmed
with lots of other stuff, I can remember that, and remember it quite easily.
So that's for the fifth step of becoming comfortable with them.
And the most important step is to use it to write stuff.
If you don't want to use it for an editor for your email client, you don't want to use
it say to draft a document that you might later put into a word processor and format
for publication.
Use it to do the outline and the show notes for the podcast that you are going to record
for HPR.
Thank you very much.
We are a community podcast network that releases shows every weekday Monday through Friday.
Today's show, like all our shows, was contributed by an HPR listener like yourself.
If you ever thought of recording a podcast, then click on our contribute link to find
out how easy it really is.
HECCA Public Radio was founded by the digital dog pound and the infonomicum computer club,
and is part of the binary revolution at binrev.com.
If you have comments on today's show, please email the host directly, leave a comment
on the website or record a follow-up episode yourself.
Unless otherwise stated, today's show is released on the Creative Commons, Attribution,
ShareLive, 3.0 license.