linux study notes management system using vi 4-

linux study notes management system using vi 4-

vi Getting Started

Linux basic text editor is the most common operations.

Highly recommended as the preferred vi text editor.

vi is preinstalled linux text editor.

is an upgraded version of vi vim (vi improved), vim is fully compatible with vi.

Enter the command line vim, vim text editor opens.

vim is a model editor, there are three basic modes, different modes to perform different tasks, respectively,

  1. Normal mode, the operation command, such as a cursor move, delete, copy, paste and the like.
  2. Input mode: character input
  3. Command line mode: open, save, find, replace, and so on.

Press i, that allow vim to enter edit mode, the lower left display INSERT. vim when the general pattern of the lower left displays the file name or a blank.

Under input mode content. Once completed, press esc, editor and enter the general mode.

Normal mode to move the cursor, h and left at j, a k, l and right. Moving the cursor operation by an arrow may be, but doing so is not recommended, since the above four keys hjkl just right hand position on the keyboard.

Remove method is to move the cursor to the text you want to delete, then press the x button. Delete an entire row, the cursor is moved to an arbitrary row to be deleted is one, then the command, "dd" command to delete the following line will shift up to fill the gap. The operation is a delete line breaks, move the cursor to the end of the line, and press shit + J (i.e. uppercase J), ​​i.e., it deletes the current line breaks. U can command undoes the last edit, press ctrl + r, can redo.

Normal mode, input: i.e. into the command line.

Use ": wq sample.txt" command to exit vim, the command will save the modified file to the hard sample.txt and exit vim. Command: Let the editor in command mode, w command tells the editor to save the file, q command to tell the editor to exit the program.

":! Q" command, the exit without saving any changes. Command! That tells editors do not need to save the file.

Advanced vim

Complete with a 12-step vim text editing tasks.

mkdir /tmp/vimtest
cd /tmp/vimtest
cp /etc/man_db.conf .
vim man_db.conf

Then the task operation content

  1. Set the line number. Task is to set the line number. Set line numbers belong to the set of environmental parameters, environmental parameters are set command Set 环境参数to cancel setting is Set no环境参数. Press colon into the command line, you can enter Set nu. To cancel setting the line number, enter "Set nonu".
  2. Precise movements and to move the line end of the line head. The first task is to move to 58 trekking first, then move to 30 characters to the right, move to the end of the eighth trekking, then move the three to the left, and finally move to file the last line. vim move command can be used to move the cursor keys, or a number key movement command + precise and rapid movement. The rightward 8l is eight characters, 3j line 3 is moved downward. gg indicates the file is moved to the first line, G represents a file is moved to the last line, the number 0 indicates the first move of the current line, the dollar sign means move to the end of the current line. 3G shows a trekking 3 moves the cursor to the first, $ represents 10 down line 10, and locate the end of the line.
  3. Find operation. Moved to the first trekking first, and this man down search string. Gg operation is moved to the first line of the file, in the normal mode, oblique type into the command line, and then enter the string man man Find downwardly from the cursor. Through all the found string n or N.
  4. Replace operation. Task is to replace man between 50 to 100 lines of MAN, and asks the user if a selected one needs to be replaced. Alternatively the pattern is substantially in vim, n1,n2s/word1/word2/gcshowing word1 string lookup n1 and n2 between the first row (when looking for replacement when required, can make that the first row n1 = 1 throughout this document, represents the last line n2 = $) and with word2 instead. Command character c may be omitted, and c represents vim comprise user is queried before replacement. Operation, in the normal mode, type a colon into command mode, enter 50,100s/man/MAN/gc.
  5. . Task is to copy the contents of 51-60 rows ten rows, and then paste it into the last row. vim copy command, yy, i.e. the line where the cursor is copied, nyy indicates a copy down n rows starting from the cursor line. vim Paste command is p, the next line indicates the cursor attached. Operations are, 50G positioning text lines 50, 10yy copy lines of text 51-60, G is positioned to the last line of text, p paste.
  6. Delete characters and delete the entire line. Task is deleted 20 lines between the 11-30 line, navigate to the first 29 trekking, and delete 15 characters. vim means to delete the line where the cursor dd, ndd means to delete down n rows starting from the cursor line. vim character delete command is x, means to delete the character at the cursor, nx represents the beginning Delete n characters from the cursor. Action is, 10G, 20dd, 29G, 15x.
  7. Undo. Task is to remove all previous modifications. vim u undo the last operation, or type E! undo all operations. Operation is
  8. File Save As operation. Mission is to save the file to a file named man.config.bak of. Operation, in the normal mode, colon type into the command line,: w man.config.bak, can. Where, w is the Save command, followed by the file name.
  9. Insert the contents of other documents. Task is, after the last line, insert the contents of the current directory turtle.txt file and save it. Action is, type G navigate to the last line, type a colon into the command line, :r /turtle.txtwill soon turtle contents of the file is inserted into the end of the file. Then saved with the w. r is the order of the contents of another file is appended to the current cursor position.
  10. Multiple documents open simultaneously. Task is to open at the same man_db.conf and man.config.bak. vim Providing multiple files simultaneously edit functions, vim file 1, file 2 file .... n, i.e. open multiple files simultaneously. Then the command line mode, with: n,: N can switch between multiple files.
  11. Visual mode. Task is to paste the first column in the end 10 copies man.config.bak turtle.txt inserted into man_db.conf the file content. Operation is in the normal mode, press ctrl V visual mode to enter, and then displaying the visual character, the visual mode provides a very friendly text selection method, cursor movement, to select text in the bottom left of the screen. After selecting 10 content, press y copy the content. Then switch file, G entering the last line, p pressed paste.
  12. Storing files and exit vim.

References Recommended

vim

Books "Vim tips"

Book "Learning vi and vim"

Guess you like

Origin www.cnblogs.com/songbiao/p/12582863.html