Several basic operations in VIM 7.3

Source: Internet
Author: User

I. Modify the configuration file. vimrc to create a personalized Vim

This document assumes that the installation directory is ~ /

In ~ In the/Vim/share/Vim/vim73/directory, there is a vimrc_example.vim sample file. Modify the corresponding configuration based on this file, and copy it to the root directory of the user. vimrc) command is CP vimrc_example.vim ~ /. Vimrc

Copy the embedded VI command to see that the change takes effect.

II. Vim split-screen operations

Split screen to start Vim
  1. Use the uppercase o parameter to split the screen vertically.

    vim -On file1 file2 ...
  2. Use the lower-case o parameter to split the screen horizontally.
    vim -on file1 file2 ...

Note: N is a number, which indicates several screens.

Disable Split screen
  1. Close the current window.

    Ctrl+W c
  2. Close the current window. If only the last one is left, exit vim.
    Ctrl+W q
Split screen
  1. Splits open files up and down.

    Ctrl+W s
  2. Split up and down, and open a new file.
    :sp filename
  3. Split the currently opened files left and right.
    Ctrl+W v
  4. Split left and right, and open a new file.
    :vsp filename
Move cursor

The cursor keys in VI are H, J, K, and L. to switch between screens, just press Ctrl + W.

  1. Move the cursor to the right screen.

    Ctrl+W l
  2. Move the cursor to the screen on the left.
    Ctrl+W h
  3. Move the cursor to the screen above.
    Ctrl+W k
  4. Move the cursor to the screen below.
    Ctrl+W j
  5. Move the cursor to the next screen ..
    Ctrl+W w
Mobile split screen

This function still uses the vim optical key, which is only in uppercase. Of course, if your split screen is messy and complicated, this function may have some very strange symptoms.

  1. Move to the right.

    Ctrl+W L
  2. Move to left
    Ctrl+W H
  3. Move up
    Ctrl+W K
  4. Move down
    Ctrl+W J
Screen Size

The following are some operations to change the size, mainly the height. You can use Ctrl + W <or> for the width, but this may be supported by the latest version.

  1. Make all screens have the same height.

    Ctrl+W =
  2. Increase the height.
    Ctrl+W +
  3. Reduce height.
    Ctrl+W -

3. Vim basic Editing Command


1. Three statuses
Command: Any input will be used as an editing command instead of on the screen. Any input will be immediately reflected.
Insert: Any input data is placed in the edit register. Press ESC to switch back to the command mode.
Escape: a command with ":" or "/" as the leading line appears in the bottom line of the screen. Any input is treated as a special command.
2. Leave Vi
: Q! Leave Vi and discard the edited content in the buffer.
: WQ writes data in the buffer zone to the disk and leaves VI.
Same as WQ.
(Note --: X indicates file encryption, which must be different from: X indicates disk exit)
3. Enter the input mode
A (append) adds data after the cursor.
A is added by the end of the row.
I (insert) adds data before the cursor.
I. Add the information at the beginning of the row.
O (open) adds a row under this row for data input.
O adds a row above this row for data input.
4. Delete and modify
X deletes the character of the cursor.
X deletes the previous field of the cursor.
R replaces the character of the (replace) cursor with the character following this command. For example, RA replaces the character of the cursor with.
R enters the replacement status until ESC.
S. Delete the character of the cursor and enter the input mode until ESC.
S. Delete the row where the cursor is located and enter the input mode until ESC.
5. move the cursor
M <A-z> set bookmarks <A-z>
'<A-z> move to bookmarks <A-z>
0 to the beginning of the row
$ Move to the end of the row.
E. Move to the last letter of the next word.
W moves to the first letter of the next word.
B moves to the first letter of the previous word.
^ Move to the first character of the row.
H. Move to the first line of the window.
M moves to the middle of the window.
L move to the last row of the window.
G to the last row of the file.
+ Move to the first character of the next column.
-Move to the first character in the previous column.
: N is moved to column N of the file.
N + column N after the cursor is located.
N-column N before the cursor position.
<Ctrl> <G> shows the row number, file name, the row number of the last row in the file, and the percentage of the row number of the cursor to the total row number.

(Vim) basic usage of cursor movement:
(You only need to combine the above functions, so you don't have to explain them one by one !)
Ge B w e
Begin certificate --- → -- →
This is-a line, with special/separated/words (and some more ).
Accept-items -- ----------------- → --- →
Ge B w e

6. Move windows
<Ctrl> <F> the window rolls down a page.
<Ctrl> <B> the window rolls a page.
<Ctrl> <D> the window is rolled down for half a page.
<Ctrl> <u> the window is rolled up half a page.
<Ctrl> <E> the window rolls a row to the next volume.
<Ctrl> <Y> the window rolls a row to the upper part.
7. Cut, copy, and delete
Operator + scope = command
7.1.operator
D cut
Y replication.
P paste, Which is used with D and Y. The last d or y data can be placed in the row and column where the cursor is located.
C modification, similar to the group and of Delete and insert. Delete A Word Group, sentence, and other materials, and insert new materials.
7.2 Scope
E is the last character of the string from the cursor position.
W is the first character from the cursor location to the next string.
B is the first character from the cursor position to the previous string.
$ From the cursor location to the last character of the row.
0 is the first character of the row from the cursor position.
7.3 whole row action
Dd deletes the entire row.
D. Delete All characters after the cursor in the unit of action.
CC modifies the entire line.
YY copies the row of the cursor to the memory buffer.
7.4 cancel the previous action (UNDO)
U.
U restores all changes to the row of the cursor.
(Vim) u can undo commands multiple times, undo one operation at a time until this operation starts.
(Vim) Ctrl + R can restore the content before undo, and can be restored multiple times by multiple times.
8. search and replace
/String to search for the string after the cursor.
? Returns the string before the cursor.
N to continue searching for the next same string.
N continues to search for the next same string.
% Find the matching characters.
S searches for a range of rows and columns.
G.
: 1, $ S/old/new/g change all the "old" in the file to "new 』.
: 10th S/^ // insert 5 blank spaces at the top of the rows from 20th.
(Vim)
/Enter the query content behind the string to save it to the buffer. You can select the previous content using the forward slash.
In addition, move the cursor Under the selected word and press *. You can select this word as a query character to avoid the trouble of inputting a long string of characters.
9. (Vim) case-insensitive replacement
First, press V to enable the selection function, and then use the character keys → keys to select the characters to be replaced. If the lowercase letters are changed to uppercase letters, press u; otherwise, press u;
If you want to select a word, you can press V, W, and U/U. In this way, you can change the case of the characters without deleting the words and then retyping them.

10. Data Connection
J sentence connection. Connect the next row of the cursor to the end of the row.
11. Environment setting
: Set all: List of configurable Environment Variables
: Current value of the Set environment variable
: Set nu to set the row number of the data.
: Set Nonu cancel row number setting.
: Set AI is automatically scaled in and out.
: Set noai cancels automatic contraction.
(Vim)
: Set ruler: The current cursor position is displayed in the lower right corner of the screen and changes as the light moves. It occupies a small amount of screen space and is convenient to use. It is recommended to use this function.
: When set hlsearch is used, all matching content is highlighted.
: Set nohlsearch disable this function.
: Set incsearch enables Vim to position matching points during the input string.
: Set nowrapscan disable the automatic search loop function, that is, find the end of the file and end the search. The default status is automatic loop.

13. Ex command
13.1 read and write data

: 10th, 20th test writes data from rows to the test file.
: 10th W> test: add the data of rows 20th to rows after the test file.
: R test reads the data of the test file into the end of the editing buffer.
: E [filename]: edit a new file.
: E! [Filename] discard the modified file and edit the new file.
: Sh: Enter the shell environment, exit with exit, and return to the editor.

:! Run the command CMD and return to the editor.
13.2 Delete, copy, and move
: 10, 20 d delete data from rows 10th to rows 20th.
: 10 days to delete data from the first row.
: % D Delete the entire editing buffer.
: 10, 20co30: Copy data from rows 10th to rows 20th to rows 30th.
: 10, 20mo30: Move the data of row 10th to row 20th to row 30th.


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.