Special usage of vi's tfmej

from http://blog.csdn.net/qqzhuyuehe/article/details/5754297
delete a line break: J
      In Vim you can concatenate two lines, which means that newlines between two lines are removed.

Here are two examples of behavior:

        A young intelligent 

        turtle

Move the cursor to the first line and press "J":

        A young intelligent turtle

get help: h

       :help t or  :h :g or :h :v

w: move to the beginning of the next word

b: move to the beginning of the previous word

e: move to the end of the next word

ge: move to the end of the previous word

x delete the character under the cursor (short for " dl ") 
X delete the character before the cursor (short for " dh ") 
D        delete from the current position to the end of the line (short for " d$ ")

^: move to the beginning of the line ($: end of line)

Move to a specified character: f/F/t/T

The single-character find command is one of the most useful movement commands. The "fx" command looks forward to the character x on this line . Tip: 
"f" means "Find". 
    For example, suppose you are at the beginning of the line in the example below, and you want to move to the h of the word "human". Just execute the 
command "fh":

   To err is human.  To really foul up you need a computer. 
        ---------->     ---------------> 
            fh           fy

This example also demonstrates using the "fy" command to move to the end of the word "really". 
    You can prefix this command with a number, so you can move to the "l" of "foul" with the "3fl" command 
:

        To err is human.  To really foul up you need a computer. 
                  ---------------------> 
                           3fl

The "F" command is used to look left:

        To err is human.  To really foul up you need a computer. 
                  <--------------------- 
                            Fh

"tx" 命令与 "fx" 相似,但它只把光标移动到目标字符的前一个字符上。提示:"t" 表示 "To"。这个命令的反向版本是 "Tx"。

        To err is human.  To really foul up you need a computer. 
                   <------------  -------------> 
                  Th:停在human的“u",   tp停在up的"u"

这四个命令可以通过 ";" 命令重复,"," 命令则用于反向重复。无论用哪个命令,光标永远都不会移出当前行,哪怕是这两行是连续的 一个句子。

有时你启动了一个查找命令后才发现自己执行了一个错误的命令。例如,你启动了一个"f" 命令后才发现你本来想用的是 "F"。要放弃这个查找,输入 。所以"f" 取消一个向前查找命令而不做任何操作。 

Note: 可以中止大部分命令, 而不仅仅是查找。

t(to)的另一个用法是复制行到其他地方:

:t . 复制当前行并粘贴到当前行的下一行

:t 7 复制当前行并粘贴到第7行的下一行

:,+t0 复制当前行和当前行的下一行,并粘贴到文件的起始位置(,+是 . , . +1的缩写)

:1,t$ 复制从文件第一行到当前行的内容并粘贴到文件末尾(1, 是 1, .的缩写)

和t相关的命令是m(move)

4m10: 把第4行的内容剪切并粘贴在第10行的下一行

%:括号匹配 和 带数字前缀的移动定位

当光标不在一个有用的字符上,"%" 会先向前找到一个。比如当光标停留在上例中的行首时,"%" 会向前查找到第一个 "("。然后会移动到它的匹配处

                if (a == (b * c) / d) 
                ---+----------------> 
                           %

使用带数字前缀的 "%" 命令。例如,"50%" 移动到文件的中间, 而 "90%" 移到差不多结尾的位置。

*,#:在文件中查找一个单词

使用/来查找需要输入单词,vim提供了更简单的方法:把光标移到那个单词下面使用 "*" 命令。Vim 会取得光标上的单词并把它作为被查找的字符串 "#" 命令在反向完成相同的功能。你可以在命令前加一个次数:"3*" 查找光标下单词在此之后第三次出现的地方。

<,>:查找整个单词

如果你输入 "/the",你也可能找到 "there"。要找到以 "the" 结尾的单词,可以用:

        /the>

"/>" 是一个特殊的记号,表示只匹配单词末尾。类似地,"/<" 只匹配单词的开头。 

^:字符匹配行首 $:字符匹配行尾
这样,要匹配一个完整的单词 "the",只需: /

这不会匹配 "there" 或者 "soothe"。注意 "*" 和 "#" 命令也使用了 "词首" 和 "词尾" 标记来匹配整个单词(要部分匹配,使用 "g*" 和 "g#")

匹 配 任 何 单 个 字 符:“."

点 "." 字符匹配任何字符。例如,模式 "c.m" 匹配一个第一个字符是c,第二个字符是任意字符,而第三个字符是m的字符串。例 如:We use a computer that became the cummin winter. 

命令组合模式:操作符-动作。 你首先输入一个操作符命令,例如,"d"  就是一个删除操作符。然后你输入一个动作命令,例如 "4l" 或者 "w"。 "4w" 命令能够向后移动四个单词。
"d4w" 命令删除4个单词,inclusive,包括光标移动到的位置的前一个位置
而"d4e"命令删除4个单词,e(xclusive),不包括光标移动到的位置的前一个位置
"y2w" 拷贝两个单词,"yw" 命令包括单词后面的空白字符。如果你不想要这个字符,改用 "ye" 命令。
 
另一个操作符命令是 "c",表示修改,change。它的作用方式与 "d" 操作符相似,只 是完成后会切换到插入模式。例 如,"cw" 修改一个词,更精确的说, 它删除一个词, 并切换到插入模式

        To err is human 
           -------> 
             c2wbe

        To be human

这里 "c2wbe" 包括如下操作:

        c       修改操作符 
        2w      移动两个单词的距离(与操作符合起来,它删除两个单词并进入插入模式) 
        be      插入 be 这个单词 
           切换回普通模式

如果你留意,你会发现一个奇怪的地方:human 前面的空格没有被删除。有一句谚语说道: 任何问题都有一个简单,清楚而错误的回 答。"cw" 命令就属于这种情况。c 操作符在很多地方都和 d 一样,但有一个例外,"cw"。它实际上象 "ce" 一样,删除到单词尾。这样单词后面的空格就不包括在内了。

像 "dd" 可以删除一行一样,"cc" 修改一整行,"yy" 命令拷贝一整行"d$" 删除到行尾;"c$" 则修改到行尾,"y$" 拷贝到行尾。

xp:交 换 两 个 字 符

经常发生这样的情况,当你输入字符的时候,你的手指比你的脑子转得快(或者相反?)。这样的结果是你经常把 "the" 敲成 "teh"。Vim 让你可以很容易得修正这种错误。只要把光标移到 "teh" 的 "e" 上,然后执行 "xp" 即可。这个工作过程是:"x" 删除一个字符,保存到寄存器。"p" 把这个被保存的字符插入到光标的后面,也就是 "h" 的后面了。

        teh     th     the 
         x       p

文本对象:aw,as,is 作为一个整体来处理,光标在对象中的位置无关紧要

命令组合模式:操作符-文本对象。

如果你在一个单词的中间而又想删掉这个单词,在你用 "dw" 前,你必须先移到这个单词的开始处。这里还有一个更简单的方 法:"daw"

        this is some example text. 
                       daw

        this is some text.

"daw" 的 "d" 是删除操作符。"aw" 是一个文本对象。提示:"aw" 表示 "A Word" (一个单词),这 样,"daw" 就是 "Delete A Word"(删除一个单词)。确切地说,该单词后的空格字符也被删除掉了。

用 "cis" 可以改变一个句子。看下面的句子:

        Hello there.  This 
        is an example.  Just 
        some text.

移动到第二行的开始处。现在使用 "cis":

        Hello there.    Just 
        some text.

现在你输入新的句子 "Another line.":

        Hello there.  Another line.  Just 
        some text.

"cis" 包括 "c"(change,修改)操作符和 "is" 文本对象。这表示 "Inner Sentence"(译者注:实在 很难用中文表示这个意思了,各位还是记英文名吧)。还有一个文本对象是 "as",区别是 "as" 包括句子后面的空白字符而 "is" 不包括。如果你要删除一个句子,而且你还想同时删除句子后面空白字符,就用 "das";如果你想保留空白字符而替换一个句子,则使 用"cis"。

 

set list: 显 示 TAB 键

文件中有 TAB 键的时候,你是看不见的。要把它显示出来:        :set list

现在 TAB 键显示为 ^I,而 $显示在每行的结尾,以便你能找到可能会被你忽略的空白字符在哪里。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326603593&siteId=291194637