zhuang@linux:~/reading/practical-vim/05-command-line-mode/$ less

Practical Vim / chapter 05

Command-Line Mode

$ grep tags 05-command-line-mode.md

This post extracts some knowledge from Chapter 5 – Command-Line Mode.

CommandEffect
:[range]delete [x]Delete specified lines [into register x]
:[range]yank [x]Yank specified lines [into register x]
:[line]put [x]Put the text from register x after the specified line
:[range]copy {address}Copy the specified lines to below the line specified by {address}
:[range]move {address}Move the specified lines to below the line specified by {address}
:[range]joinJoin the specified lines
:[range]normal {commands}Execute Normal mode {commands} on each specified line
:[range]substitute/{pattern}/{string}/[flags]Replace occurrences of {pattern} with {string} on each specified line
:[range]global/{pattern}/[cmd]Execute the Ex command [cmd] on all specified lines where the {pattern} matches
SymbolAddress
1First line of the file
$Last line of the file
0Virtual line above first line of the file
.Line where the cursor is placed
'mLine containing mark m
'<Start of visual selection
'>End of visual selection
%The entire file (shorthand for :1,$)

we could use an offset relative to the current line:

vim
:2
:.,,+3p

The . symbol stands for the current line, so :.,.+3 is equivalent to :2,5 in this case.

:copy = :co = :t

As a mnemonic, you can think of it as copy TO.

vim
:[range]normal [normal-action]

Use @: to repeat the last Ex command. After running @: for the first time, we can subsequently repeat it with the @@ command.

Just like in the shell, we can use the <Tab> key to autocomplete commands at the prompt. The <C-d> command asks Vim to reveal a list of possible completions.

At Vim’s command line, the <C-r><C-w> mapping copies the word under the cursor and inserts it at the command-line prompt.

zhuang@linux:~/reading/practical-vim/05-command-line-mode/$ comments