Vim usage notes under Linux

Source: Internet
Author: User
Tags delete key

Environment: Window can be used Gvim editing software learning is mainly in the UBUNTU15 percussion command
Learn videos from Zhipu education vim using video
1. sudo apt show vi to view the installed version of VI, of course, my Ubuntu two can see the installed
sudo apt show vim
According to the video, Ubuntu is installed by default is the version of Vim-tiny, this version of the VIM keyboard keys can not be used, backspace, delete key can not be used
sudo apt show vim-tiny view installed Vim-tiny

Under the Cd/usr/bin directory
Ls-l vi to view the installation directory of VI

sudo apt search vim find Vim's installation package, specifically what is not understood
sudo apt install vim installs full version, enhanced version. My tips for installing the VIM runtime

The VIM after installation is much more useful than it used to be.

Basic use of 2.vim
2.1 Enter
Touch Hello Create File
VI Hello Open File
Enter into the Vim,vim in general mode of operation,
Cannot write text, only a few actions
This state is called the Vim general operating mode.
Move cursor
Copy, delete, paste
2.2 Input
Press I to enter edit mode, from operation mode to edit mode
After vim edits a line, it is recommended to press ESC after the O key to enter the next line.
Press ESC and press K to move the cursor up
It is recommended that you enter edit mode only when you want to edit the file, usually in general mode.
A key is inserted in front of the cursor
I insert before cursor
2.3 Save
ESC enters General mode,
: Enter the last command mode.
: W Save
: Q exit
: Wq Disk to exit
: q! does not save exit

2.4 Exit
: Q exit
: Wq Disk to exit
: q! does not save exit
Practice Code
#include <stdio.h>

int main (int argc, char * argv[])
{
printf ("Hello world!\n");
return 0;
}
3.vim single file inside copy and paste operation
SHIFT + O adds one line to the previous line of the cursor
In normal mode, which is the ESC mode, the copy is represented by YY.
P indicates that the current line is pasted below
SHIFT + P (uppercase) indicates that the current line is pasted above
X in general mode means delete character

4YY Copy Current line below 4 lines
Shear
NDD DD Delete current row NDD Delete the currently starting contiguous n rows

Replace Mode general mode
R replaces the character you want to replace.
Practice Code
#include <stdio.h>
int add (int a, int b)
{
return a + B;
}
int minus (int a, int b)
{
return b-a;
}

int main (int argc, char * argv[])
{
int sum = 0, x = N, y = 14;
printf ("Hello world!\n");
sum = Add (x, y);
printf ("x =%d y =%d sum =%d\n", x, y, sum);
sum = minus (x, y);
printf ("x =%d y =%d min =%d\n", x, y, sum);
return 0;
}
4.vim inter-file assignment and paste operation
CP hello.c math.c copy files. Delete the main function into the math file
10DD Delete 10 rows
8DD Delete 8 rows
Multi-file text copy without split screen mode
: E math.c calls other files to vim,
After the copy command is executed,
: E hello.c back to the original file.
To perform a paste operation


Split screen replication
SP Math.cs up and down screen display two files
Switching of two file windows
Switch between the CTRL + WW window.

VSP Vertical split Screen
: Wqall all files and exits

VI Display line number inside
: Set NU Displays line number
: Set Nonu does not display line numbers
VI Syntax highlighting
: Syntax off syntax highlighting
: Syntax on to turn on syntax highlighting

Practice Code
Math.c
#include <stdio.h>
int add (int a, int b)
{
return a + B;
}
int minus (int a, int b)
{
return b-a;
}
hello.c
Include <stdio.h>
int add (int a, int b)
{
return a + B;
}
int minus (int a, int b)
{
return b-a;
}
int main (int argc, char * argv[])
{
int sum = 0, x = N, y = 14;
printf ("Hello world!\n");
sum = Add (x, y);
printf ("x =%d y =%d sum =%d\n", x, y, sum);
sum = minus (x, y);
printf ("x =%d y =%d min =%d\n", x, y, sum);
return 0;
}

5.vim lookups are in general mode.
ESC/Find, the cursor will be automatically to the location where it appears.
The N key toggles the matching value up or down.

Shift + k View Help documentation
Q exit
/is search is current cursor down search.
? Is the current cursor upward search.
N Next SHIFT + N Previous

6.vim replacement
: Starting point, End point s/replaced string/replacement string
: 2,9s/int/float
: 2,9s/int/float/g/g means replace all.
:%s/int/float/g% indicates full text

U undo Operation
:%S/INT/FLOAT/GC Comfir says to need confirmation.

Vim usage notes under Linux

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.