Learning Vim | 学习 Vim 编辑器

six editor?

six editor?

Chapter 1, The vi Text Editor

  1. A Brief Historical Perspective
  2. Opening and Closing Files
  3. The only way to learn vi is to practice.

Chapter 2, Simple Editing

  1. Moving the cursor
  2. Simple Edits
  3. General Form of vi Commands
  4. Misc
  5. Notes
  6. Overall
    Text object
       Change
       Delete
        Copy
      One word
         cw
         dw
         yw
     Two words
     2cW or c2W
     2dW or d2W
     2yW or y2W
  Three words back
     3cb or c3b
     3db or d3b
     3yb or y3b
      One line
         cc
         dd
      yy or Y
   To end of line
      c$ or C
      d$ or D
         y$
To beginning of line
         c0
         d0
         y0
  Single character
         r
       x or X
      yl or yh
  Five characters
         5s
         5x
        5yl
  1. Example

Chapter 3, Moving Around in a Hurry

  1. Movement by Screens
  2. Redrawing the Screen: C-l(not work in my evil-mode, we have recenter-top-center)
  3. Movement Within a Screen
  4. Movement by Line
  5. Movement by Text Blocks
  6. Movement by Searches
  7. Current Line Searches
  8. Movement by Line Number

Chapter 4, Beyond the Basics

  1. More Command Combinations

Change

Delete

Copy

From cursor to…

cH

dH

yH

Top of screen

cL

dL

yL

Bottom of screen

c+

d+

y+

Next line

c5|

d5|

y5|

Column 5 of current line

2c)

2d)

2y)

Second sentence following

c{

d{

y{

Previous paragraph

c/pattern

d/pattern

y/pattern

Pattern

cn

dn

yn

Next pattern

cG

dG

yG

End of file

c13G

d13G

y13G

Line number 13

  1. Options When Starting vi
  2. Yank to Named Buffer
  3. Marking Your Place

Chapter 5, Introducing the ex Editor

  __              _       _                                 _ _
 / _| ___  _ __  | | __ _| |_ ___ _ __   _ __ ___  __ _  __| (_)_ __   __ _
| |_ / _ \| '__| | |/ _` | __/ _ \ '__| | '__/ _ \/ _` |/ _` | | '_ \ / _` |
|  _| (_) | |    | | (_| | ||  __/ |    | | |  __/ (_| | (_| | | | | | (_| |
|_|  \___/|_|    |_|\__,_|\__\___|_|    |_|  \___|\__,_|\__,_|_|_| |_|\__, |
                                                                      |___/

Chapter 6, Global Replacement

  1. Substitude
  2. c, confirm
  3. Content-Sensitive Replacement
  4. Pattern-Matching Rules
  5. POSIX Bracket Expressions
  6. New Pattern of s/old/NEW/g
  7. More Substitution Tricks
  8. Exercise
  9. Examples

    <p>something</p>                                                             <p>somethingelse</p>
    <a>something</a>   ===> `:%300,400g/<p>/s/something/somethingelse/g` ===>    <a>something</a>
    <a>something</a>                                                             <a>something</a>
    <p>something</p>                                                             <p>somethingelse</p>
    one                                                  (one)
    two                                                  (two)
    three       ===> `:348,352s/.*/(&)/` ===>            (three)
    four                                                 (four)
    five                                                 (five)
    That or this   ===>  `:%s/\(That\) or \(this\)/\2 or \1/` ===>  this or That
  __              _       _                                 _ _
 / _| ___  _ __  | | __ _| |_ ___ _ __   _ __ ___  __ _  __| (_)_ __   __ _
| |_ / _ \| '__| | |/ _` | __/ _ \ '__| | '__/ _ \/ _` |/ _` | | '_ \ / _` |
|  _| (_) | |    | | (_| | ||  __/ |    | | |  __/ (_| | (_| | | | | | (_| |
|_|  \___/|_|    |_|\__,_|\__\___|_|    |_|  \___|\__,_|\__,_|_|_| |_|\__, |
                                                                      |___/

Chapter 7, Advanced Editing

  1. Customizing vi
  2. Executing Unix Commands
  3. Filtering Text Through a Command
  4. Saving Commands

Chapter 8, Introduction to the vi Clones

Tricks not from This Book

这些是我从 StackOverflow 上看到的。

  1. diw, di", di{}
  2. :!xxd, hex editor :!xxd -r
  3. de, then . as you want
  4. ddp, swap current and next line
  5. bye, yiw
  6. '., last edited line
  7. `., last edited char
  8. :changes, list changes
  9. :g/rgba/y A 10.gv, reselects last visual selection
  10. g~~, gUU, guu
  11. >>, <<, indent
  12. #, *, search word under cursor

Refs

  1. Learning the vi Editor (豆瓣)

Read more

  1. Vi Lovers Home Page