Vim中如何反向使用shift-*跳转到光标上方的函数定义?
反向执行
Shift-*的Vim快捷键方案 Great question! I deal with this exact situation constantly when digging through long code files where the function definition I need is buried above a ton of other functions.
Here's the quick solution you're looking for:
- Instead of pressing
Shift-*(which maps to the*command, jumping to the next occurrence of the word under your cursor), pressShift-#(the#command). This will jump directly to the previous occurrence of the same word, perfectly targeting definitions that sit above your current cursor position.
A few extra tips to make this workflow smoother:
- Both
*and#use Vim's default word-matching rules (based on your'iskeyword'setting), so they'll behave consistently with how you're used to jumping to function definitions. - Repeat pressing
#to keep jumping upward through earlier occurrences if you overshoot or need to check multiple instances. - If you accidentally jump too far, hit
Ctrl+Oto instantly jump back to your previous cursor position—this is a lifesaver for navigating complex codebases.
内容的提问来源于stack exchange,提问作者Chris
相关产品推荐
相关产品推荐

