general pattern
(number)(command)(text object)
advancing to a specific place
vi +n file - open file at line number n
vi + file - open file at last line
vi +/pattern file - open file at the first occurrence of pattern
according to the POSIX standard, vi should use -c command instead of +command, typically, for backward compatibility, both versions are available
if you include spaces in the patern, you must enclose the whole pattern within single or double quotes, or escape the space with a backslash:
+/“you make” or +/you\ make
notice: if wrapscan is always disabled in your customized environment, you might not able to use +/patter.
vi -R file or view file - look at a file in read-only mode
you can override read-only mode by adding an exclamation point to the write mode:
:w! or :wq
recovering a buffer
ex -r //or vi -r - get a list of any files that system has saved
use the -r option with a file name to recover the edited buffer.
Making use of buffer
recovering delections
you can recover any of your past nine delections , for they are saved in numbered buffers. The last delete is saved in buffer 1, the second-to-last in buffer 2, and so on.
to revocer a delection, type “(double quote), identify the buffered text by number, then give the put command. to recoer your second-to-last delection from buffer2, type:
“2p
if you’re not sure which buffer contains the delection you want to restore, you don’t havet to keep typing “np. if you use the repeat command (.) whth p after u, ti automatically increments the buffer number. As a result, you can search through the numbered buffer using;
“1pu.u.u etc
Yanking to named buffer
To yanking into a named buffer, preced the yank command with a double quote (“) and the character for the name of the buffer you want to load, for example:
“dyy - yanking current lint into buffer d
“a7yy - yanking next 7 lines into buffer a
after loading the named buffers and move to the new position, use p or P to put the text back:
“dP - put the contents of buffer d before cursor
“ap - put the contents of buffer a after cursor
if you specify a buffer name with a capital letter, your yanked or deleted text will be appended to the current contents of that buffer. this allow you to be selective in what you move or coppy:
“zd) - delete form cursor to the end of current sentence and save in buffer z
- move 2 sentences further on
“Zy) add the next sentence into buffer z.
warning: if you forget once, and yank or delete to the buffer without specifying it name in capitalized form, you will overwrite the buffer, losing whatever you had accumulated in it.
Marking your postition
mx - marks the current position with x (x can be any letter). original vi allows only lowercase letter. Vim distinguishes between uppercase and lowercase.
‘x - move the cursor to the first charactor of the line marked by x
`x - move the cursor to the charactor marked by x
`` - return to the exact position of the previous mark or context after a move
‘’ - return to the beginning of the line of the previout mark or context