第四章 Making small changes

usr_04 Making small changes

04.1 Operators and motions
To err is human. To really foul up you need a computer. ~
         ------------------>
             d4w 
To err is human. you need a computer. ~
        -------->
           d2e 
To err is human. a computer. ~
           ------------>
            d$  

There is a pattern here: operator-motion.

04.2 Changing text
To err is human 
   ------->
     c2wbe<Esc>

c   the change operator
2w  move two words (they are deleted and Insert mode started)
be  insert this text
<Esc>   back to Normal mode

MORE CHANGES
“cc” changes a whole line.

SHORTCUTS
x stands for dl (delete character under the cursor)
X stands for dh (delete character left of the cursor)
D stands for d$ (delete to end of the line)
C stands for c$ (change to end of the line)
s stands for cl (change one character)
S stands for cc (change a whole line)

WHERE TO PUT THE COUNT
“3d2w” deletes two words, repeated three times, for a total of six words.
REPLACING WITH ONE CHARACTER
there is somerhing grong here
rT rt rw

There is something wrong here
                   5rx

There is something xxxxx here

To replace a character with a line break use “r”.

04.3 Repeating a change
                  To <B>generate</B> a table of <B>contents ~
    f<   find first <     --->
    df>  delete to >     -->
    f<   find next <       --------->
    .    repeat df>             --->
    f<   find next <               ------------->
    .    repeat df>                     -->
    /four<Enter>    find the first string "four"
    cwfive<Esc> change the word to "five"
    n       find the next "four"
    .       repeat the change to "five"
    n       find the next "four"
    .       repeat the change
04.4 Visual mode
        This is an examination sample of visual mode ~
                       ---------->
                        velllld

SELECTING LINES

              +------------------------+
              | text more text     |
               >> | more text more text    | |
selected lines >> | text text text     | | Vjj
               >> | text more          | V
              | more text more     |
              +------------------------+

SELECTING BLOCKS
If you want to work on a rectangular block of characters, use CTRL-V to start
Visual mode. This is very useful when working on tables.
GOING TO THE OTHER SIDE
When using blockwise selection, you have four corners. “o” only takes you to
one of the other corners, diagonally. Use “O” to move to the other corner in
the same line.

04.5 Moving text
a line          a line        a line
line 2    dd    line 3    p   line 3
line 3                        line 2

MORE ON PUTTING
The “P” command puts text like “p”, but before the cursor.
Thus “dd” and then “3p” puts three copies of the same deleted line.
SWAPPING TWO CHARACTERS
teh th the
x p

04.6 Copying text
    let sqr = LongVariable *
         -------------->
               y2w
04.7 Using the clipboard

If you are not using the GUI, or if you don’t like using a menu, you have to
use another way. You use the normal “y” (yank) and “p” (put) commands, but
prepend "* (double-quote star) before it. To copy a line to the clipboard:

    "*yy

To put text from the clipboard back into the text:

    "*p
04.8 Text objects
this is some example text.
           daw

“aw” is a text object. stands for “A word”.
Using text objects is the third way to make changes in Vim. We already had
operator-motion and Visual mode. Now we add operator-text object.
To change a whole sentence use “cis”.
“cis” consists of the “c” (change) operator and the “is” text object. This
stands for “Inner Sentence”. There is also the “as” (a sentence) object.

04.9 Replace mode

The “R” command causes Vim to enter replace mode.
This is text.
Rinteresting.
You can switch between insert mode and replace mode with the key.

04.10 conclusion
    ~   change case of the character under the cursor, and move the
        cursor to the next character.  This is not an operator (unless
        'tildeop' is set), thus you can't use it with a motion
        command.  It does work in Visual mode and changes case for
        all the selected text then.

    I   Start Insert mode after moving the cursor to the first
        non-blank in the line.

    A   Start Insert mode after moving the cursor to the end of the
        line.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值