"Linux" Vim editor

Source: Internet
Author: User

This article is based on Debian

1.vim Introduction to use

  1.1vim Installation

Use apt to install vim:

sudo Install Vim

  1.2 Mode of the VIM editor

The Vim editor is divided into command mode and edit mode.

Command mode: Turn on vim by default into command mode, in command mode, a single button on the keyboard represents a command, such as the command to move the cursor: h, I, J, K. Press ESC in edit mode to return to the command mode.

Edit mode: In command mode, press the "I" key to enter edit mode, at which point you can edit the contents of the file like Word.

2. Vim File creation

new file: Vim file name. For example, the command to create a hello.c file is:

  

1 Vim hello.c

  Enter text: when the above command is completed, enter command mode, press "I" key to enter the editing mode, enter the text:

1 #include <stdio.h>23int main (void)4{  5     printf ("Hello World!\n"); 6     return 0 ; 7 }

Exit: After editing the text, press ESC back to command mode, enter ": Wq" to save and exit.

Common commands in 3.vim command mode

  Move cursor: H J k L

H: Left

J: Next

K: Up

L: Right

  Delete character: x dd u ctrl+r

  Delete one character: X

Delete one line of characters: DD

Recover Delete: U

Cancel command: Ctrl+r

  Copy and paste: P y

  Paste: P

Copy: Y

  Find string:/

  Find string in current text hello: ":/hello"

 Jump to a line: G or: N

  The command ": N" allows the cursor to jump to a low n line, or "NG" jumps to the nth row. Note G must be capitalized.

This is useful when modifying the error line of a program or debugger.

  Vim Learning Document: Enter Vimtutor in bash.

Format settings for 4.vim

Number of spaces to set tab: ": Set Tabstop=n"

 For example: Set the TAB key width to 2 spaces: ": Set tabstop=2"

Set line numbers: ": Set Number"

Configuration file for 5.vim VIMRC

Under/etc/vim/There is a configuration file for Vim VIMRC. Vim can be set to take effect when VIM is activated again.

  For example: Add at the end of the file:

Set tabstop=2set number

    

  

  

  

"Linux" Vim editor

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.