• non-greedy reg-exp search: simply replace with {-}. {-} is the non-greedy version of .
  • match all characters including newline: use _. instead of .
  • substitution in multiple files:

    1. :args * will add all files in current folder in to args list.
    2. :argdo %s/old/new/eg | w will perform substitution in all files in arg list

    Remark: the flag “e” in substitution command suppress error messages when pattern not found, and argdo will continue working on other files instead of stop there.

    Warning: I haven’t figure out how to undo this batch operation easily. Make sure you backup every file before doing this.

  • Search in multiple files: :grep <patterns> <files>, also works in windows(implemented using findstr)

  • : opt will show all setting options and documentations.
  • :set encoding=.. will convert current file encoding into new one. If you don’t want to modify the file, while still wish to view the file in another encoding, then use :e ++enc=...
  • Editing file on a remote server can be frustrating because of slow internet connection. Vim is able to download file from remote server, and edit it locally. When you save the file after editing, it will be uploaded to server automatically. This is done by :e scp://user@host/path/to/the/file
  • C-X C-F will auto complete file name in current directory. This is useful when editing makefile.
  • backupdir is the directory where backup files(~) saved. directory is the directory where swap file(.swp) saved. Set these two variables if you don’t want to see your working folder filled with ~ and .swp files.
  • C-t and C-d will indent/unindent whole line in insertion mode
  • :set ? will show the value of in configuration. e.g. set ff?