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

The "Wrapping up Vim" 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:

While wrapping up the course, James shows some tricks with Vim including inserting a file into another file; pipe commands within the editor; and remap characters for better editing experience.


Transcript from the "Wrapping up Vim" Lesson

>> James Halliday: More fun tricks. There aren't too many more of these, but these are choice tricks. So if you wanna insert another file into your current file. So a good example is if you got a little snippet of code you need to stick into the current file, you can totally do that.

So this is a bad example, but if I wanna stick in the package.json file into this file where I currently am, you can do :r space filename. And that just pastes in that whole file's contents, you don't have to copy it into your clipboard and paste it, you can just do it this way.

>> Speaker 2: Use pipe, [CROSSTALK]
>> James Halliday: You can, so to pipe the output of a command, you can do :r!, and then you can type a command in. So here I can paste the date command by doing :r!date, date command. So you can combine all of these ideas in different ways, so for example if I visually select some blocks of code, and then I wanna run that block through a command and display the output in the file, I can do from visual mode >r!wc -l, and then it will run, I guess you have to control c it or something.

Anyways, I think if you do it with :w maybe that would work. Anyways, there are ways to combine this kind of stuff. I think maybe I had some of those. Yeah, so if you wanna check out my vimrc file which is fantastic, it's in the notes. Otherwise, if you really like VIM, you can configure your terminal to work the way that VIM works.

So for example, here I'm in my terminal, right? I can hit Escape, I can hit K, K, K, K, K, J, J to go up and down. I can also do, I can do things like F space jumps to the space. I can do dollar sign, jumps to the end of line 0, so you enable this by typing set -0vi like that.

The default mode is Emax mode by the way, which is like all kinds like control the combos. I don't know even know how to use, but I know how use this one, cuz I VI, it's great.
>> James Halliday: So I see on the chat, there's can you paste the same line where your cursor is located if you select the complete line shift.

I don't know how to parse that exactly, but maybe I'll get to that later. Also, if you wanna remap your caps lock key to be escape, then I recommend that as well. It's fantastic, once you get use to them, it's right there next to your pinky, so you only gotta like move it a little bit.

It's really great.
>> Speaker 2: And you can do that just in vim.
>> James Halliday: You have to do that configure your operating system. So like on Linux you can use X mod map. I don't know what you do on Mac but, place in similar. There's also Ctrl+]. If you do that, I think you get out of escape mode, and you can also do Ctrl+C to get out of insert mode.

So sometimes that's easier than configuring your Esc keys. So that is what I have to present about them, and that's everything, so if anyone has any questions. I guess there was a questions whichl I will have to parse very carefully in the chat, but, okay, thanks.

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