vim tips

tung's picture

Found some VIM tips online. I won't paraphrase the whole thing here; just the bits that were new to me. Read on, and embrace vimmery in all its glory!

Effective Use of VIM - Part 1

ZZ is now my new method of exiting VIM. It used to be :x, but I found that sometimes I'd press the x too fast, and I'd end up with a weird encryption prompt.

Also, window commands I didn't know about, but always intended to learn:

  • C-w s - split horizontal (new window below)
  • C-w v - split vertical (new window to the right)
  • C-w n - open a new blank window
  • C-w c - close active window
  • C-w o - close all windows but the active one

Effective Use of VIM - Part 2

Auto-complete is done with C-n and C-p. Choose from the choices with the arrow keys, select using RET.

As a bonus, my current .vimrc is included. Hooray!

" Syntax highlighting
:syntax enable
 
" Mouse support
:set mouse=a
 
" Use visual vertical line movement
:map <Up> gk
:imap <Up> <C-o>gk
:map <Down> gj
:imap <Down> <C-o>gj
 
" Enable left/right cursor keys to wrap to next/previous lines
:set whichwrap+=<>[]
 
" Make Home and End keys work by display lines
:map <Home> g<Home>
:imap <Home> <C-o>g<Home>
:map <End> g<End>
:imap <End> <C-o>g<End>
 
" Bash-style pathname tab-key completion
:set wildmode=longest,list
 
" Line numbers
:set number
 
" Word wrapping, but don't break words
:set wrap
:set linebreak
 
" Show incomplete lines even if they don't fit on-screen
set display+=lastline
 
" Indent tabs by 4 characters
:set tabstop=4
:set shiftwidth=4
:set et
 
" Autoindent on, smart indent OFF
:set autoindent
:set nosmartindent

Oddly enough, I'm using Emacs most of the time. I'm a dual wielder.