Introduction to Bash, VIM & Regex

Paste Buffer and Insert Modes

Introduction to Bash, VIM & Regex

Check out a free preview of the full Introduction to Bash, VIM & Regex course

The "Paste Buffer and Insert Modes" Lesson is part of the full, Introduction to Bash, VIM & Regex course featured in this preview video. Here's what you'd learn in this lesson:

Within visual mode, James introduces the paste buffer, which allows for copy and pasting. Then James introduces insert modes for finer control over the opening of files.

Preview
Close

Transcript from the "Paste Buffer and Insert Modes" Lesson

[00:00:00]
>> James Halliday: Another fun thing you can do in visual mode, you can yank text. So here, born visual line mode. Whenever you delete something, which you can do a d or x from visual mode, it actually gets put into a paste buffer. So if you navigate somewhere else in the file, and you hit p, it gets pasted.

[00:00:19]
A way to do that without deleting what you're working on is to press y. So if you visually select something, press y and then you can go somewhere else and press p to paste it without deleting the original. So that's yank and cut. If you want to adjust the amount of indentation that you're using, there are a bunch of ways to do that.

[00:00:56]
There is, in fact, a .vimrc file that you can set. So if you wanna look at mine, if you like tabs, don't set this. But if you don't like tabs, if you like spaces better, you can do set expandtab. And every time you hit the tab character on your keyboard, it will expand out to be a certain number of spaces.

[00:01:17]
So, I have my vim configured so that every time I hit the tab key, I'll get two spaces of output. You can also configure it to do things like autoindent, which is a very good setting. This means that whenever you're in a line of code like I can show a line of code again.

[00:01:35]
So when I'm in an indented part of code, if I hit Enter again, I stay at that level indentation which is really handy. Another nice feature is there are other ways of getting into insert mode. If you press o instead of i, you go into insert mode and a new line will be placed after the current line.

[00:01:56]
And there's likewise capital O, which does the same thing but for the preceding line. So if I go into O, I'm now in insert mode and a new line has been inserted, the previous spot to where I was. But at the same indentation level, if you have r indent turned on.

[00:02:19]
>> James Halliday: Right, there's also one called A, which if you do capital A, it puts you in INSERT mode at the end of the current line, which is sometimes handy. And there's also a lowercase a, which puts you into INSERT mode, next character. Whereas INSERT mode will put you into INSERT mode at the current character.

[00:02:41]
So just like little worn off, quick ways to jump to the right spot in the file. I think it sounds maybe like this kinda stuff wouldn't really save you much time, but I don't know. I think that you can get muscle memory for doing this kinda stuff, it feels really satisfying.

[00:03:03]
I don't know how else to describe it but. [LAUGH]
>> James Halliday: Right, capital J is another good trick. If you wanna take this line and join it to the next line. If you do capital J, it sticks them together. So now, it just removed that new line, that's a really useful trick.

[00:03:26]
And back tick dot is really easy. So if I quit this file,
>> James Halliday: And I open it again and I do back tick dot, I jump to the last part where I made an edit. That's really hideous well if you are editing source files, and you wanna skip back to the last part of the file you were working on.

[00:03:47]
>> Speaker 2: Where does it store that?
>> James Halliday: I don't know where it stores it. [LAUGH] Good question.
>> Speaker 2: I was just looking, there's a vim info file in mine machine that I'm guessing that stores that.
>> James Halliday: Yeah, it seems like it. Yeah, cool, it is like all the places in the file.

[00:04:05]
That's neat.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now