vim – Jumping around in code

Sometimes you want to jump back to an area of code, so it would be nice to have a bookmark or something similar handy. Well, vim has this feature too.

  • m<someletter> – This will “mark” this particular spot for you to return to later.
  • <someletter> - The backtick and the letter you used to mark that spot will jump to that location again.
  • . – Backtick and period will jump back to the last edited spot. Useful if you edit something, go to a different area to look at something and need to jump back quickly.

Don’t forget to use “zz” to make your life easier as you jump around.

vim – Navigating around code blocks quickly

You can use the following to quickly navigate around code blocks in vim.

  • [{ – Jump to nearest inner code block ( { curly brace ).
  • ]} – Jumps to the nearest inner code block ( } curly brace ).
  • [[ and ]] – allows you to quickly jump from function to function within the file.
  • % – Jumps to the opposite bracket or brace you are currently on.

You can keep pressing [{ to keep going out a scope. Then you can jump to the other using % if you want.

I have my space bar mapped to “zz” in my vim config file. zz allows you to center the text on the screen, which is very useful when navigating around code files like this.