Expanding the search in Vim
I just discovered a new Vim trick I think I am going to use quite often, so I am sharing it here to look it up when I forget.
As you may know, you can issue the
/ command in Vim to start a search. Every character you type will be in the search, until you hit enter, which will jump you to the first occurance of your searched text.
Another thing you may know, is that you can use this search-motion as a motion to other commands as well. When you do
v/here, you will visually select everything between the current cursor position and the first occurance of 'here' in the buffer. I use this to delete stuff that I can't target using the
Then there is the thing I once found out, but never could remember: once you press
/, you are in a little submode I can find the name for. In this mode, you can use Ctrl+L and Ctrl+H to increase or decrease your search string by the characters of the first match. You can also use Ctrl+G to move that virtual cursor to the next match, or Ctrl+T to get to the previous. Once you hit enter you are on that last position, removing the need to do
But here it comes: when you are deleting with
d/, you can also use Ctrl+G to get to that next match. If you searched for a small snippet that accidentally occurs before the place you wanted to go, you can press Gtrl+G to jump over it, and pressing enter will delete the full distance.