Skip to content

Instantly share code, notes, and snippets.

@rrmartins
Forked from todgru/vim_info.md
Created September 18, 2013 17:54
Show Gist options
  • Select an option

  • Save rrmartins/6612902 to your computer and use it in GitHub Desktop.

Select an option

Save rrmartins/6612902 to your computer and use it in GitHub Desktop.

#vim

My .vimrc file:

syntax on
set bs=2
set expandtab
set tabstop=2
set shiftwidth=2
set number

Editing

  • shift V select line, up or down select lines
  • shift > shift select block or line out
  • shift < shift select block or line in
  • d to delete highlighted text and copy to cliboard
  • D delete everything after cursor to end of line
  • y to copy (yank)
  • p to paste after cursor, P before
  • u undo last change
  • . repeat last command
  • $ vim +linenumber file.c open file and jump to that line number
  • gg go to first line, GG go to last
  • gt go to next tab {i}gt go to tab number {i}
  • tabm move current tab to last tab
  • U convert SELECTED text to uppercase (also gU)
  • u convert SELECTED text to lowercase (also gu)
  • ~ toggle SELECTED text to opposiste case (also g~)
  • control l to refresh vim when changes happen (like git pull)
  • Use * to go to the definition of the word under the cursor
  • In NERDTree, shift T opens select file in new tab behind current
  • In NERDTree, t opens selected file in new tab
  • :set syntax=php or :set syntax=yaml or :set syntax=perl etc.
  • :set nowrap turn off word wrap
  • :%s/$/',/ search the entire file %s, find end of line $ and replace with ',
  • s/' .*/'/ search the selection for ' if found, replace it and the rest of the line with '
  • %s/ ->\zs .*// keep the arrow, delete all after arrow
  • %s/ -> .*// delete the arrow and everything after
  • vim scp://url/path/remote_file edit remote file locally, saving to remote
  • Find this or that or blue this\|that\|blue
  • Sort selection alphabetically: sort, reverse sort!
  • Folding: in .vimrc add let php_folding = 1
  • Folding: za to toggle fold zA to toggle all
  • If command r and loose arrow-key, then ctrl z and type fg on the command line
  • d0 delete every thing before cursor in visual mode
  • ctrl u to delte every thing befor cursor in insert mode
  • e reload current file
  • :retab set all tabs in current file to current settings. Good for files that used tabs, not spaces.
  • :vertical resize 30 to resize the current window to exactly 30 characters wide.

To select a column, or even a block: In normal mode (press ESC),

  1. control v
  2. select column
  3. shift I
  4. enter your comment syntax, like #
  5. press ESC

To delete a column:

  1. control i
  2. select column
  3. d will delete (and copy to clipboard, p to paste)

After copying (yanking) a block of text, can also select another block of text and paste over it. Similar to other editors gui's.

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