Vi: Difference between revisions

From miki
Jump to navigation Jump to search
Line 63: Line 63:
** <tt>Ctrl-v</tt> to start ''VISUAL BLOCK'' mode.
** <tt>Ctrl-v</tt> to start ''VISUAL BLOCK'' mode.
** <tt>Shift-I</tt> to insert some text at the start of each line of selected block.
** <tt>Shift-I</tt> to insert some text at the start of each line of selected block.
* Set option '''[http://www.vim.org/htmldoc/options.html#'whichwrap' whichwrap]''' or '''ww''' that allows specified keys that move the cursor left/right to move to the previous/next line when the cursor is on the first/last character in the line.

Revision as of 14:16, 18 November 2008

Links

  • General
  • Fun
    • Vi would not be vi without a bit of fun...
  • Guides & Cheat sheets
    • Very good post explaining why vi is superior and defeating common misconception (with examples) [1].
    • Very good graphical cheatsheet

Keyboard Shortcuts

! If keys HJKLM have been remapped to MHJKL, shortcut below must be changed accordingly !

Shortcut Description Custom
Ctrl+[ Same effect as Esc, but a bit faster/easier to type. Also works on AZERTY keyboard (but apparently not for AndLinux, snif!)
* Search next occurence of word under cursor (Here more like this...)
# Search previous occurence of word under cursor
gd Search first occurence of current search

Some Stuff to Add in ~/vimrc file

(remarks: command in ~/vimrc file must not be prefixed with a colon :)

  • To enable syntax highlighting + numbering:
syntax enable
set bg=light          " Use set bg=dark if console background color is dark
set number
  • To remap movement key bindings to JKLM (instead of HJKL, so that they are right under right hand fingers on AZERTY keyboards). Commands on key 'M' are now on key 'H'.
nnoremap j h
nnoremap k j
nnoremap l k
nnoremap m l
nnoremap h m
vnoremap j h
vnoremap k j
vnoremap l k
vnoremap m l
vnoremap h m

Miscellaneous Tips and Tricks

  • Inserting only a single character (http://vim.wikia.com/wiki/Insert_a_single_character).
  • Macro
    • qq to start recording a macro q. End macro with q again.
    • @q to replay macro, followed by . to replay it again.
  • Visual Block
    • Ctrl-v to start VISUAL BLOCK mode.
    • Shift-I to insert some text at the start of each line of selected block.
  • Set option whichwrap or ww that allows specified keys that move the cursor left/right to move to the previous/next line when the cursor is on the first/last character in the line.