As stated in the header, I would like to go to the next occurrence of the character currently under the cursor in Vim. I know about f <character>
, etc., but I specifically want "this" character. How do I do this?
You can type f<character> to put the cursor on the next character and F<character> for the previous one.
Press w (“word”) to move the cursor to the right one word at a time. Press b (“back”) to move the cursor to the left one word at a time. Press W or B to move the cursor past the adjacent punctuation to the next or previous blank space. Press e (“end”) to move the cursor to the last character of the current word.
Vim Screen NavigationM – Go to the middle line of current screen. L – Go to the last line of current screen. ctrl+f – Jump forward one full screen.
Basic searching Type ggn to jump to the first match, or GN to jump to the last.
It does not exist natively.
If you want, you can create a new mapping (bound to <leader>a
for example). Add the following to your .vimrc and restart:
nnoremap <leader>a vy/<C-R>"<CR>
" vy : copy the character under the cursor
" / : open search
" <C-R>" : paste the character
" <CR> : launch the search
Then each following search will be available via the n key as usual.
(Leader is by defaut the \ key but can be remapped with the command :set mapleader =
)
This is not part of the question, but I should add that for easy navigation, it is a good idea to have look at easymotion plugin and know that it exists.
I'm not aware of a built-in equivalent to *
for the character under the cursor but the mappings below should cover your requirements:
nnoremap <silent> <key> "zyl:normal! f^Rz^M
nnoremap <silent> <key> "zyl:normal! F^Rz^M
nnoremap <silent> <key> "zyl:normal! t^Rz^M
nnoremap <silent> <key> "zyl:normal! T^Rz^M
^R
is obtained with <C-v><C-r>
and ^M
with <C-v><CR>
.
You can do:
yl:normal! f<Ctrl-R>"<CR>
Explanation:
yl
— yank (copy) the character under cursor into the "
register:normal
— execute a Normal mode command that followsf<Ctrl-R>"<CR>
— insert the contents of the "
register and run the f{char}
command.
Of course, you'll want to create a mapping for the command to make it usable.
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