TT Lab
Get started
Learn Learning paths Courses

vim and tmux

Basic vim Editing

Continue in TT Lab

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

  1. Create /root/.vimrc and turn on these four things: line numbers, spaces instead of tabs, tab width 4 and indent width 4.
  2. 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
  3. Create /root/vim/notes.txt with the following 3 lines. i = insert before cursor / a = append after cursor / o = open line below
  4. 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.
  5. In poem.txt, add one more delta line directly below delta, and save the resulting 9 lines as /root/vim/dup.txt.
  6. In poem.txt, swap only the order of alpha and bravo, and save the resulting 8 lines as /root/vim/swap.txt.
  7. 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.
  8. 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

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.