vim 中的“find”和“till”有什么区别?

vim 中的“find”和“till”有什么区别?

我发现我可以使用t cTc移动到下一个/上一个字符c

我还可以使用fcFc移动到下一个/上一个字符c

它们之间的唯一区别是tc将光标放置在字符之前,Tc(向后)将光标放置在字符之前角色和fc/Fc或都将其放置在角色本身上?

答案1

它们之间唯一的区别是光标位置。从:help motion.txt

                                                  f
f{char}             To [count]'th occurrence of {char} to the right. The                                                         
                    cursor is placed on {char} inclusive.                                                                         
                    {char} can be entered as a digraph digraph-arg.                                                               
                    When 'encoding' is set to Unicode, composing                                                                  
                    characters may be used, see utf-8-char-arg.                                                                   
                    :lmap mappings apply to {char}.  The CTRL-^ command                                                           
                    in Insert mode can be used to switch this on/off                                                              
                    i_CTRL-^.                                                                                                     

                                                   F                                                                             
F{char}             To the [count]'th occurrence of {char} to the left.                                                           
                    The cursor is placed on {char} exclusive.                                                                     
                    {char} can be entered like with the f command.                                                                

                                                   t                                                                             
t{char}             Till before [count]'th occurrence of {char} to the                                                            
                    right.  The cursor is placed on the character left of                                                         
                    {char} inclusive.                                                                                             
                    {char} can be entered like with the f command.                                                                

                                                   T                                                                             
T{char}             Till after [count]'th occurrence of {char} to the                                                             
                    left.  The cursor is placed on the character right of                                                         
                    {char} exclusive.                                                                                             
                    {char} can be entered like with the f command.

答案2

是的,它们之间的主要区别是光标位置,正如您所说。

例如,当您想要删除或更改某些字符时,这会派上用场。假设您有以下行:

print "Hello, world!\n"; exit

假设您想更改分号之前的所有内容。为此,您需要转到行的开头 ( ^),然后c将所有内容挂t在分号上。

相反,如果您想删除第一个命令并只保留exit,则可以通过输入分号d来删除所有内容。f

简而言之,ft就是所谓的vim运动命令。他们帮助修改他们之前的运算符。当您移动操作符时,f它会对当前光标位置之间的所有字符进行操作并包括您用 示意的角色f。如果您选择t相反,您的操作员将对从当前位置到并排除您用 示意的角色t

相关内容