Configuration of Vim under Ubuntu

Source: Internet
Author: User
Tags save file set background switches

since the beginning of learning Linux, like Blake Multi-operation is not familiar with, encountered some difficulties, recorded here.

1 Install VIM. I now understand that Vim has a console version and a GUI version. Console version seems to be the Ubuntu comes with, you can enter VIM in the terminal to perform a bit. GUI version takes itself under, executed at the terminal

sudo apt-get INSTALLVIM-GTK can be installed.

2 followed by setting some properties.

Enter the root directory at the terminal input sudo-s,

Then enter the password, then the CD Etc/vim

Followed by Vim VIMRC

At this point, the contents of ETC/VIM/VIMRC will appear. Roughly as follows:

Roughly as follows:

"All system-wide defaults is set in $VIMRUNTIME/debian.vim (usually just
"/usr/share/vim/vimcurrent/debian.vim" and sourced by the call To:runtime
"You can find below." If you wish to change any of those settings,you should
"Do it in this file", since Debian.vim would beoverwritten/ETC/VIM/VIMRC
"Everytime an upgrade of the VIM packages is performed. It isrecommended to
"Make changes after sourcing debian.vim since it alters the valueof the
"' Compatible ' option.

"This line should is removed as it ensures that variousoptions is
"Properly set to work with the vim-related packages available Indebian.
runtime! Debian.vim

"Uncomment the next line to make Vim more vi-compatible
"NOTE:debian.vim sets ' nocompatible '. Setting ' compatible ' changes numerous
"Options, so any other options should is set after setting ' compatible '.
The Set compatible

"VIM5 and later versions support syntax highlighting. Uncommentingthe Next
"Line enables syntax highlighting by default.
"Syntax on

"If using a dark background within the editing area and syntaxhighlighting
"Turn on this option as well
The Set Background=dark

"Uncomment the following to has Vim jump to the last Positionwhen
"Reopening a file
"If has (" Autocmd ")
"Au bufreadpost * if line (" ' \ "") > 0 && line ("' \" ") <= Line (" $ ")
"    \| EXE "normal g ' \" "| endif
"EndIf

"Uncomment the following to has Vim load indentation rulesaccording to the
"Detected filetype. Per default Debian Vim only load filetypespecific
"Plugins.
"If has (" Autocmd ")
"FileType indent on
"EndIf

"The following is commented out as they cause vim to behave alot
"Differently from regular Vi. They is highly recommendedthough.
"Set ShowCmd" Show (partial) command in the status line.
"Setshowmatch" showmatching brackets.
"Setignorecase" do caseinsensitive matching
"Setsmartcase" do smartcase matching
"Setincsearch" Incremental Search
"Setautowrite" Automatically save before commands Like:next And:make
"Sethidden" Hide buffers when they is abandoned
"Set Mouse=a" Enablemouse usage (all modes) in terminals

"Source a global configuration file if available
"XXX Deprecated, please move your changes here IN/ETC/VIM/VIMRC
If Filereadable ("/etc/vim/vimrc.local")
Source/etc/vim/vimrc.local
endif

then press the i key (Insert command), at this point in the bottom of the "--insert--" the word, and then insert the following statements into the last (can be based on the comments with their own needs to choose, Not necessarily all written)

Setai "Auto indent, new line and previous row hold-auto space
Set AW "Auto write, transfer to shell or use: N edit other file, current buffer is written
Set Flash "flashes at error but does not bark" (default)
Set IC "Bribery case when querying and pattern matching
Setnu
Set Number screen shows line numbers on the left
Setshowmatch "Show bracket pairing, when typing"] ", high brightness displays matching parentheses
Setshowmode mode indicator in the Highlight button bar in text input mode
Setshowcmd "Displays the currently executed instruction in the status bar, and the unfinished command fragment will also be displayed.
Setwarn/nowarn "After a new modification to the text, the system gives the display when leaving the shell (default)
Setws/nows "When searching for the end of the file, go back to the file header to continue searching
Setwrap/nowrap "long line shows automatic wrapping
ColorScheme Evening "Setting the background for night mode
FileType Pluginon "Automatically identifies file types, automatically matches corresponding," file type Plugin.vim "files, using indentation definition files
Setautoindent "Set auto indent: The indent value for each line is equal to the previous line; Use Noautoindent to cancel the setting
Set cindent "indent in C + + mode
Setnoignorecase "Default case sensitive
Setruler "Open the status bar ruler
Setscrolloff=5 "The window automatically scrolls when the cursor is 5 rows from the upper and lower bounds of the window
setshiftwidth=4 "Settings << and >> command width of 4 when moving
Set softtabstop=4 "so that when the backspace bar can be deleted at a time 4 spaces, less than 4 delete all the remaining space)
settabstop=4 "Set tab length to 4
Setwrap "Wrap Line display
Syntax enable
Syntaxon "Automatic syntax highlighting

Then press ESC to exit the edit state, and the following "--insert--" disappears.

Then press: W to save the file

Then: Q quit vim to return to the terminal

This completes the installation and setup of Vim.

Some VIM related knowledge is included:

A basic knowledge

One of the most confusing features of Vim is that she has 3 modes.

Insert mode: Enter text

Command mode: Executes the command. Also known as normal mode.

Ex mode: Execute colon command

Insert mode is not the default mode, you must press I to enter the insert mode, enter some text on the screen. Pressing the button will go from Insert mode to command mode. The command pattern is used to move and manipulate text, sometimes in very interesting ways. The ex mode is used to execute colon commands, such as Save, find/Replace, and configure Vim. To save the text, you only need to enter in normal mode: Enter ex mode and enter: Wfilename. To exit vim, execute the colon command: Q. Summarized below,
Vim (start vim)
I (enter insert mode)
< Enter text >
(Back to command mode)
: w filename (save file as ' filename ')
: Q (Exit Vim)
Vim filename (Opens the file you just saved in vim)

Keep in mind that the best way to learn vim is to use her. You can learn the basic use of vim with the built-in vim tutorial, just enter Vim-tutor in the terminal (enter Vimtutor in dapper).

Two common commands

When you enter VI, you will first enter the command mode (also edit mode).
Press I to enter the insertion method, the user entered the visual characters are added to the file, displayed on the screen.
Press ESC to return to the command state (also edit mode).
The way you edit and command is similar, you have to enter a command,
But its command does not start with: it directly accepts the keyboard input single character or the combined characters command,
For example, pressing u directly means canceling the last modification of the file, which is equivalent to the undo operation under Windows.
There are some commands to be started in the compilation mode,
For example, the Find string is:/string matches the Find string string in the file.
Press in edit mode: Enter command mode.
Basic command Explanation:
1. Cursor command
K, J, H, l--up, down, left, right cursor move command.
Although you can use the 4 cursor keys on the right side of the keyboard in Linux,
But it is still very useful to remember these 4 commands. These 4 keys are the basic positions that the right hand places on the keyboard.
ng--jump command. n is the number of rows, and the command immediately causes the cursor to jump to the specified line.
ctrl+g--the number of rows and columns in the cursor location report.
W, b--causes the cursor to skip forward or backward through a word.
2. Edit command
I, a, r--insert character commands (I=insert, A=append, R=replace) before, after, and where the cursor is located.
CW, dw--Change (displace)/delete the command (C=change, d=delete) of the word where the cursor is located.
X, d$, dd--delete one character, delete all characters at the end of the line, and delete the entire line.
3. Find command
----/string,? string--the command to find the appropriate string from the cursor location, backward or forward.
4. Copy Copy command
----yy, p--copies a row to the Clipboard or takes out the contents of the Clipboard command.
Common operations:
Whether you are opening a new file or modifying an old one, you can use VI, which requires the following instructions:
$ VI Filemane
If the file is new, you'll see a message at the bottom of the screen telling the user that a new file is being created.
If the file already exists, VI displays the first 24 lines of the file, and the user can then move up or down with the cursor.
~
~
Above is a VI open simulation file, a line at the beginning of the twists and turns (~) indicates the end of the file.
-instruction I inserts the body at the cursor
-instruction I inserts the body at the beginning of a line
-instruction a appends the text to the cursor
-instruction a appends the body at the end of the line
-Command o opens a new line below the cursor
-Command o opens a new line above the cursor
In the Insert mode, cannot enter the instruction, must first press the 〈esc〉 key, returns the command way.
If the user does not know what the state, you can also press the 〈esc〉 key, regardless of the state, will return to the command mode.
When you modify a file, it is important to archive and exit the specified file. Within VI, when the command to archive or exit is exercised,
To change the command by a colon (:), the user can see the colon (:) in the lower left of the screen,
Display VI has been changed to the instruction state, can be archived or exited work.
: q! Discard any changes and exit VI, that is, forcibly quit
: W Archive
: w! Forcibly archive for read-only files
: Wq Archive and Exit VI
: x works the same as Wq
: ZZ Deletes the text as Wq works
The deletion or modification of the body is made using the editing method, so the instructions mentioned below only need to be edited.
Type the instructions directly.
-X removes the character at the cursor (Character)
-nx Delete the next n characters at the cursor
-NX Delete the first n characters at the cursor
-NDW Delete the next n words at the cursor (word)
-DD Delete an entire row
-d$ or D is deleted by the cursor to the bottom of the line
-U restores the previous delete
When you use VI to modify the body, add and subtract characters, you will take another set of instructions to operate in edit mode.
-R Char replaces the character at the cursor by Char
-rtext〈esc〉 text instead of the character at the cursor
-cwtext〈esc〉 replaces the word at the cursor by text
The-ctext〈esc〉 is replaced by the text cursor at the end of the line
-CC makes the whole line blank, but retains the cursor position, allowing you to start entering
-As with the delete instruction, the number that is scored before the instruction indicates how many times the instruction was executed.

To retrieve a file, you must do so in edit mode.
-/str〈return〉 forward to Str until end of file
-?str〈return〉 to search for STR until the file opens in the first place.
-N repeat search in same direction
-N repeat search in opposite direction
-vi wraps the entire file and retrieves it continuously until it finds the next occurrence that matches the pattern.
Full Replacement command:
:%s/string1/string2/g Replace "string1" into "string2" throughout the file.
If you want to replace the path in the file:
Use the command ":%s#/usr/bin#/bin#g" to change all the paths in the file/usr/bin to/bin.
You can also use the command ":%s/\/usr\/bin/\/bin/g" Implementation, where "\" is an escape character, indicating that subsequent "/" characters are characters that have practical meaning, not delimiters.

Edit 2 files Simultaneously, copy the text from one file and paste it into another file:
The command is as follows:
----VI file1 file2
----YY in the cursor at the file 1 copy the row
----: n Switch to File 2 (n=next) or press CTRL+WW, switch between two files.
----p Pastes the copied row at the cursor where the file 2 is located
----: N switches back to file 1 (Ctrl +WW also switches)

Save a part of the file to a temporary file,
For example, just save the contents of line 20th to 59th to file/tmp/1, we can type the following command.
----VI File
----: 20,59W/TMP/1

If you want to go to shell execution during VI execution, use an exclamation point (!) to execute the system instructions,
For example, during VI, listing the contents of the current directory, you can type:
:!ls
On the other hand, the user can create a. EXRC environment file in the home directory, with set-entry options,
Each time you call VI, you will read the instructions and settings in the. Exrc. Here's an example of a. EXRC environment file:
Set Wrapmarging=8
Set Showmode
Set Autoindent

Configuration of Vim under Ubuntu

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.