Vim - gwenn/hypomnemata GitHub Wiki

Tips

Search

  • * Search forward for the keyword under the cursor

  • # Same as "*", but search backward

  • /{pattern}[/]<CR> Search forward

  • ?{pattern}[?]<CR> Search backward

Multiline match

:%s/\_. -> /, /gc
/<\(\w\+\)>\_s*<\/\1> 

Move

[{ Move to the start of the current block

Open

Open file under cursor

  • gf Edit the file whose name is under or after the cursor
  • C-w f Edit the file whose name is under or after the cursor in a new window
  • C-w gf Edit the file whose name is under or after the cursor in a new tab

File completion

  • <C-X><C-F> filenames completion

Tab vs Space

  • tabstop (ts) (8)
  • expandtab (et) (noexpandtab)
  • shiftwidth (sw) (8)
  • softtabstop (sts) (0) (useful only when shiftwidth <> tabstop)
"no tab
set et sw=2 sts=2 (set expandtab shiftwidth=2 softtabstop=2)
set et sw=2 sts=2 ts=7

"tab
set noet sw=2 sts=0 ts=2
set noet sw=7 sts=0 ts=7

Swith between Tab or Space

map \M <Esc>:set noet sw=8 sts=0 ts=8<CR>
map \m <Esc>:set et sw=2 sts=2<CR>

Modeline

<!-- vim: set encoding=utf-8: -->
# vim: set expandtab softtabstop=2 shiftwidth=2:

Global command

:[range]g[lobal]/{pattern}/[cmd]<CR> where {pattern} matches
:[range]g[lobal]!/{pattern}/[cmd]<CR> where {pattern} does NOT match

Alter

  • C-X Decrement a number
  • C-A Increment a number

Switching case of characters

  • gum Lowercase text operated on by motion m
  • gUm Uppercase text operated on by motion m
  • g~m Switch case

Append line numbers

%s/^/\=strpart(eval(line('.')-1)." ",0,&ts)

Format current XML buffer

:%!xmllint --format -

Reformat code

gg=G or G=gg

Customize vimdiff

:set diffopt=filler,iwhite

Transform diff/patch

:%g/^\d\+/d^M:%g/^---/d^M:%s/^> /+;/^M:%s/^< /-;/^M:w

Customize Perl

:compiler perl
:set makeprg=/path/to/perl\ -c\ -W\ %
autocmd BufRead *.pl,*.pm compiler perl | set makeprg=/path/to/perl\ -c\ -W\ %

Tags

ctags -R -V --exclude='.svn'
:set tags+=$MY_REP/tags,$OTHER_REP/tags

Windows keys

C-Q = C-V doc

⚠️ **GitHub.com Fallback** ⚠️