Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Last active June 11, 2018 19:53
Show Gist options
  • Save rcanepa/814bc1f1dc7df4bbecbd1da8b53e0fb8 to your computer and use it in GitHub Desktop.
Save rcanepa/814bc1f1dc7df4bbecbd1da8b53e0fb8 to your computer and use it in GitHub Desktop.
Vim tips

Buffers

List open buffers:

:ls

Open buffer by file name:

:b <buffer-name>

Split (vertically) and open buffer:

:sb <buffer-name>

Split (vertically) and open buffer:

:vsp | b <buffer-name>

Comments

Method 1

To comment a block of lines

  1. Enter the visual block mode CTRL + V
  2. Selected the lines to comment/uncomment
  3. Press SHIFT + I (capital i)
  4. Press ALT + # (insert a hash #)
  5. Press ESC and wait

To uncomment a block of lines

  1. Enter the visual block mode CTRL + V
  2. Selected the lines to comment/uncomment
  3. Press x

Method 2

To comment a block of lines

  1. Enter the visual mode with v
  2. Select the lines to comment
  3. Press SHIFT + :
  4. Enter norm i# (:'<,'>norm i#) ^ this will insert a # at the first position of every line

To uncomment a block of lines

  1. Enter the visual mode with v
  2. Select the lines to comment
  3. Press SHIFT + :
  4. Enter norm x (:'<,'>norm x) ^ this will delete the first char of every line

References

http://www.moolenaar.net/habits.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment