Skip to content

Instantly share code, notes, and snippets.

@mingrisch
Last active August 29, 2015 14:08
Show Gist options
  • Save mingrisch/61c8b858c54b0aaa221b to your computer and use it in GitHub Desktop.
Save mingrisch/61c8b858c54b0aaa221b to your computer and use it in GitHub Desktop.

Movements

    • / # Move to next / previous word under cursor
  • H / B / L # move to top/middle/bottom line of the screen. Follow this possibly by:

  • z. put the line with the cursor at the center

  • zt put the line with the cursor at the top

  • zb put the line with the cursor at the bottom of the screen

  • CTRL-O CTRL-I undo/redo last jump

Marks

  • m[a-z] define a mark in the current file
  • m[A-Z] define a global mark
  • '[a-z, A-Z] jump to the line (in the appropriate file in case of [A-Z]) containing the mark
  • mV in .vimrc : quick shortcut to upen .vimrc by 'V

Change inside/outside stuff.

  • ciw # Change inside word. Delete the current word and enter insert mode.
  • ci" # Change inside quotes. Delete what is inside quotes and enter insert mode.
  • ca" # Change outside quotes. Delete quotes and what's inside them, and enter insert mode.
  • cip # Change a paragraph.
  • vip # Select a paragraph.

How to record a macro.

  1. Press q followed by a lowercase letter (the register).
  2. Perform some editing.
  3. Stop recording by pressing q.
  4. Play the macro by pressing q and the letter you chose.
  5. To repeat it, type :N @ macroletter, in which N is the number of times.

Line wrapping and textwidth. (original)

  • gq # Rewrap the text.
  • :set tw=72 # Rewrapping will rewrap to 72 columns.
  • :set fo=cqt # Enable automatic wrapping with the t flag. Must have a nonzero value of tw set.
  • :set tw=0 fo=cqt wm=5: Automatic wrapping at a 5 col right margin. That's a good one

Working with multiple files.

  • :ls # List currently opened files.
  • :b filename # Show filename (which should be already open) in the current buffer.

References

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