Files
hpr-knowledge-base/hpr_transcripts/hpr1734.txt
Lee Hanken 7c8efd2228 Initial commit: HPR Knowledge Base MCP Server
- MCP server with stdio transport for local use
- Search episodes, transcripts, hosts, and series
- 4,511 episodes with metadata and transcripts
- Data loader with in-memory JSON storage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 10:54:13 +00:00

302 lines
18 KiB
Plaintext

Episode: 1734
Title: HPR1734: Vim Hints 003
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1734/hpr1734.mp3
Transcribed: 2025-10-18 08:23:51
---
This is HPR episode 1,734 entitled Vim Hints 3 and is part of the series Vim Hints.
It is hosted by Dave Morris' and is about 26 minutes long.
The summary is Hints and Tips for Vim users Part 3.
This episode of HPR is brought to you by an honesthost.com.
Get 15% discount on all shared hosting with the offer code
HPR 15. That's HPR 15.
Better web hosting that's honest and fair at An Honesthost.com.
Hello everyone, this is Dave Morris and today I've got Vim Hints number 3 and this being
the third show in a series we can now create a series on HPR for it.
In this episode I want to look at moving around in the file that you're editing.
I also want to add a few more things to the configuration file that we started
constructing in the last episode.
Moving around is one of the very powerful things you can do in Vim and we'll
see in future shows how you can link this with other actions.
Some of the basic things you can do to move around, we've already seen some extent.
All of these movements are done in normal mode.
That is the mode you're in when you first start up Vim.
You've got the LKJ and H keys that we looked at before.
These are the mid row of your keyboard.
L means go right, unfortunately, it always confuses me.
JNK are down and up and H is move left.
Somebody said remember the sequence by thinking of the J as a downward pointing arrow
and that should anchor the group.
I don't know if you would find that useful.
I find it slightly useful, it helps me.
I tend to use the cursor keys myself and of course the cursor keys are the
alternative to these movements.
But today we've also got a few more that we're adding to this group
and that is the first one is the dollar key.
If you press the dollar key it moves your cursor to the end of the line
and that's the end meaning the last character on the line.
So some editors, at least in the midst of time, would assume that your line was
80 characters along with position U2 the 80th character.
But if the line in your editor is only 10 characters long then
there is no 80th column so as far as VIMT Concerned
so it would position you to the 10th character.
The alternative to the dollar key is the end key
and the one in the keypad with the home page up page down in Sir Delete.
So the next one is to move to the start of the line
that is character one and that's the zero key
and the alternative to that is the home key.
Now sometimes you might want to move, there might be some spaces at the start of
the line, you might want to move to the first non space character
winding non tab character if that's the case.
And the up arrow or circumflex will do that.
I call it up arrow I suppose it's not really that at all
but it's an ingrained habit. People used to refer to it that way back in the day.
The minus and plus keys are the last two in this group.
Minus key moves up one line and positions the cursor on the first
non blank character. The plus key moves down one line
which is you can think of them as decrementing and incrementing the line
number moves down to the first non blank character.
Now in the notes I've pointed out that when you're writing these things down
you can refer to them as sort of meta symbols
the characters I'm talking about and this is what's done in the VIM
documentation. So a less than sign a U and a P capital U P
a greater than sign means the up key the cursor up key.
So there's a lot of them that are documented in this way.
The only real reason that I'm mentioning them is because that's what I'm using
now from now on in my notes and also it's what the
the documentation uses and it will be of relevance when you come to
build up your own key sequences which VIM is very very very configurable
and you can build your own key sequences to do a
manner of things. The only other thing to say about this really is that
if you want to talk about these keys in conjunction with
shift or control that is hold the shift key down and press this key or hold the
control key down and press it then you put an S for shift
inside these angle brackets as I call them
or a C for control. Okay I don't want to spend too long on that it's not
that important it's really a documentation thing rather than a
podcast thing. So these movements don't seem to be very exciting
many other editors will let you move up down left right etc
but VIM has got the added feature that you can put a number on the front of
each of the commands so if you typed one zero
L then it that what that means is do the L command 10 times
which means move 10 characters to the right. You could also type in one zero
and then press the the right arrow key the right cursor control key
and that would do the same thing and the same goes for all of the other
characters looked at 10h 10 left key 10k or 10
followed by the up cursor key. The only ones in the group we've looked at
that don't take account are the zero or the home
command because it doesn't make a lot of sense to go to the start of the line
multiple times I guess and the circumflex similarly similar argument.
So these things are nice you can whiz around lines and between lines and
this sort of thing pretty easily in VIM and we'll look at
in future shows lots of other things that let you move around
according to many other features of your file. We're going to start on
some of these I suppose you could call them sort of object movements
you're moving in relation to certain objects within the
within the file. We'll look at word related movements.
Now there are a group of commands in VIM which let you move the cursor in relation
to words in the text but then we reach a slight difficulty
difficulty in terms of description really. I think if you read the show notes
you'll find that this is pretty clear but it's not an easy thing to
talk about in a podcast because we need to define what a word is and
there are in VIM there are two definitions and it refers to them in the
documentation as lowercase word WRRD and uppercase word
they mean two different things now how on earth can I
without saying uppercase lowcase all the time it gets a little confusing
it's not easy to talk about so what I'm going to do is just talk them about
them as word objects and what I think I need to do is to try and describe
why VIM is seeing these two different things. Now I've put the definition from
the VIM documentation into the notes to try and clarify this but
really in essence if you're moving by the lowercase form of the
word the simple word object then you're moving in a way that
you would expect to move so if you have say a word which is
enclosed in quotes then and your cursor is on the first
quote and you want to move to a word well the word is
that thing that's inside the quotes then if you move again
the word is the closing quote so it's stopping everything which is
which can be defined as a word or a word boundary but if you're looking at the
other word object the one that's written down is an uppercase word
then it would skip right over the punctuation and the criterion for
starting end of a word is whether they're separated by
white space white space being that generic term that means space tab
end of line so the the ones in lowercase that the reason these these two
definitions are in uppercase because the commands are in uppercase will come
on to them in a moment and the lowercase ones move
in relation to what you'd expect to happen in terms of
moving from one element of the text
delimited element of the text to the next whereas the the uppercase thing
is moves in relation to the boundaries between
white space all right I think I've just proved that it is hard to explain this
so the the commands that we're we're going to look at here are
w e and b now w just talk about the lowercase one
moment it moves forward to the start of a word
lowercase e moves forward to the end of a word
lowercase b moves backwards to the start of a word
so you see you can jump around a line pretty effectively just using lowercase
versions of w e and b I think you need to experiment with these things
yourself to see how they work it's really quite difficult to explain
if you use the uppercase version uppercase w
uppercase e and uppercase b they do the same
general things just that they stop on different boundaries
I do have an example in the notes where i took a
a line out of my log file i just plugged in my
mp3 player came up on dev sdh and i got an error message in
log file which talks about the fact that the the mp3 player is a
fat file system and it's moaning about aspects of this
i used it because it had hyphons and brackets and colon and comma and stuff
in it and i thought it would be a useful thing to
you demonstrate commands and movements on i made a little diagram of
where the cursor would be after certain movements
and i used the circumflex to point up to the
the line in question i don't know how useful that is
i find it a little difficult to read because the circumflex is not very
obvious character if i need better glasses i don't know
but i also wrote it out in text as as clearly as i could
i'm not going to read this because i don't think it's a
it's a fantastically useful thing to read out on a podcast
so the thing i haven't said is that of course all of these movement
commands can be preceded by a numeric count so five w
means go five words forward and five b means go five backwards and so on
my examples use counts and of course the other the other factor
that i haven't mentioned is that or the two two forms of w and the two
forms of b both have counterparts using the cursor keys
so shift right is the same as lower case w control right is the same as
uppercase w shift left is the same as lower case b
and control left is the same as uppercase b the ease don't have anything
in the way of cursor controls so i guess that's yeah it's
personally i tend not to use the cursor keys for these types of
movements i would be using the w e and b
and out of a band and the the cursor keys so really i should teach myself to
use the h j k business so i think i've said before
okay that's that's all i'm going to say about movement
today i hope it's pretty clear both the way i've expressed it and also the
the notes any feedback on this side of pre-shed because
this is i know a difficult area since we're using audio only here
and i plan only to use audio now we're going to move on to looking at the
configuration file so in the last episode
i told you about the command set compatible set back up
set undo dear to point to a directory and set undo files which on the
the persistent undo feature today we're going to look at a few more things
and the first one is adding a ruler a ruler is a is a display at the bottom
the screen that gives you information about stuff
and you enable it with the command in your config file set
space ruler that's s-e-t space i-u-l-e-r and this causes the line and column
number of the cursor position to be shown at the bottom right of the screen
the two numbers are separated by commas
and if there's enough room then the relative position
the cursor in the in the text is not so much the cursor actually the displayed
text because you you've got to view into a larger
thing through a window effectively and that's shown
so if your the file you're looking at is
positioned so that the top of the file is visible then the word top is appears
in the ruler if it's positioned so that the last line is visible then
b-o-t bottom is is written in the ruler
and if you can see both the top and the bottom because it's just a small
file then all a-w-l is is in the ruler
and if you've got a much bigger file and you're somewhere else in it
then a percentage number will be put to the to the right of the ruler
now the set ruler command can be abbreviated to s-e- space
I think I would discourage you from doing that unless you really want to
because you're going to get very confused by all these abbreviations if you're
not careful I certainly am so you might be clever than me but I don't know
I prefer to use the full form anyway you can switch the ruler off
if for some reason you you want to to disable that
then set no ruler will switch it off there's not much point in having that in
your config file so remember these are commands so you can in normal
mode you can press the colon key and then type the
command so colon set space no ruler will switch off the ruler
temporarily so sorry about the noises off I'm sitting in my kitchen
with the door open and you can hear the ambient sounds outside maybe
don't know one thing is and it will probably be getting on to this later
you can customize the ruler change its layout the layer I mentioned is the default
the other thing I found when researching so I haven't quite appreciated before
is that a number of Linux distributions set this option for you
when you install them it comes with system wide config which sets various things
I run Debian Testing and there's a set
ruler definition I found in one of the the config files provided in the
package I put the path in case you're interested in the notes what I
want really that I think it's a good idea to set this in your config file
because you then have a config file that you could move elsewhere
possibly to a system that doesn't preset this for you so now we've got we've
got the ruler but the ruler doesn't look particularly
nice it's just sitting on the bottom line and that line's also used for
entering commands and things so there's another feature which is a status line
and normally when you're running VIM in its very default mode the whole
windows available to you except the last lines we just mentioned
and in there you'll get messages and you'll get that's where you put your
commands but you can open this up a bit using the command set
last status now if you set that to equal to set last
state status equals to then it will produce a
another line over the top of that command line
which is in inverse color usually black white and black actually I think
though again you can configure that change colors and all tools
so fancy things the status lines got the the name of the file being
edited in it and if you've enabled a ruler that's where the ruler will go
and that's actually quite a nice layer that's what would be my default
there's a picture in the in the notes which shows what that looks like
the only thing is that in the original days of the eye
when it was developed on hardware terminals which were 24 lines by 80
columns then taking away two lines at the bottom might have been a bad idea
but today we will have enormous monitors we can
create terminals virtual terminals of any old size we like pretty much
then I don't think it's a big deal the command can be abbreviated I won't
go into what it is it's in the notes
and you can switch it off with set space last status equals zero
final command that I'm going to add this time is the set show mode command
which shows what mode you're in you remember
vims a modal editor with many modes some of which we've
yet to look at and it doesn't tell you which mode you're in
by default setting this option show mode will
give you information about the mode you're in if you go into insert mode for
example and various other modes
now in my case again Debian testing has set this for me
but I still like to put it in my config file I've said in the notes that
with show mode enabled and when you're going to insert mode you get a little
message at the bottom of the screen that indicates you're in insert mode
you can switch this off set no show mode if you want to
you could do that temporarily during an editing session if you wanted to
the final point about the config file is to
point out that you can put you can interspersed blank lines
in your in your config file and that's often a good thing because it makes
things more readable you can and you can also group
related commands together and you can also add comments and a comment is
a comment character think that opens a comment is is a
double quote character a double quote is usually put in the first column
and then you would type a comment after it so in the notes there's a
screenshot as I mentioned before showing in fact me editing the notes
in markdown format and it's got a ruler it's got a status line
and I think it's the point which I just opened the file up so
there's a little message at the bottom that reports the file name
it's length and the number of characters so which is at that point somewhat
longer than the maximum it's even longer now
so that's it really in terms of the content this week
I wanted to just mention at the end that I've
going to the habit putting a summary at the end of these these notes
hopefully so you can go and have a quick look at
the commands we've covered and there's one there for
the various movement commands we've looked at
and there's also a list of the contents of the configuration
file that I have constructed for this this particular show
with all the commands we had before and the new ones with blank lines and with
comments so I hope you'll find that that is helpful
and that I've just got links in the end there pointing to the previous two
shows and I'll try and continue to do that so you can hop around between
shows if you ever want to refer back to anything
but hopefully once we've got it set up as a series you can also walk through
the series I'm hoping other people might like to
contribute to the the VIM series at some point in the future as well
which would be nice so that's the end of it that's all from me
speak to you again soon bye-bye
you've been listening to Hacker Public Radio at Hacker Public Radio.org
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 HBR
listener like yourself if you ever thought of recording a podcast
then click on our contributing to find out how easy it really is
Hacker Public Radio was founded by the digital dog pound and the infonomican
computer club and is part of the binary revolution at binwreff.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 status
today's show is released on the creative comments
attribution share a light 3.0 license