Vim Tutorial Study(4)

来源:互联网 发布:淘宝手机壳进货渠道 编辑:程序博客网 时间:2024/06/02 20:21

Chapter 4 Text Blocks and Multiple Files

The Vim editor has the concept of a register. This enables you to hold data for multiple cut, copy, or paste operations. Most other editors are limited to a single cut/paste clipboard. With the Vim registers you get more than 26 clipboards.

Cut, Paste and Copy

when you delete something with the d, x, or another command, the text is saved

you can use p command to paste it back (technical name is put) 3p is also correct

if you delete an entire line, the p command places the text on the line after the cursor

if you delete part of a line(like dw), the p command puts it just after the charater under the cursor

他会在你光标所在位置的下一行,或者下一个字符开始

Charater Twiddling  (twiddle)

change 'teh' into 'the': xp

More on "Putting"

insert count times: 3p

Marks: enable you to place marks in your text

mcharater: ma (marks the place under the cursor as mark a)

to go to a mark, use the command: `mark (which moves you to the marked line and column)

moves you to the beginning of the line containing the mark: 'mark

'mark command can be very useful when deleting a long series of lines:

move the cursor to the begining of the text you want to delete

mark it using the command ma

go to the end of the text to be removed, use d'a

(其实在这里,头和尾都不重要。他会删除整行而不是从起始光标开始末尾光标结束)

反过来做也是可以的:就是你从后面的行开始标记,到前面的行删

由于你在这里删除了文字,所以照样可以用p进行put

Where are the marks?

list all the marks: :marks

view specific marks: :marks args (:marks a)

Yanking

the y command "yanks" text into a register(without removing it from the file), general form: ymotion

yanks the current line into the buffer: yy

mark ma from the beginning line, the y'a end with the ending line: then the text block have been copied

use p to paste

Y, yy are the same; so are 3Y and 3yy

Filtering

!motion command takes a block of text and filters it through another program

it runs the system command represented by command, giving it the blocks of text represented by motion as input.

the output of this command then replaces the selected block

suppose you are at first line, line 1

then use !10Gsort<Enter>

!! command runs the current line through a filter (a good way to get the output of system commands into a file)

Example:

!!ls

!!date

Editing another file

:vi filename    you must use this command after :write or :w

or force Vim to discard your changes and edit the new file using:  :vi! file

New file opened in read-only mode

:view file

you can also force the Vim to write the changes into the read-only file using: :write!

Dealing with Multiple files

$gvim one.c two.c three.c, by default vim displays just the first file

to edit the next file: :next after :write

a shorthand command for this: :wnext

if you use :next! you will lose the changes in the current file

turn auto write option on:

:set autowrite

to turn it off

:set noautowrite

:2next or :2 next is also correct and acts the same

caution: if it reaches the last file, it will not automatically turn to the very beginning to continue, it just stops

Which File Am I On?

:args

Going Back a File

:previous or :Next

:wprevious or :wNext

Editing the First or Last File

the first: :rewind  **caution: not :first**

the last: : last

Editing Three Files

$gvim one.c two.c three.c

1CTRL-^ will turn to one.c

2CTRL-^ will turn to two.c

3CTRL-^ will turn to three.c

while you are using just CTRL-^, it will just switch you to the file you previously edited, will not iterate all the candidate files

原创粉丝点击