- Lab
- A Cloud Guru
Vim Modes
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.
Path Info
Table of Contents
-
Challenge
Start Vim, Lookup Vim Modes in Help, Practice Switching Modes
-
Start the Vim editor:
vim
-
Use Help to lookup information about Vim
modes
::help modes
-
Notice this does not show help for the type of modes we are looking for, so try:
:help vim-modes
-
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:
:q
-
Verify you are in Command Mode by pressing
ESC
twice in rapid succession. You should hear the Error Bell, or the screen should flash. -
Switch to Insert Mode by pressing the
i
character, and type a short sentence, such asThis is a sentence in Vim.
then press theESC
key 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:
Shift-v
-
Change the case of the text in the line with:
Shift-u
-
Use Command Line Mode to save your buffer to a file named
file1.txt
:ESC :w file1.txt
-
Then exit Vim with:
:q
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:q
keystrokes 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 theq
key again to stop the recording.
-
-
Challenge
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:
vim
- 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::q
- While still in Vim, open the
~/quotesdemo.txt
file in a buffer with::e ~/quotesdemo.txt
- 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
Coming
and pressv
to start Visual mode. The last line should show-- VISUAL --
as a mode indicator. - Then highlight/select the word
Coming
by pressinge
to go to the end of that word. - Press
w
twice to select two more words. - Set the words to upper case by pressing
U
while they are selected. - Enter Visual mode again by pressing:
Shift-v
- Then move your cursor down to select the entire paragraph that starts with
Coming
and ends withFonseca)
. - Set the entire paragraph to upper case by pressing
U
while all the text is selected. - Re-select the entire paragraph by pressing
gv
. - Delete the paragraph by pressing
d
. - Save and exit the file by pressing:
ZZ
- Open the Vim editor:
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.