Posts about vim

2014-05-15 Vim commands for moving around

Basics commands in Vim

Sometimes, it's good to go back to the basics.

In command mode, typing :help usr_02.txt (or simplier something like :h usr_<TAB>02<TAB><ENTER>), you learn the letters for navigating a file:

  • these letters are HJKL - glad it works on an international keyboard.
  • letters on the borders (HL) are for horizontal movements- obviously H for left, L for right
  • letters on the inside are for vertical movements - J for down, K for up; a nice feature is that these keys are now quite widely used in the community, take for example in the gmail interface when switching to the next message.

I was still using the arrows keys, but taking this habit makes thinks easier, especially when switching often keyboards.

Simalarly, to scroll the text - you can use:

  • <CTRL-U> to scroll a half-page up
  • <CTRL-D> to scroll a half-page down

Here, the :h ctrl-u page will give you more info (or :help usr_03.txt).

Note that to follow a link (think "searching a tag"), you can press * (or # to go backwards).

2014-01-15 Vim folding commands

Using folds in Vim

Folds are useful when having long files to have a good perspective on its structure. Especially useful in LaTeX mode.

To install, I recommend using the python-mode described in

The magical shortcut all begin with z. Type :hep fold to learn more about them.

These are the most common shortcuts in my personal order of preference.

  • zo opens a fold at the cursor.
  • zc closes a fold at the cursor.
  • zM closes all open folds.
  • zO opens all folds at the cursor.
  • [z move to start of open fold.
  • ]z move to end of open fold.
  • zj moves the cursor to the next fold.
  • zk moves the cursor to the previous fold.
  • zf#j creates a fold from the cursor down # lines.
  • zf/string creates a fold from the cursor to string .
  • zm increases the foldlevel by one.
  • zr decreases the foldlevel by one.
  • zR decreases the foldlevel to zero -- all folds will be open.
  • zd deletes the fold at the cursor.
  • zE deletes all folds.