VIM
时间:2006-03-17 来源:科罗拉多
3. 如果光标当前位置是括号(、)、[、]、{、},按 % 可以将光标移动到配对的
括号上。
4. 在一行内替换头一个字符串 old 为新的字符串 new,请输入 :s/old/new
在一行内替换所有的字符串 old 为新的字符串 new,请输入 :s/old/new/g
在两行内替换所有的字符串 old 为新的字符串 new,请输入 :#,#s/old/new/g
在文件内替换所有的字符串 old 为新的字符串 new,请输入 :%s/old/new/g
进行全文替换时询问用户确认每个替换需添加 c 选项,请输入 :%s/old/new/gc
1. :!command 用于执行一个外部命令 command。
请看一些实际例子∶
:!dir - 用于显示当前目录的内容。
:!rm FILENAME - 用于删除名为 FILENAME 的文件。
2. :w FILENAME 可将当前 VIM 中正在编辑的文件保存到名为 FILENAME 的文
件中。
3. :#,#w FILENAME 可将当前编辑文件第 # 行至第 # 行的内容保存到文件
FILENAME 中。
4. :r FILENAME 可提取磁盘文件 FILENAME 并将其插入到当前文件的光标位置
后面。
Syntax Coloring
:syntax on
To find out the value of the Background
:set background?
Set Background color to light
:set background=light then you should switch syntax on use :syntax on set Shiftwidth to 4 character :set shiftwidth=4 shift the text to the left (<<) or the right (>>). AutoMatic Indentation cindent
smartindent
autoindent :set cindent :set noautoident --- switch off autoindent =motion Command =% match blocks and indent : for example below: {
if (strcmp (arg, option1) == 0)
return (1) ;
if (strcmp (arg, option2) == 0)
return (1) ;
return (0) ;
}
1) Position cursor on the first "{"
2) Execute the command "=%".
{
if (strcmp (arg, option1) == 0)
return (1) ;
if (strcmp (arg, option2) ==0)
return (1) ;
return (0) ;
} Instant Word Searches Including #include Files
([CTRL-I, ]CTRL-I)
Jumping to a Variable Definition (gd, gD) Jump to Macro Definition ([CTRL-D, ]CTRL-D) Displaying Macro Definitions ([d, ]d, [D, ]D) Matching Pairs
The % command is designed to match pairs of (), {}, or [] Shifting a Block of Text Enclosed in {} use >% Indenting a Block Using Visual Mode
To indent a block using visual mode, follow these steps:
1. Position the cursor on the left or right curly brace.
2. Start visual mode with the v command.
3. Select the inner {} block with the commandi}.
4. Indent the text with >. Finding the man Pages
The K command runs a UNIX man command using the word under the cursor as a subject. Tags
ctags-------This program comes with Vim To generate the table of contents file, which is named tags, use the following command:
$ ctags *.c
:tag myfunction This command will find the function even if it is another file.
Tag jumping with CTRL-]. CTRL-] command jumps to the tag of the word that is under the cursor. The :tags command shows the list of the tags that you have traversed through The CTRL-T command goes the preceding tag. Windows and Tags---Split the windows and find tag in new window
:stag tag CTRL-W] command splits the current window and jumps to the tag under the cursor in the upper window :set list
n this mode, tabs show up as ^I. Also the editor displays $ at the end of each line Sorting a List in Visual Mode
To sort a list using visual mode, you need to execute the following commands:
1. Move to the top of the text to be sorted.
2. Start line visual mode with the command V.
3. Move to the bottom of the text to be sorted.
4. Execute the command !sort.The ! tells Vim to pipe the selected text through a command. Making the Program :make //press Enter to see where errors Goes to where the next error occurs
:cnext :cprevious :cNext goes to the previous error. :clast goes to the last error :crewind goes to the first. :cnfile goes to first error message for the next file If you forget what the current error is, you can display it using
:cc
To see a list of errors, execute this command:
:clist Searching for a Given String :grep -w my2find *.c use the :cnext, :cprevious, and :cc commands to page through the list of matches. Saving Your Setting
:mkvimrc filename writes all your mappings , abbrevations , settings to a file.
You can read this file by using the following command:
:source file My .vimrc File
My .vimrc file contains the following:
:syntax on
:autocmd FileType * set formatoptions=tcql
\ nocindent comments&
:autocmd FileType c,cpp set formatoptions=croql
\ cindent comments=sr:/*,mb:*,ex:*/,://
:set autoindent
:set autowrite
:ab #d #define
:ab #i #include
:ab #b /****************************************
:ab #e <Space>****************************************/
:ab #l /*-------------------------------------------- */
:ab #j Jack Benny Show
:set shiftwidth=4
:set hlsearch
:set incsearch
:set textwidth=70
相关阅读 更多 +