[英]How to move cursor to specific word in current line in Vim
Let's say we're currently in this line of code:假设我们目前在这行代码中:
readonly L|a|zy<ICountryRepository> countryRepo;
and the cursor is in the position of letter "a", as shown in the code between two "|"并且光标在字母“a”的位置,如两个“|”之间的代码所示symbols.
符号。
Now I want to move my cursor to the letter y
of the word countryRepo
, how can I do that using the minimum key strokes?现在我想将光标移动到
countryRepo
单词的字母y
上,我该如何使用最少的击键来做到这一点?
(Currently I'm using the key sequence of fyfyfyfy
in normal mode ... Kind of stupid) (目前我在正常模式下使用
fyfyfyfy
的键序列......有点愚蠢)
If you know that it's the 4th y
, you can do如果你知道它的第四
y
,你可以做
4fy
If you know it's the last y
in the line, you can do如果你知道这是行中的最后一个
y
,你可以这样做
$Fy
If you don't know at which position it is, you can still do如果你不知道它在哪个位置,你仍然可以做
fy;;;
In this case, I would use在这种情况下,我会使用
W
to move to countryRepo
, followed by移动到
countryRepo
,然后是
fy
I can think of:我能想到:
4fy
But you should only do this if you are some strange robot.但是只有当你是一些奇怪的机器人时才应该这样做。
/co<cr>fy
Which is one character shorter than your solution, but more easy..哪个比您的解决方案短一个字符,但更容易..
Wfy
Go one WORD forward and then find y.向前移动一个 WORD,然后找到 y。
f>fy
Something like this I would do.我会做这样的事情。 Depends on what popups in my mind.
取决于我脑海中的弹出窗口。
You should look into the easymotion plugin, which helps with arbitrary movements.您应该查看easymotion插件,它有助于任意移动。
EDIT:编辑:
easymotion is rather worthless here, it is more useful for jumping to targets further away. easymotion 在这里相当没有价值,它对于跳转到更远的目标更有用。
If you have vim-easymotion
, https://github.com/Lokaltog/vim-easymotion如果你有
vim-easymotion
, https://github.com/Lokaltog/vim-easymotion
You can do <leader><leader>t
and then search for letter y
.您可以执行
<leader><leader>t
然后搜索字母y
。 It's not that fast for the letters on the same line though.不过,对于同一行上的字母来说,速度并没有那么快。 The real advantage is when you jump in the entire file.
真正的优势是当您跳转到整个文件时。
I would do我会做
tR;
or或
WtR
or maybe或者可能
Wfy
Use EasyMotion .使用EasyMotion 。
In your case, <Leader><Leader>e
then a corresponding keypress (in this case b
) will bring your cursor onto the second y.在您的情况下,
<Leader><Leader>e
然后相应的按键(在本例中为b
)会将您的光标带到第二个 y 上。 Personally I use <Leader>
as the easymotion trigger so it is only 3 keystrokes for me.我个人使用
<Leader>
作为 easymotion 触发器,所以它对我来说只有 3 个按键。 The main advantage is you do not need to guess or calculate.主要优点是您不需要猜测或计算。
use / for search, then type your word and press Enter使用/进行搜索,然后输入您的单词并按 Enter
however, if you want to jump to next word, just press n但是,如果您想跳到下一个单词,只需按n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.