Creating and Using Marks
The command ma marks the place under the cursor as mark a.You can place 26 marks (a through z) in your text. (You can use a number of other marks as well.) To go to a mark, use the command `mark, where mark is the mark letter (and ` is the backtick or open single-quote character). The command ‘mark (single quotation mark, or apostrophe) moves you to the beginning of the line containing the mark.This differs from the `mark command, which moves you to the marked line and column.
The ‘mark command can be very useful when deleting a long series of lines.To delete a long series of lines, follow these steps:
Listing Marks
To list all the marks, use the following command:
:marks
Yanking Stuff
Using marks, first go to the top of the text to be copied and mark it with
ma.Then go to the bottom and do a y’a (yank to mark a). Now go to where the
copied text is to be inserted and put it there using the p command.
The Y command yanks a single line. If preceded by a count, it yanks that number
of lines into the register.
Filtering
You want to sort lines 1 through 10 of a file.You start by putting the cursor
on line 1. Next you execute the following command:
!10G
The ! tells Vim that you are performing a filter operation.The Vim editor
expects a motion command to follow indicating which part of the file to
filter.The 10G command tells Vim to go to line 10, so it now knows that it is
to filter lines 1 (the current line) through 10 (10G). In anticipation of the
filtering, the cursor drops to the bottom of the screen and a ! prompt
displays.You can now type in the name of the filter program, in this case sort.
Therefore, your full command is as follows:
!10Gsort
The !! command runs the current line through a filter. Examples:
!!ls
!!date
Editing Two Files
By pressing CTRL-^, you can switch editing from the current file to the alternate file.
Buffers
:buffers - lists the buffers
:bnext
:buffer #number - moves to that buffer
Visual Mode
v character mode
V line mode
ctrl-V rectangle mode
d deletes the highlighted chars
D deletes the highlighted lines even partially
y/Y Yank and linewise yank
c/C Deletes the selected text and starts in insert mode
J Joins all the lines
>< Indent/outdent
Programming Stuff
Ctrl-D while in insert mode, moves back one tabstop.
% matches brackets
>i{ shifts all text between brackets one tabstop.
set list/nolist
Searching - Highlighting
The following command causes Vim to highlight any strings found matching the
search pattern:
:set hlsearch
To turn off search highlighting, use this command:
:set nohlsearch
To clear the current highlighting, use the following command:
:nohlsearch