Vim getting started

Source: Internet
Author: User

Vim getting started

VIM and EMACS have been working for a while. But as a JAVA program, it is not realistic to use VIM to write JAVA code (IDEA is used now. I recently felt that VIM was good when I was writing front-end code and blogs, so I decided to pick up VIM.

The bare VIM is not very easy to use. You need to install the required plug-ins. The previous method was to download the corresponding compressed package and modify the configuration. This process is extremely patient and character-oriented!

Use vundle management plug-in

Vundle removes the need to find plug-ins and configurations. All plug-ins are managed in a similar way, greatly reducing the cost of use!

The path where the plug-in is stored is ~ /. Vim/bundle/. After the directory is created, download vundle:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Later configurations can be found in ~ /. Completed in vimrc:

Set nocompatible "Disable compatibility mode filetype off" Disable Automatic file type detection set rtp ++ = ~ /. Vim/bundle/Vundle. vim "add to runtime path call vundle # begin ()" initialization "ins list start in 'vundlevim/Vundle. vim '" call vundle # end ()" complete filetype plugin indent on "open file type detection

Common plug-in source configurations include:

Source Description
Github.com Plug-ins hosted on github (Plugin 'tpope/vim-fugitive ')
Vim-scripts.org/vim/scripts.html Plug-ins maintained on the site (Plugin 'd9 ')

After the configuration is complete, open VIM and use the following command:

  1. : PluginList: Open the plug-in list
  2. : PluginInstall: Install the plug-in
  3. : PluginSearch foo: Search for plug-ins. You can choose to install the plug-ins after finding them.
  4. : PluginClean: Clear unused plug-ins (this is not very understandable)

Finally, when you want to install the winmanager plug-in:

  1. Add in. vimrcPlugin 'winmanager'
  2. Open vim
  3. Run:PluginListYou can see the winmanager plug-in.
  4. Run:PluginInstallInstall

Is it much simpler than before? There is no complicated plug-in management. Now we will go to VIM!

Basic usage

I was very uncomfortable switching from EditPlus to VIM. I just wanted to edit the file, but I still had to consider switching to different modes:

  1. Command mode
  2. Edit mode
  3. Visual Mode

After a long time, it seems reasonable to separate the text. In the command mode, you can use some simple commands to quickly view and modify the text, it is more efficient than using the mouse in EditPlus. This mode uses a lot of commands, which are classified below!

I. move the cursor

You can jump to any dimension at will:

Command Function
H/j/k/l Move up/down/up/right
Ctrl + f/B Flip up/down
Ctrl + d/u Flip up/down half page
$/0/^ End of line/beginning of Line
(/) Previous sentence/next sentence
W/B Next word/previous word
Gg/G Document start/end
% Matching of parentheses
Ngg/nG/: n To row n
H/M/L Screen top/middle/Bottom
*/# Position of the next or last occurrence of the Current Character
2. search and replace
Command Function
: S/s1/s2 Replace the next s1 WITH s2
: % S/s1/s2 Replace all s1 WITH s2
: S/s1/s2/g Replace s1 of the current row with s2.
: N1, n2 s/s1/s2/g Replace s1 from line n1 to line n2 with S2.
/Xxxx Search for xxxx, find and continue searching by n, and then continue searching by N
Mx Insert a bookmark (x is a lowercase letter). You can use 'x' to jump to this bookmark later.
'. Last edited location
Iii. Copy, cut, paste, and delete

Some registers exist in VIM to store the copied and deleted content:

  1. ": Recently deleted or copied content
  2. 0: Recently copied content
  3. 1、2、、9: Add the last deleted content to 1, the original content to 2, and so on.
  4. %: File Name
  5. :: Command
  6. /: String to be searched

You can use reg to view the content in each register during editing! To facilitate the selection of the visual mode introduced in text VIM, first move the cursor to the start position, and then run the following command to enter the visual mode:

  1. ctrl+v: Block
  2. v: Normal
  3. V: Line

Move the cursor to select and operate the text! Frequently Used commands for editing include:

Command Function
Y Copy the selected text and use"nyTo copy to register n
X Cut selected text or delete current character
D Delete selected text
P Paste"npTo paste the content in register n.
Dd Delete current row
Dw Delete a word after the cursor
Dl Delete a character
D/C Delete to end of line
Yy/Y Copy a row

You can useuAndctrl+rTo perform undo and redo operations.

Iv. macros

Some simple and mechanical operations are often encountered during data creation, which can be done with macros:

  1. px: Starts macro recording. x is a lowercase letter.
  2. Operation
  3. q: Record operations to registers
  4. @x: Execute operations in register x
  5. @@: Execute the last recording.

You can also use: reg to view the register status.

5. Edit

Run the following command to enter the insert mode:

Command Description
I/ Insert before/after the cursor
I/ Insert at the beginning/end of a row
O/O Insert a row before/after to edit
S/S Delete one character/line for editing
R Replacement mode, which is very useful for drawing
Multi-screen operations

When writing code, it is common to write several files. It is very comfortable to split several screens. The following methods can be used to enable split screens:

  1. vim -On file1 file2 ...: Open multiple files on the Vertical Split screen
  2. vim -on file1 file2 ...: Open multiple files on the horizontal split screen
  3. ctrl+w s: Splits the current file up and down
  4. ctrl+w v: Split the current file horizontally
  5. :sp filename: Split up and down to open a new file
  6. :vsp filename: Open a new file horizontally

To switch the working screen, run ctrl + w h/j/k/l/w. h/j/k/l moves in the direction and w moves to the next screen! You can use ctrl + w H/J/K/L to move the split screen when you think the screen sequence is a little uncomfortable. You can also adjust the screen size:

  1. ctrl+w =: The height of all screens is the same
  2. ctrl+w -: Height reduction
  3. ctrl+w +: Increase the height

During editing, you can browse the directory on the split screen:

  1. :He: Split up and down the screen, in the following (:He!On the top) browse the Directory
  2. :Ve: Left/right split screen, on the left side (:Ve!View the directory on the right.

You can also use: E to open the directory on the current screen for browsing. You can use some commands to perform operations:

  1. -: Go to the parent directory
  2. s: Sort files
  3. x: Execution File
  4. R: Modify file name
  5. D: Delete an object
  6. Enter: Go to the subdirectory

While reading and writing, You Need To synchronously scroll on multiple screens.:set scbAnd:set scbTo bind and unbind (this function is still very useful )! Finally, you can usectrl+w cOrctrl+w q(If it is the last screen, exit VIM) to close the split screen!

Summary

Having mastered this, it should be difficult to edit simple text. Later, we will write more details separately.

For more Vim tutorials, see the following:

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

This article permanently updates the link address:

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.