Basic vim Editing
Goal
You get comfortable with basic vim editing (insert, delete, copy and paste), and learn how to save editing commands to a file so you can reproduce them.
Why it matters
vim's keys are not a list to memorize but a grammar: {횟수}{동작}{범위}. If you combine d (delete) and 3w (3 words) into d3w, you can build commands you were never taught. Also, in vim deleting is cutting. Deleted content stays in a register, which is why idioms such as ddp (swap with the line below) work. In the last two steps you submit the editing commands themselves as files because matching only the result is completely different from being able to reproduce the procedure.
Steps
- Create
/root/.vimrcand turn on these four things: line numbers, spaces instead of tabs, tab width 4 and indent width 4. - Create
/root/vim/poem.txtwith exactly the following 8 lines. Lines 4 and 7 are blank lines.alpha/bravo/charlie/ (blank line) /delta/echo/ (blank line) /foxtrot - Create
/root/vim/notes.txtwith the following 3 lines.i = insert before cursor/a = append after cursor/o = open line below - In
poem.txt, delete only the two linesbravoandcharlie, and save the result as/root/vim/cut.txt. Leave the original as it is. - In
poem.txt, add one moredeltaline directly belowdelta, and save the resulting 9 lines as/root/vim/dup.txt. - In
poem.txt, swap only the order ofalphaandbravo, and save the resulting 8 lines as/root/vim/swap.txt. - Save one ex command line that deletes all blank lines to
/root/vim/blank.ex, and save the 6-line result of applying that command as/root/vim/nogap.txt. - Save the ex commands that delete the blank lines and convert every letter to uppercase to
/root/vim/build.ex, and save the result as/root/vim/final.txt.
Notes
- Put only editing commands in the
.exfile. Do not include save or quit commands such as:wq. The grader saves for you. - The grader applies the
.exfile to a copy of the original and checks that the result is the same. So the result file and the command file must agree with each other. - Refer to the whole match in a substitution with
&; the uppercase conversion specifier is\U. - Common mistake 1: if you edit
poem.txtitself in steps 4–6, every later step breaks. Use:w 새파일to save under another name (new file name). - Common mistake 2: if there is a typo in
.vimrcin step 1, only that line is silently ignored. Open vim and check with:set expandtab?whether it is really applied.
Create and verify the configuration file
Create /root/.vimrc and turn on these four things: line numbers, spaces instead of tabs, tab width 4 and indent width 4.
What you write in the file is different from what vim applies. Inside vim, adding a question mark, as in :set number?, tells you the current value.
Create a practice file
Create /root/vim/poem.txt with exactly the following 8 lines. Lines 4 and 7 are blank lines.
alpha / bravo / charlie / (blank line) / delta / echo / (blank line) / foxtrot
A blank line counts as a line too. Lines 4 and 7 must be empty.
Practice entering Insert mode
Create /root/vim/notes.txt with the following 3 lines.
i = insert before cursor / a = append after cursor / o = open line below
i, a and o start typing before the cursor, after the cursor and on the line below, respectively. Match the contents and order of the three lines exactly.
Delete lines
In poem.txt, delete only the two lines bravo and charlie, and save the result as /root/vim/cut.txt. Leave the original as it is.
dd deletes one line and 2dd deletes two. Do not touch the original file; save the result to a new file.
Duplicate a line
In poem.txt, add one more delta line directly below delta, and save the resulting 9 lines as /root/vim/dup.txt.
Copy with yy and paste with p. Recall that deleting in vim is also cutting.
Swap two lines
In poem.txt, swap only the order of alpha and bravo, and save the resulting 8 lines as /root/vim/swap.txt.
A line deleted with dd stays in a register. Then think about where to press p.
Remove blank lines with a command
Save one ex command line that deletes all blank lines to /root/vim/blank.ex, and save the 6-line result of applying that command as /root/vim/nogap.txt.
:g/pattern/d deletes the lines that match the pattern. The pattern for a blank line is one where the start of the line and the end of the line are adjacent.
Several edits in one script
Save the ex commands that delete the blank lines and convert every letter to uppercase to /root/vim/build.ex, and save the result as /root/vim/final.txt.
Combine the substitution specifier that converts to uppercase with the symbol that refers to the whole match. Put the two commands in order.