---
title: "Vim file open save, load, moving, changing and selecting text"
url: "https://courses.osherove.com/courses/vim-hates-you/vim-file-open-save-load-moving-changing-and-selecting-text.md"
canonical: "https://courses.osherove.com/courses/vim-hates-you/vim-file-open-save-load-moving-changing-and-selecting-text/"
tags: []
author: "Roy Osherove"
description: "Lesson 2 of 26 in Vim Hates You (Get Somewhat productive in an hour or so), 7:04. Free video by Roy Osherove."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Vim file open save, load, moving, changing and selecting text

1. [Courses](https://courses.osherove.com/#courses)
2. [Vim Hates You](https://courses.osherove.com/courses/vim-hates-you/)
3. Get Somewhat productive in an hour or so

Lesson 2 of 26

Duration: 7:04 [Watch on YouTube](https://www.youtube.com/watch?v=dEsp5YTF6u8)

## In this lesson

Starting Vim from the command line, Roy writes a hello world file in insert mode, saves it with a colon, w and a file name, and quits with a colon and q, or writes and quits with wq. In what he calls navigation mode he adds lines with o and Shift-O, moves with h, j, k and l and by words with b and w, and undoes with u. He changes text by selecting it with v or Shift-V and pressing c, or with cw and ciw for change word and change in word.

## Transcript

1,154 words

[\[00:12\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=12s) Let's start Vim up. We just type vim in the command line. Press enter. And this is the main screen of Vim. And what we're going to do first, we're just going to write a simple hello world text file. And the way that you enter into writing mode in Vim is you type I for insert mode. And now you can see at the bottom here that we're in insert mode and I can type hello world. Now if you want to get out of insert mode and save stuff, you press escape. And now you can see we're no longer in insert mode.

[\[00:43\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=43s) If we actually want to save the file, we use a special command line mode which is the colon mode. So you type colon. You see at the bottom we can now type a command and there are many multiple commands. many multiple really for example if you want to write you just say w now if I just type w now I'm going to get an error it says oh no file name to save so let's type colon w hello hello world and I'm going to type enter

[\[01:15\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=75s) And now I can see that there's a file called hello world now let's say I want to quit vim and I want to see the file so how do you quit vim you type colon and Q for quitting. And now what we can see is that if you type ls here, we have a file called hello world. If I show the contents of hello world, you can see that's the content. So let's try to edit the file again. So I'm going to type vim hello world.

[\[01:47\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=107s) And you can see that I am in the file again. And I can change the text. But how do I change the text? Well, obviously I can press I and then I can move about with the arrows, but that's not the way Vim is really really designed. You see, the way Vim is designed is to kind of give you a surgical like precision attacking your code. So, let's say I want to add a new line. There's a special command for that. So, I'm not in insert mode. I'm not in command mode. I'm in what we call navigation mode or what I call navigation mode.

[\[02:20\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=140s) And navigation mode also allows for surgical strikes against your code. So if I just want to add a new line below hello world, all I have to do is to say O for a new line below. So O, I want a new line. And here I am in insert mode with a new line. This is the second line. And press escape again. And the way that things work in Vim usually is that you do something something surgical and then you press escape if you want to get back into navigation mode again.

[\[02:52\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=172s) Let's say I want to add a line just above this line. I don't want to I don't need to go up or down. All I have to do is to say shift O for a line above. Shift O and I'm in insert mode. This is now the now the second line. Now let's say I want to change second line in the third line to the word third. So how do I move down and up? So one way to move down and up is with the J K keys. So J goes down, K goes up.

[\[03:24\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=204s) J K J K. So I can just move down and up. And I can also move H and L for left and right. Le H and L left and right. J and K. Down and up. But I can also move between words in a in an easier way. So if I want to move a whole word back, I'll say B in navigation mode and I move a whole word back. If I want to move a word forward, I just say W. So I can move back and front.

[\[03:55\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=235s) Now let's say I want to change this word. I can do it in multiple ways. For example, I can go into what we call selection mode, which is I can press V and then I can move L to the right like this. And now I can press C to change the selection. So I'm going to press C. And now the word I can change it to third. Press escape and I'm done. Now let's say I want to undo that. So I can show you a different way to do it.

[\[04:26\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=266s) So to undo, you just press U. So I'm going to I just undid that. Let's say I want to change it. There's an easier way to change stuff in Vim. So I can say CW that is change word. So C W will change a word. So now I can say third and press escape again. Let's undo that. And you can see that there is a pattern. Usually the pattern that I use to change a specific word I just say CW. So CW third escape.

[\[04:58\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=298s) Now I can be in the middle of a word. So I can say change in word. C I W change in word. Third escape. Get undo. Doesn't matter if I'm the beginning or the end. I'm going to say undo and then say changing word third escape. Let's do that to change it to number two. changing word to escape.

[\[05:29\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=329s) I can select a whole line and change the whole line with not a regular V but a a shift V. So shift V moves into line selection mode. And now when I move up and down I can go up and down like this. And I can change by pressing C and then doing something else in this line. escape. Okay, so that was a kind of a flurry of commands. So, just to repeat, the commands we've learned so far are going up and down with J and K, up and down.

[\[06:06\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=366s) V for selecting, H and L to move left and right. B to go backwards whole words, W to go forward whole words. Change CW for changing a word from the beginning. here. Escape changing word c i w in the middle of a word and escape for closing. Let's say I want to save the file. I can do command w col w and then write and it will save the file because it already has a file name.

[\[06:42\]](https://www.youtube.com/watch?v=dEsp5YTF6u8&t=402s) But let's say I want to quit as well. I can do col wq for write and then quit. And here I am back in the file. I can press cat hello world and this is a new file. So that's the most simple beginning. Next we're going to look at a bit more complicated stuff.

## Related

- [vimming - Hello World with vim](https://www.youtube.com/watch?v=eiVnG0lkfF4) · YouTube

    Roy's short video on the absolute basics: writing text and saving it to a file, as the lesson starts with.

- [\[Video\] Vimming - All about change](https://osherove.com/blog/2012/5/8/video-vimming-all-about-change.html) · osherove.com

    A Vimming episode on the change command, which the lesson uses through c, cw and ciw.

- [Vimming - Natural Selection](https://www.youtube.com/watch?v=aaCGJCJPSjA) · YouTube

    Covers visual-mode selection with v and Shift-V, which the lesson uses before changing text.

- [A Casual Introduction to VIM on windows](https://www.youtube.com/watch?v=xJz2Hq-jWxY) · YouTube

    A relaxed livestreamed walk through Vim basics, a second pass over the opening, editing and saving covered here.

[Previous lesson Why Vim?](https://courses.osherove.com/courses/vim-hates-you/why-vim/) [Next lesson Copying, Pasting and Yanking in Vim](https://courses.osherove.com/courses/vim-hates-you/copying-pasting-and-yanking-in-vim/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
