I would like to know if/how I can make vim look for the next occurrence of a variable. Let's say the variable's name is simply 'n', then /n
would give me all occurrences of that letter, which isn't always terribly helpful. I guess I could create a regex to solve the problem, but I wondered whether there was some command/keystroke I simply don't yet know about; and as all my googling has been to no avail I decided to put a question on here.
Thanks a lot for your help!
vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return. Type n to go to the next occurrence of the string. Type N to go to the previous occurrence.
One can search forward in vim/vi by pressing / and then typing your search pattern/word. To search backward in vi/vim by pressing ? and then typing your search pattern/word. Once word found in vim, you can press the n key to go directly to the next occurrence of the word in backwards.
CTRL-F is a vital keystroke to control vim - it provides the page-down behavior and without that I have to find the actual page-down key which takes my fingers off the home row.
Use N to move to the previous occurrence. For the info command, type s to search, then enter your search term or regex. It will bring you to the first occurrence. To move to the next match, type } , to move to the previous occurrence type { .
If you have the cursor over the variable in question, you can press *
and it will search for the next occurrence or #
will search for the previous one.
This is equivalent to typing:
/\<n\>
(\<
matches on the start of a word and \>
matches on the end of word). The only difference (for reasons I'm not sure of) is that *
and #
don't pay attention to the 'smartcase'
option.
See:
:help * :help /\<
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With