我发现我可以使用t c或Tc移动到下一个/上一个字符c
我还可以使用fc或Fc移动到下一个/上一个字符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
简而言之,f和t就是所谓的vim
运动命令。他们帮助修改他们之前的运算符。当您移动操作符时,f它会对当前光标位置之间的所有字符进行操作并包括您用 示意的角色f。如果您选择t相反,您的操作员将对从当前位置到并排除您用 示意的角色t。