Editing Files and Scripts with Vim | 2026 HPC Training Series #3

Everybody, welcome to the third workshop series for the HPC team this semester.

It is a session on VI or Vim. It is a popular Linux text editor. A little bit more on the history and what it is.

It is a screen-oriented text editor originally created for the Unix operating system back in the 1970s. And Vim, it's basically a free open source configurable text editor that expands a little bit on the Vim, but both of them are compatible. And main thing to remember about either one is that it's a modal editor, meaning that it has separate modes for inserting text, for issuing commands, and some other functions.

But it allows users to edit text rapidly in the Linux terminal. A little bit more on the history, if you're interested. Again, VI was created in 1976, designed as a lightweight Unix text editor, a standard on many systems.

And Vim just adds syntax, highlights, and plugins, and more functions, basically. Some of the differences in VI, it's a little bit more basic. So, you can do a single level undo.

It has a limited amount extensibility, and Vim has more features. Multiple undo's, it's highly configurable, powerful and modern, maybe. And if you ever worked with Linux systems before, maybe you're aware of other text editors, such as Nano and Emacs, and just to compare all of the three.

Emacs, very powerful, very customizable, but a very steep learning curve, in my opinion, more so than VI or Vim. With Nano, it's easy to use, but it does have limited features, and it's not always available in all situations. For instance, like if your system crashes, and you go into rescue mode, you might not have Nano.

And with Vim, it's fast and efficient, but sometimes for the beginners, it's a little difficult to get used to. So, you know, to reiterate why we are still using VI instead of Nano, or something that is more like a text editor on Windows, because it's installed in every Linux system. It works over SSH.

You don't need GUI. You don't need Xterm. And for system administrators, it is essential for servers in recovery mode.

Any questions? And I don't know if people are able to speak up, or if it's just the chat. People can do either one. They can speak on mute themselves, or they can talk in the chat.

Okay. Sounds good. So, you know, I think all of this so far, just like pretty self explanatory.

And for this class, our learning objectives, just to be able to use VI, Vim, efficiently, open and exit files, navigate, edit without getting panicked, and save, quit, recover from mistakes. And what did I want to mention? So, I'm already logged in to our Insomnia system. And I wanted to mention that on our system, Vim is just a shortcut to VI.

So, if you look it up, and you look at the actual Vim file, what happened? I don't know. I think my terminal is a little bit off. Oh, that's interesting.

Okay. Never mind. I'm gonna redo this.

And I'm gonna SSH into Insomnia. And this is something you're gonna do a couple of slides later also when you're getting into Insomnia. Let's move on.

I'm not sure what happened with my terminal here. But we don't need to cover the rest of the class today. And we can move on.

But actually, like, I do want to fix this issue. So, for the rest of you, you should be able to SSH into our Insomnia H3C cluster using your uni at insomniarcscolumbia.edu. And let me try to do it again on my end. And hopefully, you got the instructions and you set up the authentication.

Maybe I'm gonna do a new window. Yeah. So, if you're logging in along with me, you should be getting the password prompt and a do a push.

And, you know, I recommend that you just, like, press one for the text message instead of the phone call. And so, we're in the cluster. And for today's exercises, like, you don't need to be on our cluster.

But just, like, for consistency, if everybody can log in and copy the files in the exercise folder, I think that would be helpful. And so, in order to do that, let me know if this works for you. But we have some exercise files in Insomnia departments and intra-series VI workshop.

And if you attended the Linux workshop, you probably remember that copy-r means recursively copy all the files and directories. And wildcard means all the files. And dot means copy into the current directory.

So, I'm gonna do that right now. And I'm gonna copy all the files into my home directory. And because I practiced, it was already in my home directory.

But you wouldn't be getting prompted. Let me know. Because, again, it's difficult to speak and see what's going on in the chat.

Like, if anyone is having issues with the permissions or anything, please let me know. We haven't gotten any. Okay.

So, we copied over the files. And just, like, a quick demo of the important feature, how to create and exit a file. So, in order to create a file, you would type in VI or VIM.

And the name of the file doesn't have to be txt extension. This is just for demo purposes. And here we are.

A new file. How to quit. Without saving.

And we're skipping a little bit ahead. For the command mode, we're doing a colon and Q for quitting and exiting out of the file. So, circling back about the modes of the VI, there's normal mode for navigation and commands, insert mode for typing text, and command mode that we just used to issue other commands.

And generally, in insert mode, you can get to it typing in I or O to type above the line. And there's also a different visual mode that we will cover at the end that is also useful, in my opinion. And so, in normal mode, default mode for navigation, editing commands, moving around, deleting, copying, pasting, et cetera.

Insert mode, again, to type and edit text like a regular editor. And the keystrokes are inserted directly. And let me just like quickly demo again.

When I open the file, I'm in a normal mode. If I type in I, you see at the bottom that I navigate to the insert mode. And then I can type things in the file.

And let's skip ahead a little bit about the visual and command line mode. And so, in the past, the movement was just like keystrokes. But these days, you can just use arrow keys instead of the letters to navigate around the file.

But for the faster navigation, there are a bunch of shortcuts that we can do. And it is, you know, like once you learn it, it is a little bit intuitive. So, next word is W. If you want to skip ahead four words, it can be 4W.

And maybe you can follow along with me and look at the Columbia history file. And it's going to be clearer. So, if I just like press W in the normal mode, I'm moving ahead one word at a time, right? And if I do 4W, I'm moving ahead four words at a time.

To get to the top of the file, we can do capital G. To get off to the bottom, we can do capital G. So, for the top of the file, we can do one G. And the bottom of the file, we can do capital G. To get to the start of the line, zero. To get to the end of the line, dollar sign. And this we already mentioned a little bit.

So, insert mode I for inserting. A to insert after the cursor. O to insert on the new line.

Et cetera. And so, like we mentioned in Vim Editor, there are extra features. And whatever we did or typed can be undone if we go into the command mode and type earlier five minutes, for instance.

But we can also undo functions with just hitting U for undo. But let me demo this. And I'm just going to do one minute because I don't think we have gone well.

We didn't do any changes. So, not much to undo. What else is useful in the regular mode? Deleting characters with X. Deleting lines.

DW to delete a word. And again, you can combine all the commands. So, deleting two words, two DW.

And like we said, undo to undo. Copying lines with IY. And we can paste and replicate.

Questions? Nothing in the chat at the moment. Mm hmm. Okay.

So, I'm going to exit out of this file. And I'm going to use let's say like QW for write and quit. And I'm for demo purposes, I'm going to use the other file, the get story.

And I think it highlights pretty well how the search function works in the eye. So, when I'm in the normal mode, I can just hit the front slash and you see my cursor at the bottom. And it invokes the search function.

And let's say I want to look for a word cat in the file. And it will be highlighted everywhere. And when I hit N, I go to the next instance.

Navigating around. But also, you know, often if we program, we want possibly to replace the text in the text file. Like renaming a variable.

And how do we do that in VI? And for that, we would need to go into the command mode again. Which, again, heading column. And you see the cursor on the bottom.

And the regular expression for that is to do the dollar sign and ass and cat and let's replace the word with a dog. And we see that the first occurrence has been replaced. But maybe we just like we want to replace everything in the file.

And it's really easy to go back into the command mode. We have an app arrow to replicate our command. And we can just hit add the G at the end.

And all of the instances will be replaced. So, another useful feature, uh, setting line numbers, especially when you're programming. It's quite useful.

Again, it is something you would do in the command mode. And there's an abbreviation. You can just like do set and U instead of set number.

But the full command is set number. So, let's say I wanted to replace the words on just specific lines. And I'm going to go into command mode again.

And instead of cat, I'm going to say dog. And instead of doing the entire file, I'm just going to do lines two and three. And now we have the word changed back.

And of course, if you're familiar with regular expressions, it's really powerful. You can do a bunch of things in VI. And, again, you can do a lot.

For instance, this regular expression here, just like substituting cat with the two ampersands, it will make the first occurrence of word being replicated on every line. Or you can append text at the end of the line. And, yes, you know, like we cannot cover everything possibly in the class today.

But there's just a lot you can do. And, for instance, if you're programming in Python and you want to convert your variables, you can do snake case to camel case using regular expressions. You can delete blank lines, et cetera, et cetera.

And so, the last thing that I wanted to share today is visual block mode. And I find it quite useful myself in some cases. And we can look at another one of our files here.

Email list. So, you know, many ways to go about it. But, like, let's say I just I have a file.

I want to delete a bunch of spaces. Visual block mode is very useful for that. And in order to go into the visual block mode, I would hit control V. And, again, at the bottom, you see visual block.

And I can move my cursor. And it highlights space, right? And, like, let's say I want to delete. I would then hit X because X is a delete in VI, right? So, and extra spaces are deleted.

Or let's say I just want to comment out some of the lines like I would do in code. So, I would hit control V, move the cursor down, hit shift I, and the hash character for the line for the comment lines. A little bit more information.

Yeah. There's actually a bigger cheat sheet that is shared with you guys. But also, you know, you have this information in the slides if you want it.

And, you know, a little bit of humor at the end. There's there are a lot of Vim commands and shortcuts and things to memorize. But, you know, don't be like this guy and try to memorize all of it on your own.

There's there are always resources available. And just, like, looking it up. And I think that concludes our lesson for today.

Fall 2026

This workshop focuses on the VI/VIM Linux text editor, teaching beginner users how to use it efficiently for tasks like safely opening and exiting files, navigating, editing text, and recovering from mistakes. The session covers key concepts such as VI being a modal editor with separate normal, insert, command, and visual block modes, and demonstrates commands for file navigation (HJKL, W, B, 0, $, G), text manipulation (I, A, O, U, X, D, Y, P), searching, and replacing text using regular expressions. The material highlights that VI's value due to its availability on all Linux/Unix systems and the fact that it works over SSH without a GUI.