How to select lines in Vim
In Normal mode, press V to select the whole line, extend the selection with j or k (V3j for four lines, Vip for the paragraph), then press an operator: y to copy, d to delete, > to indent.
Selecting in Vim is Visual mode, and there are three kinds. V selects whole lines (Visual Line mode); v selects characters, from where you start to where the cursor is; Ctrl-v selects a rectangle (Visual Block mode). The bottom line shows which one you're in: -- VISUAL LINE --, -- VISUAL -- or -- VISUAL BLOCK --. Any motion moves the end of the selection, and Esc leaves without doing anything.
Carry two tasks over
The two open tasks move to tomorrow. The cursor is on the first: V selects its line, j adds the next, d cuts both. Then G goes to the last line and p puts them below it.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | Selects |
|---|---|
| V | the current line |
| Vj / Vk | this line and the one below / above |
| V3j | this line and the three below it |
| Vip | the paragraph, up to the blank lines around it |
| VG / Vgg | from this line to the end / the start of the file |
| v, then a motion | characters: vw, ve, v$ to the end of the line |
| viw / vi( | the word under the cursor / what is inside the brackets |
| o | not a selection: jumps to the other end, so you can move that end instead |
| gv | the last selection again |
Then act on it
A selection waits for a command. y copies it, d (or x) cuts it, c deletes it and starts Insert mode, > and < indent and unindent it, J joins the lines into one, and p replaces it with what you copied. Pressing : starts a command on the selected lines: Vim types :'<,'> for you, so :'<,'>s/old/new/g replaces only inside them.
After the command, Vim is back in Normal mode and the selection is gone.
Fix a selection instead of starting over
A selection has two ends, and motions move the end the cursor is on. Started one line too low? Press o and the cursor jumps to the other end, so k now grows the selection upwards. Lost it to a stray Esc, or want a second command on the same lines? gv selects them again: V2j> then gv> indents three lines two levels.
Practise selecting
Type the keys for each one, as you would in Vim.