Vi Cheat Sheet( vi 小抄)
来源:互联网 发布:乎怎么读音 编辑:程序博客网 时间:2024/05/17 08:29
Vi Cheat Sheet
- Modes
- Quitting
- Inserting Text
- Motion
- Deleting Text
- Yanking
- Changing Text
- Putting Text
- Buffers
- Markers
- Searching
- Replacing Text
- Regular Expressions
- Counts
- Ranges
- Files
- Other
Click here for the Advanced VI Cheatsheet
Modes
Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for "colon" commands which execute when you press the ruturn key.
Quitting
:xExit, saving changes:qExit as long as there have been no changesZZExit and save changes if any have been made:q!Exit and ignore any changes
Inserting Text
iInsert before cursorIInsert before lineaAppend after cursorAAppend after lineoOpen a new line after current lineOOpen a new line before current linerReplace one characterRReplace many characters
Motion
hMove leftjMove downkMove uplMove rightwMove to next wordWMove to next blank delimited wordbMove to the beginning of the wordBMove to the beginning of blank delimted wordeMove to the end of the wordEMove to the end of Blank delimited word(Move a sentence back)Move a sentence forward{Move a paragraph back}Move a paragraph forward0Move to the begining of the line$Move to the end of the line1GMove to the first line of the fileGMove to the last line of the filenGMove to nth line of the file:nMove to nth line of the filefcMove forward to cFcMove back to cHMove to top of screenMMove to middle of screenLMove to botton of screen%Move to associated ( ), { }, [ ]
Deleting Text
Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:xDelete character to the right of cursorXDelete character to the left of cursorDDelete to the end of the lineddDelete current line:dDelete current line
Yanking Text
Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:yyYank the current line:yYank the current line
Changing text
The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For wxample cw changes a word. A few other change commands are:CChange to the end of the lineccChange the whole line
Putting text
pPut after the position or after the linePPut before the poition or before the line
Buffers
Named buffers may be specified before any deletion, change, yank or put command. The general prefix has the form "c where c is any lowercase character. for example, "adw deletes a word into buffer a. It may thereafter be put back into text with an appropriate "ap.
Markers
Named markers may be set on any line in a file. Any lower case letter may be a marker name. Markers may also be used as limits for ranges.mcSet marker c on this line`cGo to beginning of marker c line.'cGo to first non-blank character of marker c line.
Search for strings
/stringSearch forward for string?stringSearch back for stringnSearch for next instance of stringNSearch for previous instance of string
Replace
The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).:s/pattern/string/flagsReplace pattern with string according to flags.gFlag - Replace all occurences of patterncFlag - Confirm replaces.&Repeat last :s command
Regular Expressions
. (dot)Any single character except newline*zero or more occurances of any character[...]Any single character specified in the set[^...]Any single character not specified in the set^Anchor - beginning of the line$Anchor - end of line\<Anchor - begining of word\>Anchor - end of word\(...\)Grouping - usually used to group conditions\nContents of nth grouping
In the second character position, the SET containing all letters
Note the use of ( ) with the pipe symbol to specify the 'or' condition/[0-9]*/Matches if there are zero or more numbers in the line/^[^#]/Matches if the first character is not a # in the lineNotes:
1. Regular expressions are case sensitive
2. Regular expressions are to be used where pattern is specified
Counts
Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example, 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurence of the letter e. Even insertions may be repeated conveniently with thismethod, say to insert the same line 100 times.
Ranges
Ranges may precede most "colon" commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s/pattern/string/g to make a replacement from the current line to the end of the file.:n,mRange - Lines n-m:.Range - Current line:$Range - Last line:'cRange - Marker c:%Range - All lines in file:g/pattern/Range - All lines that contain pattern
Files
:w fileWrite to file:r fileRead file in after line:nGo to next file:pGo to previos file:e fileEdit file!!programReplace line with output from program
Other
~Toggle upp and lower caseJJoin lines.Repeat last text-changing commanduUndo last changeUUndo all changes to line
- Vi Cheat Sheet( vi 小抄)
- vi vim cheat sheet
- Advanced Vi Cheat Sheet
- Vi Cheat Sheet
- VI/VIM Graphical Cheat Sheet
- Graphical vi-vim Cheat Sheet and Tutorial
- 程序员工具大全(CHEAT SHEET 小抄大全)
- [ZZ] Graphical vi-vim Cheat Sheet and Tutorial
- GBin1分享10个移动设备开发需要的"小抄"(Cheat Sheet)
- Cheat Sheet
- Cheat Sheet
- VI
- vi
- vi
- vi
- vi
- vi
- VI
- Linux:Tar
- 【第十二章】零配置 之 12.1 概述 12.2 注解实现Bean依赖注入 ——跟我学spring3
- Android最经典的入门手册
- Common Lisp --- Fibonacci 序列
- 【第十二章】零配置 之 12.3 注解实现Bean定义、12.4基于Java类定义Bean配置元数据 ——跟我学spring3
- Vi Cheat Sheet( vi 小抄)
- 科大讯飞17亿增发助阵语音云技术链应用
- ACM大牛!!!
- 历史性的一课,神十美女航天员王亚平,太空授课。
- 学习编程的5点忌讳
- 樊磊:车载导航的云时代
- zencart 网店系统的安全
- SQL Injection Attacks by Example
- POI导入2003和2007到数据库