create new tag
, view all tags

Mastering VIM

(Auszüge aus Damian Conways VIM-Kurs)

Tip 1: Get VIM

Tip 2: Seek help

  • Type: :help
  • Or for a specific topic: :help <topic><CR>
  • Or for a list of topics containing a given string: :help <string><TAB>
  • Or any topic matching a given (vim-ish) pattern: :helpgrep <pattern>

Tip 5: Quit smarter

  • Standard way :w<CR> :q<CR>
  • faster: :wq<CR>
  • even faster: :x<CR>
  • directly from normal mode: ZZ

Tip 6: Learn to move

  • Cursor motions in Normal mode: h k l j
  • Word motions: w b e ge
  • Line and paragraphs motions: 0 ^ $ <CR> - { }
  • Top / end of the buffer: gg G
  • Move to a specific line n: nG or ngg
  • Move to the point p percent through the buffer: p%
  • :set showcmd
  • Matching brackets: %
  • :set matchpairs+=<:>,«:»
  • repeated motions: n<motion>
  • Scrolling: <CTRL-F> <CTRL-D> <CTRL-U> <CTRL-B>

Tip 7/8: Keep track of where you are / were

  • <CTRL-g> File Info / where am I?
  • g<CTRL-g> more precise info about where I am
  • :set ruler :help rulerformat :help statusline
  • Set mark: m<char>
  • jump to a mark: '<same char>
  • char is lowercase: mark per buffer
  • char is uppercase: global mark

Tip 10: change text efficiently

  • i start inserting before current cursor position
  • I start inserting before the start of the current line
  • a start inserting after current cursor position
  • A start inserting after the end of the current line
  • o start inserting on a new line below the current line
  • O start inserting on a new line above the current line
  • R replace-mode
  • C replace current line

Tip 14-18: Search and destroy

  • search: /<pattern>/
  • global search and replace: :%s/<matching pattern>/<replacing string>/gc
  • useful settings: :set wrapscan, :set incsearch, :set smartcase
  • delete until end of line: d$ or D
  • delete line including <CR>: dd
  • delete until before next semicolon: dt;
  • delete paragraph the cursor is inside: dip or dap
  • p Paragraph, w Word, s Sentence

Tip 19: Copy & paste shamelessly

  • copy a line: yy or Y
  • copy a word: yw, a paragraph: y}
  • copy anything: y<motion or search command>
  • copy the paragraph the cursor is inside: yip or yap
  • copy the word the cursor is inside: yiw or yaw
  • paste text after cursor: p
  • paste text before cursor: P
  • paste and indent: ]p or ]P

mein .vimrc File

set nocompatible
set mouse=a
set ruler
set showcmd
set matchpairs+=<:>,«:»           "Allow % to bounce between angles too
set wrapscan
set ignorecase
set smartcase
set incsearch
set hlsearch
set wildmode=list:longest,full
set define=^\\s*sub
set autowrite
set softtabstop=4
set smartindent
set showmatch
inoremap # X<C-H>#
set cinwords=if,elsif,else,unless,while,until,for,foreach
set keywordprg=perldoc

function! TabOrCompletion()
    let col = col('.') - 1
    if !col || getline('.')[col -1] !~ '\k'
        return "\<TAB>"
        return "\<C-N>"
inoremap <silent> <TAB>   <C-R>=TabOrCompletion()<CR>

syntax enable

nnoremap v <C-V>
nnoremap <C-V> v
nnoremap <C-J> :bn <CR>
nnoremap <C-K> :bp <CR>
nnoremap <C-H> 0
nnoremap <C-L> $
nnoremap <C-H> 0
nnoremap <C-L> $
nnoremap <C-H> 0
nnoremap <C-L> $

set autoindent                   "Preserve current indent on new lines
set textwidth=78                 "Wrap at this column
set backspace=indent,eol,start    "Make backspaces delete sensibly
set tabstop=4                     "Indentation levels every four columns
set expandtab                     "Convert all tabs typed to spaces
set shiftwidth=4                  "Indent/outdent by four columns
set shiftround                    "Indent/outdent to nearest tabstop

"Inserting these abbreviations inserts the corresponding Perl statement...
iab phbp  #! /usr/bin/perl -w
iab pudd  use Data::Dumper 'Dumper'; warn Dumper ;<Left>
iab pbmk  use Benchmark qw( cmpthese );^Mcmpthese -10, {};^[O
iab pusc  use Smart::Comments;^M^M###
iab putm  use Test::More qw( no_plan );

iab papp  ^[:r ~/.code_templates/perl_application.pl^M
iab pmod  ^[:r ~/.code_templates/perl_module.pm^M

-- SwenVermeul - 15 Apr 2009

Topic revision: r2 - 2009-04-15 - SwenVermeul
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback