Vim Paste Copy operation

Source: Internet
Author: User
Tags add numbers



Original link: http://www.cnblogs.com/lansh/archive/2010/08/19/1803378.html



The VI editor has 3 modes: Command mode, input mode, and last line mode. It is important to master these three models:

Command mode: VI starts after the default entry is the command mode, from this mode to use the command can switch to the other two modes, and no matter in any mode just click the [ESC] key can return to the command mode. Enter the subtitle "I" in the command mode to edit the file into the input mode of VI.

Input mode: In this mode we can edit, modify, input and other editing work, in the last line of the editor to display a "--insert--" Mark VI entered the input mode. We need to save the file when we have finished modifying the input, then we need to return to the command mode and save it in the last line mode.

Last-line mode: Enter ":" in the command mode to enter the mode, there are many good commands in the last line mode.



4. Edit operation
Enter input mode command
I insert command a append command o Open command C modify command
R replace command s replace command ESC exit command

Input modulo Operation
Home cursor to beginning
End cursor to line end
Page up and PAGE DOWN
Delect Remove the character of the cursor position

Delete operation (Command mode use)
x Delete single character at cursor br> DD Delete the line where the cursor
DW deletes all characters from the current character to the end of the word including spaces
#xFor example 3x deletes the three characters to the right at the cursor
#dd For example, 3dd deletes three lines of text from the current line.


Undo Action
U command Cancel last  Operation, you can use multiple times to restore the original Operation
U cancel all operations
Ctrl+r can resume operation with the U command

copy operation
yy command Copy the contents of the current entire line to the VI buffer
YW Copy the contents of the current cursor to the end of the word to the vi buffer, the equivalent of copying a word
y$ the location of the cursor to the end of the line to the buffer
y^ copy the cursor location to the beginning of the content to the buffer
#yy例如: 5yy is to copy 5 lines
# YW For example: 2yw is to copy two words

If you want to copy the content between rows m to nth, you can enter M,ny in the last line mode for example: 3,5y copy the third line to the fifth row of contents to the buffer.



5. Find and replace
The search and replace function of VI is mainly done in the last line mode:

Top-down Search
/To find the character channeling, where/represents the search from the cursor location, for example:/work

To the bottom of the search
? To find the character channeling for example:/work

Replace
: S/old/new replaces the first occurrence of the old in the row with new
: S/old/new/g replaces all occurrences of old in line with new
: #,# s/old/new/g replaces the old from line # to # # with new
:% s/old/new/g replaces the old that appears in the entire article with new

If the range of replacements is large, a C command is added at the end of all commands, forcing each substitution to require the user to confirm, for example: S/OLD/NEW/C or S/OLD/NEW/GC

6 Recovering files
VI when editing a file, a temporary file is generated, which is the file. Begins and ends with a. SWP. Normal exit the file is automatically deleted, if unexpected exit such as sudden power outage, the file will not be deleted, we can choose the next edit command processing:

o read-only open without changing the contents of the file
E continue editing the file without restoring the contents of the. swp file saved
R restores the contents of the file after the last edit was not saved
Q Exit VI
D Delete the. swp file
Or use the Vi-r file name to restore unsaved content



Under the GUI:
(1) Can press I into the insertion mode
(2) Use the mouse to drag the reverse selection to paste the content, press the left mouse button to copy the selected block to the buffer
(3) Then move the cursor to the point where you want to paste, press the middle mouse button (two-button mouse can press the left and right), paste the buffer contents.



Under the plain text terminal:
(1) Select text block, use V to enter visual mode; Move cursor key selection
(2) Copy the selected block to the buffer, use Y; Copy the whole line, with YY
(3) Cut the selected block to the buffer, use D; cut the whole line with DD
(4) Paste the contents of the buffer, using p

Open the second file in the same edit window with: SP [filename]
Switch between multiple edit files, using Ctrl+w

The command preceded by a number indicating the number of repetitions, plus the letter indicating the name of the buffer used.
To get help, by using: helps [content or commands]





VI set tab to 4 and automatically convert to space 2009-10-30 15:33




: Set tabstop=4 "Force tabs to being displayed/expanded to 4 spaces (instead of default 8).
: Set softtabstop=4 "Make Vim treat <Tab> key as 4 spaces and respect hard Tabs.
: "I don ' t think this one would do and you want.
: Set Expandtab "Turn tab keypresses into spaces. Sounds like this is happening.
"You can still insert real Tabs as [ctrl]-v [Tab].
: Set Noexpandtab "Leave tab keys as Real tabs (ASCII 9 character).
: 1, $retab! "Convert all tabs to space or ASCII-9 (per" Expandtab "),
"On lines 1_to_end-of-file.
: Set shiftwidth=4 "When auto-indenting, indent by this much.
"(Use Spaces/tabs per" Expandtab ".)
: Help TabStop "Find out more about this stuff.
: Help VIMRC "Find out more about. VIMRC/_VIMRC:-)





Copy and paste basic method in VI


Default classification2009-07-30 11:16 Read 407 Comments 0 Font Size: MediumSmallWe first do such a small attempt, please open the browser, from the Web page to copy a paragraph of text, and then open Vim, with Vim, "P" paste, you will find that nothing is affixed to the station, the reason is that, unlike Windows,vim has multiple clipboard, And the system Clipboard is completely independent, so when you copy the text in the browser, the text is saved in the system Clipboard, when you are using "P" to paste, in fact, he read the vim of the Clipboard.
How is it convenient to copy the contents of the system Clipboard? Simple! Use another shortcut "Shift+insert" on it, if you are using Gvim, you can play the same role directly with the middle mouse button. Isn't it simple?
Ok! Let's get to the stage!
As we have said before, Vim has multiple shear plates, which are designed to make it easier for users to copy and paste when making more complex character processing. Please use the ": Reg" Command Now (press the ESC key, exit edit mode, then press: Enter command mode, then enter the Reg return), see? The output on the screen! It's not very familiar, right! Is everything you've ever copied! Perhaps at this time you also found that the vim of the shear plate has so many, according to the number and the symbol of one of the areas separated, here to give a number example-"" 5, see? It starts with ". And also! Have you seen the Clipboard with the number "+"? Is the content inside the text that you copied in the browser just now? Oh...... That's right! The system Clipboard number is "+".
Well, now that you know how to view all of the previous clipboard contents, we'll try to copy the contents of a particular shear board into the file we're editing. We know that the vi paste instruction is "P", but if you want to paste a specific clipboard, just use p will not, how to do? Simple! Can you put the number on the clipboard? Now press ESC, exit edit mode, and then click +p Three characters (how do I press?). No way! "and + How to press?" Use Shift! ), All right!  You see, the text that was previously copied in the browser is pasted into the document? You already know how to copy the contents of the system Clipboard into vim. So how do you paste the characters copied in vim somewhere else? Very simple, we just need to copy the text, copied into the "+ Shear board is not OK?" ("+ Shear plate is the system shearing board, forgot?") In Vim, the copied instruction is Y (press Y in non-edit mode), then copy the text into the specified clipboard, just add the clipboard number. For example, we want to copy a piece of text from vim and then paste it into the browser's address bar: The first step is to select the text that needs to be copied (not in edit mode), then press the "+y" button on the keyboard, and then click the three characters, ok!  has been copied down, now with: Reg command to see, is not in the "+ Clipboard?" Well, so far, you have mastered the basic use of vim shear plate, of course, the function of vim shear board is also very powerful, this article can not be a word, please continue to explore it. VI in a number of files between each other copy, paste function introduction!


Post: 2007-6-08 22:43 | Author: seanhe | Source: | Viewed: 25 times | Go to Software Testing Forum discussion



Yesterday someone raised such questions, I specifically to edit, please share, may not write well!

In vi editing, you often encounter the need to put the file a in one or more lines, copied to the B file inside
(Many people may not know what to do), what should be done?
Here are some of the methods:
1. If you have more than one machine and are networked, you can . NETTerm virtual terminal, Telnet login host to a file to modify, copy, and then open B file Paste the past!
2. If a stand-alone, of course, use UnixWhat about your own editing capabilities?
Let's briefly introduce the commands in the VI Editor:
(A). YW the current word into the nameless buffer, preceded by "X", which indicates the name of the named X is stored
Buffer (x is a-Z), you can also add numbers to indicate the number of words deposited, later can be p or p life
Make out
YY to save the current row in the nameless buffer, see YW

(B). The command is as follows: A-Z is a buffer, or it can be moved out of the number 1-9 specified delete buffer
A named buffer is a good way to save several text segments for later access, movement, or rearrangement. These buffers are named with A to Z letters! In order to access one of these buffers, use double quotation marks
For example, to insert a row into the a buffer, you can type:
"Ayy
In order to put this text back in the file, type "AP


(c). m do the sign command:
The M letter marks the current line with a letter, and then the ' letter ' is used to move the cursor to the current line.
(see ' Command ')

The following: 1. 4 lines in a file to B file

The command is as follows: "ay4+
: Ex B (go to file B)
Then "AP
2. Copy multiple lines in a to file B
First sign at the beginning, Mk.
Then use "Ay" K at the end (the cursor automatically returns to the beginning, when you have put your content in the buffer)
Where a means buffer a
Then escape to your file B with an ex and paste it with the AP command.

3. If you have more than one file to copy and paste, look below:
A means buffer a, and you can still use buffer B?
Buffers have a-Z and 1-9 so much
It's like a buffer. WindowsUnder the fried version of the same, it has a number of good, you can put you want to copy into, and then paste, but you use "ay time more A is, if you want to copy 462 lines with" Ay, copy 536 lines with "by





Vim Paste Copy operation


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.