Tips for using the vi text editor and Linux copy and paste

Source: Internet
Author: User

Tips for using the vi text editor and Linux copy and paste

To be an efficient DBA, you must be familiar with the vi Editor, especially those preparing for the OCM exam. In addition, in Linux, it is also a skill to stick the selected text with the left mouse button and press and hold the scroll bar in the middle of the mouse. Seven years after I got started with Linux, I learned this skill through an accidental question. The Linux function has at least improved my testing speed by more than 15%. People who have passed the test know that the test is not only skillful, but also a test of efficiency and speed.

Use the vi Text Editor

The configuration file is one of the notable features of Linux. Its function is somewhat similar to the Registry in Windows, but the registry is centrally managed, and the configuration file adopts a decentralized and free management mode. Vi is a powerful full-screen text editing tool. vim is an enhanced version of the vi editor. It extends many practical functions based on the vi editor, but it is also called vi as a habit.

Vi Editor Working Mode:

Command mode: After the vi editor is started, the command mode is enabled by default. In this mode, you can move the cursor, search for strings, and delete, copy, and paste file content.

Input mode: the main operation in this mode is to enter the file content. You can modify the text file or add new content. In the input mode, the last line of the editor displays the "-- insert --" status prompt.

Last line mode: This mode allows you to set the vi editing environment, save the file, exit the editor, and perform operations such as searching and replacing the file daughter. In the last line mode, the ":" prompt appears in the last line.

I. vi open and edit the file

Vi <filePathAndName> (example: vi test. conf, vi/tmp/test. conf ,...)

If the specified filePathAndName exists, the content of the file is automatically loaded. If it does not exist, the file is automatically created. Note: If the Tilde is displayed before each row, the behavior is empty.

Ii. mode switching: In the command mode, use a, A, I, I, o, O, and other buttons to quickly switch to the input mode. In the return mode, Press Esc. Enter the last line mode and press ":" In command mode.

Iii. vi editing commands

1. Screen flip

Ctrl + u: half screen up

Ctrl + f: Flip the screen up

Ctrl + d: Flip down half screen

Ctrl + B: Flip down the screen

2. move the cursor

Moving the cursor is commonly used as a direction key. Considering compatibility, vi defines too many direction commands. below is only a small part (commonly used ):

Space: move the cursor one character to the right

Backspace: move the cursor one character to the left

Enter: move the cursor down a row

NG: move the cursor to the beginning of line n

N +: move the cursor down n rows

N-: Move n rows above the cursor

N $: move the cursor to the end of line n

0: move the cursor to the beginning of the current row

$: Move the cursor to the end of the current row

3. insert and delete commands

Common insert and delete commands are as follows:

I: insert in front of the current cursor, move the text behind the cursor to the back

A: insert the cursor from the current position and move the text behind the cursor.

I: insert the cursor at the beginning of the line (before the first non-blank character)

A: insert from the end of the row where the cursor is located

O: add a line under the row where the cursor is located (and enter the input mode)

O: add a line above the row where the cursor is located (and enter the input mode)

X: Delete the character of the cursor, equivalent to the [Delete] function key.

X: Delete the prefix of the cursor, equivalent to [Backspace]

Dd: Delete the row where the cursor is located.

Yy: copy the content of the current row to the clipboard.

# Yy: # It is a specific number. You can copy the line content starting from the cursor. #

P: paste the content in the clipboard after the current cursor position

P: paste the content in the clipboard before the current cursor position

R: Modify the character of the cursor

R: Replace the current and subsequent characters until you press [ESC]

S: Starting from the current cursor position, replace the specified number of characters with the input text

S: delete a specified number of rows and replace them with the input text

Do: Delete to the beginning of a row

D $: Delete to the end of the row

Iv. vi search, save, and exit

Exit the input mode. Press the [ESC] Key (or press twice) and run the following command:

Press/key-enter the specified string and search down from the current cursor.

Press? Key-enter the specified string and search up from the current cursor.

Press the n and N keys to select different search results.

Press u to cancel the last operation. You can perform the operation multiple times, similar to canceling the operation.

Press U to cancel all edits on the current row. : W -- save the current file

: Wq -- save disk to exit (same as command: x)

: Q -- exit directly. If modified, a message indicating whether to save the modification is displayed.

: Q! -- Exit directly without saving

5. Open a new file or read other file content

In the current vi Editor, execute the last line command in the form of ": e new file" to edit the new file.

In the current vi Editor, execute the last line command in the form of ": r other files" to read the contents of other files and copy them to the position of the current cursor.

In the current vi Editor, Run ": r! Command "form of Moxing mode, you can paste the output of other commands to the position of the text file cursor.

Run the "set number" command in the last line mode to display the row number. Run "set nonu" to undisplay the row number.

Vi. vim editor's useful parameters

-O file1 file2; the two files are opened at the same time and displayed up and down. use ctrl + w to switch the files.

-O file1 file2; the two files are opened at the same time and displayed on the left and right. use ctrl + ww to switch the files.

VII. search and replace
? /N N
: S/old/new/
: N, M s/old/new/
: % S/old/new/g % all rows g Global

Save
: N, M w file.txt

Visual mode v
D. Delete y-copy.

8. Configuration File Location

/Etc/vimrc

Make the vimtutor command display normally
Cd/usr/share/vim/vim72/tutor
Mv tutor. zh. euc tutor. zh. euc. bak
Iconv-f GBK-t UTF-8 tutor. zh. euc. bak-o tutor. zh. euc
Vimtutor

-------------------------------------- Split line --------------------------------------

Build VIM into a simple and practical IDE

Vim Learning Guide

Quick learn Vi Editor

Powerful Vim Editor

Build a Vim Development Environment on CentOS 6.2

Install the highlighted Vim editing tool in CentOS 5.4

Vim tips: C language settings

Set the Vim row number in Ubuntu

Vim editor basic tutorial

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.