Learning.the.vi.and.Vim.Editors

Simple Editing

两种模式:命令模式和插入模式.

ESC退出到命令模式, i进入插入模式.

1. 光标的移动

0(数字): 移动光标到行首

$: 移动光标到行尾, 2$: 移动光标的下一行的行尾, 4$= 3j + $

h: 左移一个光标

j: 下移一个光标

2k: 上移两个光标

4l: 右移4个光标

+: 转到下一行的首字符

-: 转到上一行的首字符

b or B: 前一个单词(或当前单词)词首, 大写B: 前一个单词的词首, 不算计数符号和标点符号

e or E: 后一个单词(或当前单词)词尾

w or W: 后一个单词词首, , 大写W: 后一个单词的词首, 不算计数符号和标点符号

G: 移动要一个特定的行, 可以使用G命令. G移动到文件末尾, 1G移动到文件开头, 43G移动到43行. 

 

2. 简单的编辑

注: 前面加上数字,表示多次执行该命令.

i for insert; a for append; c for change; and d for delete.

move text with a d for "delete", then a p for "put".

copy text with a y for "yank", then a p for "put".

i: (insert)在光标前处插入

a: (append)在光标后插入

c: changing text, leave you in insert mode until u press the ESC key.

cw: To the end of a word

c2b: Back two words

c$: to the end of line

c0: to the beginning of line

 

Words

cw: delete the word marked and insert new text until ESC is pressed

Lines

cc: replace the entire current line until ESC is pressed.

C=c$: replace characters from the current cursor position to the end of the line.

Characters

x: delete only one or 2 characters.

r: replaces a single character with another single character. U do not have to press ESC.

Substituing text(替换文本), leave u in insert mode

s: replace a single character

S: replace wholes lines.

R: enters overstrike(覆写) mode. leave u in insert mode.

Changing Case

~: change a lowercase letter to uppercase or an uppercase letter to lowercase.

Deleting Text

dw: delete by word, 删除当前光标 至 下个单词开始字符 之间的所有字符, 包括空格.

de: 删除当前光标 至当前单词的最后一个字符. 不包括后面的空格(如果有的话)

dE: 同上, 不过它将标点符号视为普通字符, 如 "text,abc" 如果逗号后面没有空格的话, 该命令视其为一个单词来删除.

dd: delete the entire line that the cursor is on.

D=d$: delete from the cursor position to the end of the line.

Moving text

just like a "cut and paste"

p: puts the text that is in the buffer after the cursor position.

P: puts the text before the cursor

Transposing(调换,互换) two letters

xp: delete character and put after cursor

Copying Text

y for yank and p for put.

yy: copy an entire line

Y=yy; Notice is not same as D=d$ & C=c$;

Repeat command

.(the period): repeat the same editing command

Undo

u: undo your last command

U: undo all edits on a single line, as long as the cursor remains on that line. Once you move off a line, you can no longer user U.

Redo:

CTRL-R: redo an undone operation.

 

some other insert commands for inserting text at different positions relative to the cursor:

注: 除了R之外, 其余几条命令执行后, 均处于insert模式

 A: Append text to end of current line

I: Insert text at beginning of line

o(小写字母o): 在当前光标的下一行插入新行

O(大写字母o): 在当前光标的上一行插入新行

s: 删除当前光标下的字符, 并且替换text. 进入insert模式, 相当于xi.

S: 删除当前行, 替换为新text. 相当于0D.

R: 用新字符覆写旧字符. 进入replace 模式, 可使用bakespace先前移动光标, 且恢复覆写内容.

 

插入命令的数字参数

50i*ESC: 插入50个星号

25i*-ESC: 插入50个字符, 25对"*-"

 

 Joining Two Lines with J

J: 连接当前光标所在行和下一行 成一行, 之后, 光标位于连接处(第二行的第一个字符处)

 

在.vimrc中设置显示行号: set nu, 或在命令模式输入":set nu"

 

实用中文帮助手册:http://yangbo.name:88/wp_page/vi/

英文帮助手册: http://vimdoc.sourceforge.net/htmldoc/

转载于:https://www.cnblogs.com/xlmeng1988/archive/2012/06/04/2535191.html

注:下载后,评价给5星,还你11分 Part I. Basic and Advanced vi 1. The vi Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 A Brief Historical Perspective 5 Opening and Closing Files 6 Quitting Without Saving Edits 10 2. Simple Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 vi Commands 13 Moving the Cursor 14 Simple Edits 18 More Ways to Insert Text 30 Joining Two Lines with J 31 Review of Basic vi Commands 32 3. Moving Around in a Hurry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Movement by Screens 35 Movement by Text Blocks 38 Movement by Searches 39 Movement by Line Number 43 Review of vi Motion Commands 44 4. Beyond the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 More Command Combinations 47 Options When Starting vi 48 Making Use of Buffers 51 Marking Your Place 52 Other Advanced Edits 53 Review of vi Buffer and Marking Commands 53 vii 5. Introducing the ex Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 ex Commands 55 Editing with ex 58 Saving and Exiting Files 63 Copying a File into Another File 65 Editing Multiple Files 65 6. Global Replacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Confirming Substitutions 72 Context-Sensitive Replacement 73 Pattern-Matching Rules 74 Pattern-Matching Examples 81 A Final Look at Pattern Matching 89 7. Advanced Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Customizing vi 95 Executing Unix Commands 99 Saving Commands 103 Using ex Scripts 114 Editing Program Source Code 120 8. Introduction to the vi Clones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 And These Are My Brothers, Darrell, Darrell, and Darrell 125 Multiwindow Editing 126 GUI Interfaces 127 Extended Regular Expressions 128 Enhanced Tags 129 Improved Facilities 134 Programming Assistance 138 Editor Comparison Summary 140 Nothing Like the Original 141 A Look Ahead 141 Part II. Vim 9. Vim (vi Improved): An Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Overview 146 Where to Get Vim 150 Getting Vim for Unix and GNU/Linux 151 Getting Vim for Windows Environments 156 Getting Vim for the Macintosh Environment 157 Other Operating Systems 157 viii | Table of Contents Aids and Easy Modes for New Users 157 Summary 158 10. Major Vim Improvements over vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Built-in Help 159 Startup and Initialization Options 160 New Motion Commands 167 Extended Regular Expressions 169 Customizing the Executable 171 11. Multiple Windows in Vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Initiating Multiwindow Editing 174 Opening Windows 177 Moving Around Windows (Getting Your Cursor from Here to There) 180 Moving Windows Around 181 Resizing Windows 183 Buffers and Their Interaction with Windows 186 Playing Tag with Windows 190 Tabbed Editing 191 Closing and Quitting Windows 192 Summary 193 12. Vim Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 What’s Your Favorite Color (Scheme)? 195 Dynamic File Type Configuration Through Scripting 205 Some Additional Thoughts About Vim Scripting 213 Resources 218 13. Graphical Vim (gvim) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 General Introduction to gvim 220 Customizing Scrollbars, Menus, and Toolbars 225 gvim in Microsoft Windows 236 gvim in the X Window System 237 GUI Options and Command Synopsis 237 14. Vim Enhancements for Programmers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Folding and Outlining (Outline Mode) 240 Auto and Smart Indenting 251 Keyword and Dictionary Word Completion 259 Tag Stacking 268 Syntax Highlighting 270 Compiling and Checking Errors with Vim 279 Some Final Thoughts on Vim for Writing Programs 284 Table of Contents | ix 15. Other Cool Stuff in Vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Editing Binary Files 285 Digraphs: Non-ASCII Characters 287 Editing Files in Other Places 289 Navigating and Changing Directories 290 Backups with Vim 292 HTML Your Text 293 What’s the Difference? 294 Undoing Undos 296 Now, Where Was I? 297 What’s My Line (Size)? 300 Abbreviations of Vim Commands and Options 302 A Few Quickies (Not Necessarily Vim-Specific) 303 More Resources 304 Part III. Other vi Clones 16. nvi: New vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Author and History 307 Important Command-Line Arguments 308 Online Help and Other Documentation 309 Initialization 309 Multiwindow Editing 310 GUI Interfaces 311 Extended Regular Expressions 311 Improvements for Editing 312 Programming Assistance 315 Interesting Features 315 Sources and Supported Operating Systems 315 17. Elvis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 Author and History 317 Important Command-Line Arguments 317 Online Help and Other Documentation 319 Initialization 319 Multiwindow Editing 320 GUI Interfaces 323 Extended Regular Expressions 328 Improved Editing Facilities 328 Programming Assistance 332 Interesting Features 335 elvis Futures 340 x | Table of Contents Sources and Supported Operating Systems 340 18. vile: vi Like Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 Authors and History 343 Important Command-Line Arguments 344 Online Help and Other Documentation 345 Initialization 346 Multiwindow Editing 347 GUI Interfaces 349 Extended Regular Expressions 357 Improved Editing Facilities 359 Programming Assistance 365 Interesting Features 368 Sources and Supported Operating Systems 374
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值