zhuang@linux:~/reading/practical-vim/05-command-line-mode/$ less
Command-Line Mode
This post extracts some knowledge from Chapter 5 – Command-Line Mode.
| Command | Effect |
|---|---|
:[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]join | Join 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 |
| Symbol | Address |
|---|---|
1 | First line of the file |
$ | Last line of the file |
0 | Virtual line above first line of the file |
. | Line where the cursor is placed |
'm | Line 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
:.,,+3pThe . 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