Wednesday, October 28, 2009

Daily VIM commands

These are commands I found to be using frequently when on command line:

Window Operations:
  • :split - horizontal split
  • :vs - vertical split
  • :vsplit - vertical split
  • Ctrl + W, Ctrl + W - will tab between windows
  • Ctrl + W, _ - will maximize current window
  • Ctrl + W, = - will resize all windows equally
  • 4 CTRL-W + - will increase height of window by 4 lines
File Explorer:
  • :e - will tab through the files available in current directory
  • :cd <..> - will change to directory, just like system command
  • :Ex - open file explorer in current window
  • :Sex - split current window and open explorer in one of windows
  • Hit a file to open that file in current window
  • Ctrl + 6 to go back to explorer from opened file
Search/Replace
  • :s/OLD/NEW - find and replace a first occurrence on current line
  • :s/OLD/NEW/g - find and replace all occurrences on current line
  • :%s/OLD/NEW/g - find and replace all occurrences in entire file
Diffing files
  • From within VI: :vertical diffsplit file
  • From command shell: vimdiff file1, file2
Buffer Operations
  • :ls - will list currently open buffers
  • :bn - will open a buffer n, where n is a number as reported by ls
  • :b - tab through open buffers, select one to open with Enter
Tabs
  • :tabe - opens a new tab (tab in edit mode)
  • gt - advance to the next
  • gT - advance to the previous
  • {count}gt - go to the {count} tab
  • :tabe - path/to/file - to open a file
  • :tabn - go to next tab
External Commands
  • :pwd - print working directory
  • :cd - as usual - move to directory
  • :cd D - will iterate through directories starting with D

Visual Selection Mode
  • v - to put in the visual selection mode
  • y - yank/copy
  • x - cut selection
  • p - paste at cursoe location


Autosuggest
Ctrl + N or Ctrl + P - this will show choices when typing partial working


Expand tabs with spaces(put these onto the .vimrc file):
:set tabstop=4
:set expandtab
:%retab

Mouse Support (in the .vimrc file)
:set mouse=a


This is mostly a cheet sheet for myself, ..but enjoy
igor

No comments: