In this lab, you’ll be working with Vim Modes. One of the most important things about editing in Vim is knowing what mode you are _in_, how to get _out_ of that mode and back to Command Mode, and then into the next mode you need to operate in.
Being able to use the right mode to accomplish a needed step is critical, and this lab will ensure you know how to get to the right mode for the task.
Successfully complete this lab by achieving the following learning objectives:
- Start Vim, Lookup Vim Modes in Help, Practice Switching Modes
Start the Vim editor:
Use Help to lookup information about Vim
Notice this does not show help for the type of modes we are looking for, so try:
Note how many BASIC modes Vim has, and also the help part of the screen is not very large.
To show more of the help screen, press the keystrokes:
Note: This will not work while using the browser terminal.
Ctrl-w (Press and hold Ctrl, then w and release) 10+ (Type 10 and then Shift-= or +)
Note: This will increase the size of the Help window and allow you to read more without scrolling
When done reading the descriptions of the seven Basic Modes, exit Help by pressing:
Verify you are in Command Mode by pressing
ESCtwice in rapid succession. You should hear the Error Bell, or the screen should flash.
Switch to Insert Mode by pressing the
icharacter, and type a short sentence, such as
This is a sentence in Vim.then press the
ESCkey to return to Command Mode.
Note that when you are in Insert Mode, the bottom left of your Vim window has the mode shown as
-- INSERT --.
With your cursor on the line you have added, and use Visual Line mode to select the line by pressing:
Change the case of the text in the line with:
Use Command Line Mode to save your buffer to a file named
ESC :w file1.txt
Then exit Vim with:
Note: If while trying to exit from Help, you are presented with a window that appears to contain commands, you pressed
q:, so repeat the
:qkeystrokes until you have exited Help.
Note: If at any time you are shown a message at the bottom left that Vim is
recording @q, simply press the
qkey again to stop the recording.
- Use Help and Command Mode to Create a Working File, Use Visual Mode Select and Manipulate Text, and Use Command Mode to Save and Exit the File
- Open the Vim editor:
- Create a working file with:
:help quotes :w ~/quotesdemo.txt
- When the file is written to disk (the status will read
[converted]), quit Help with:
- While still in Vim, open the
~/quotesdemo.txtfile in a buffer with:
- Navigate by your preferred means to the paragraph starting with:
Coming with a very GUI mindset...
- Place your cursor on the first character of the word
vto start Visual mode. The last line should show
-- VISUAL --as a mode indicator.
- Then highlight/select the word
eto go to the end of that word.
wtwice to select two more words.
- Set the words to upper case by pressing
Uwhile they are selected.
- Enter Visual mode again by pressing:
- Then move your cursor down to select the entire paragraph that starts with
Comingand ends with
- Set the entire paragraph to upper case by pressing
Uwhile all the text is selected.
- Re-select the entire paragraph by pressing
- Delete the paragraph by pressing
- Save and exit the file by pressing:
- Open the Vim editor: