Docsity

Vim Text Editing Exercise: Inserting, Changing, Replacing, and Joining Text, Manuais, Projetos, Pesquisas de História

Toggle sidebar
bg1
Inserting, Changing, Replacing, and Joining
Goal:
The goal of this exercise is to give you practice with the different ways to insert, change, replace,
and join text.
Instructions:
Open the insert-practice.txt file
First, start a command line session on your local machine. Next, use vim to open the
"insert-practice.txt" file that came in the course downloads. To do that, navigate to the location of
the file. Remember this could be different for you depending on where you extracted the contents of
the file. This example assumes the course download was saved into your Downloads folder and
extracted from there.
cd Downloads
cd vimclass
vim insert-practice.txt
Using the i command
Remember that the i command places you into insert mode right at your current cursor position.
Use i to insert some text at the very beginning of the first line in the file. For example, you might
insert "vim". After you have inserted the text, return to normal mode with <Escape>.
Using the I command
Move down to the next line of text by type 2j. Your cursor will be in the middle of this line:
<= What is your favorite color?
Insert text at the very beginning of the line by using the I command. Answer the question posed on
the light. Your answer might be "blue," for example. Hit <Escape> to return to normal mode.
Using the a command
Position your cursor on the next line of text with 2j. Insert your name between these symbols: ><.
http://www.LinuxTrainingAcademy.com
pf3
pf4
pf5

Pré-visualização parcial do texto

Baixe Vim Text Editing Exercise: Inserting, Changing, Replacing, and Joining Text e outras Manuais, Projetos, Pesquisas em PDF para História, somente na Docsity!

Inserting, Changing, Replacing, and Joining

Goal:

The goal of this exercise is to give you practice with the different ways to insert, change, replace, and join text.

Instructions:

Open the insert-practice.txt file

First, start a command line session on your local machine. Next, use vim to open the "insert-practice.txt" file that came in the course downloads. To do that, navigate to the location of the file. Remember this could be different for you depending on where you extracted the contents of the file. This example assumes the course download was saved into your Downloads folder and extracted from there.

cd Downloads cd vimclass vim insert-practice.txt

Using the i command

Remember that the i command places you into insert mode right at your current cursor position. Use i to insert some text at the very beginning of the first line in the file. For example, you might insert "vim". After you have inserted the text, return to normal mode with .

Using the I command

Move down to the next line of text by type 2j. Your cursor will be in the middle of this line:

<= What is your favorite color?

Insert text at the very beginning of the line by using the I command. Answer the question posed on the light. Your answer might be "blue," for example. Hit to return to normal mode.

Using the a command

Position your cursor on the next line of text with 2j. Insert your name between these symbols: ><.

Enter your name here =><=

To do that, first position your cursor under > with f>. (NOTE: The f command is covered in the searching lesson. For now, know that it moves your cursor to the character you specify, but only on the same line.) Next enter insert mode after your cursor position with the a command. Now type your name and finally press to return to normal mode.

Using the A command

Position your cursor on the next line of text with 2j. Append your name to the end of line by typing A which places you in insert mode at the end of the line. When you are done typing your name press to return to normal mode.

Enter your name here:

Using the o command

Position your cursor on the next line of text with 2j. Enter insert mode on the line below the current line by typing o. Next, type the name of your favorite movie. When you are done press to return to normal mode.

One the line below, type the name of your favorite movie.

Using the O command

Position your cursor on the next line of text with 2j. Enter insert mode on the line above the current line by typing O. Next, type "vim" and press to return to normal mode.

^^^ One the line above, type the name of the editor you are using.

Using the J command

Position your cursor on the next line of text with 3j. Join the following lines:

This line belongs with the one below it.

After your edit, they will appear on the same line:

This line belongs with the one below it.

I am having a brilliant time in this vim class!

First, position your cursor under "g" in the word great. You can do the by performing a forward search with /gr. (NOTE: The / command is covered in the searching lesson. For now, know that it moves your cursor to the next matching string you specify, even if it is on a different line in the file.) Now type cw , which stands for change word, and type "brilliant". Finally press to return to normal mode.

In the following sentence, change "myself." to "everyone!":

I love myself.

After your edit, the line should look like this:

I love everyone!

First, position your cursor under "e" in the word everyone. You can do the by performing a forward search with /my. (NOTE: The / command is covered in the searching lesson. For now, know that it moves your cursor to the next matching string you specify, even if it is on a different line in the file.) Now type cW , which allows you to change a word including the punctuation that follows. Next type "everyone!". Finally press to return to normal mode. (NOTE: You could have also used the c$ or C command in this example to achieve the same result as the cW command.

Change this entire line of text to anything you want to type:

Type something wonderful here.

First, place your cursor anywhere on the line with 2j. Next, use the command cc which allows you to change the entire line. Type anything you want. For example, "The sky is beautiful!". Finally press to return to normal mode.

Changing case with the ~ command

Capitalize the first letter of the word "monday" on this line:

monday <= The "m" is supposed to be in uppercase.

To do that place your cursor under the "m" by performing a forward search with /m. Next type ~ to perform the case switch case operation.

Capitalize the entire word "shout" on this line:

Don't shout. It's not nice.

To do that place your cursor under the "s" by performing a forward search with /sh. Next type g~w to perform the case switch case operation on the word motion.

Switch the case of the entire following line:

mONDAY'S START BETTER WITH coffee.

After your edit it will look like this:

Monday's start better with COFFEE.

To make that change, place your cursor anywhere on the line with 2j. Next type g~~ to switch the case of the entire line.

Using the U command

On the following line, change the word "Shout" to "SHOUT":

Don't Shout. It's just too loud.

To do that place your cursor under the "S" by performing a forward search with /S. Next type gUw to perform the uppercase operation on the word motion.

Try it again on the next line, but this time use gUW.

Using the u command

One the following line, change the word "Whisper" to "whisper":

Please Whisper.

To do that place your cursor under the "W" by performing a forward search with /W. Next type guw to perform the lowercase operation on the word motion. (NOTE you could have also just used the ~ in this case.)

Repeating commands

One line below the following line, create a new line that contains 80 asterisks (*).