Slide 1

Slide 1 text

The Power of V!M by Dima Chumak [email protected] February 10, 2013

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Links • vim.org - main site: docs, plugin search • vim.wikia.com - vim tips collection • ru.wikibooks.org/wiki/Vim • vimcasts.org - collection of video tutorials • vim-scripts.org - all vim plugins under git • rayninfo.co.uk/vimtips.html Best of Vim Tips by David Rayner a.k.a. zzapper, 15 years with Vim and still learning ;) • derekwyatt.org/vim/vim-tutorial-videos Derek Wyatt's Vim video totorial

Slide 4

Slide 4 text

Documentation :help help-context :help :h :help $ vimtutor vimdoc.sf.net/htmldoc

Slide 5

Slide 5 text

Core functionality

Slide 6

Slide 6 text

. .

Slide 7

Slide 7 text

Modes

Slide 8

Slide 8 text

i I gi a A o O R gh gH v_Ctrl-g v V Ctrl-v

Slide 9

Slide 9 text

Motion commands

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

h j k l H M L ( ) { } w W b B e E ge gE 0 $ ^ g_ g0 g$ gj gk f F t T ; , | gm / ? * # g* g# n N gg G ` ' [ ] %

Slide 12

Slide 12 text

Change operators

Slide 13

Slide 13 text

c d y ~ g~ gu gU ! = < > gq gw g?

Slide 14

Slide 14 text

Change commands

Slide 15

Slide 15 text

r R dl x D dd Y yy p P [p [P s S C cc J

Slide 16

Slide 16 text

Text objects

Slide 17

Slide 17 text

iw iW aw aW is as ip ap it at ib ab i( a( i) a) iB aB i{ a{ i} a} i< a< i> a> i" i' i` a" a' a`

Slide 18

Slide 18 text

Undo/Redo

Slide 19

Slide 19 text

u Ctrl-r U g+ g-

Slide 20

Slide 20 text

Text completion

Slide 21

Slide 21 text

i_Ctrl-x_Ctrl-l i_Ctrl-x_Ctrl-n i_Ctrl-x_Ctrl-k i_Ctrl-x_Ctrl-t i_Ctrl-x_Ctrl-i i_Ctrl-x_Ctrl-] i_Ctrl-x_Ctrl-f i_Ctrl-x_Ctrl-d i_Ctrl-x_Ctrl-v i_Ctrl-x_Ctrl-u i_Ctrl-x_Ctrl-o i_Ctrl-x_s i_Ctrl-n

Slide 22

Slide 22 text

Macros

Slide 23

Slide 23 text

q{0-9a-zA-Z"} q @{0-9a-z".=*} @@

Slide 24

Slide 24 text

Search/Replace

Slide 25

Slide 25 text

/ ? n N * g* # g# :s/XXX/YYY/flags & g& :g/XXX/command

Slide 26

Slide 26 text

Scrolling

Slide 27

Slide 27 text

Ctrl-f Ctrl-b Ctrl-d Ctrl-u Ctrl-e Ctrl-y zt zz zb zl zh zL zH

Slide 28

Slide 28 text

Buffers

Slide 29

Slide 29 text

:ls :bN :bufdo Ctrl-^

Slide 30

Slide 30 text

Windows

Slide 31

Slide 31 text

Ctrl-w_n Ctrl-w_c Ctrl-w_o Ctrl-w_s Ctrl-w_v Ctrl-w_f Ctrl-w_F Ctrl-w_{hjkl} Ctrl-w_{HJKL} Ctrl-w_{+-<>_|=} :windo

Slide 32

Slide 32 text

Tabs

Slide 33

Slide 33 text

:tabedit :tabnew gt gT Ctrl-w_gf Ctrl-w_gF :tabdo

Slide 34

Slide 34 text

Jumps

Slide 35

Slide 35 text

Ctrl-o Ctrl-i g; g, gf gF

Slide 36

Slide 36 text

Marks

Slide 37

Slide 37 text

two ways of jumping: ` '

Slide 38

Slide 38 text

named marks (user): `{a-z} `{A-Z} [` ]` special marks (auto): `{0-9} `` `" `^ `. `[ `] `< `> `( `) `{ `}

Slide 39

Slide 39 text

Folding

Slide 40

Slide 40 text

:set foldmethod=syntax zo zO zc zC za zA zr zR zm zM zv zj zk [z ]z

Slide 41

Slide 41 text

Moving through source code [ ] %

Slide 42

Slide 42 text

{ Code blocks }

Slide 43

Slide 43 text

function(int a) +-> { | if (a) | +-> { [[ | | for (;;) --+ | | +-> { | | [{ | | foo(32); | --+ | | [{ | if (bar(a)) --+ | ]} | +-- | +-- break; | ]} | | | } <-+ | | ][ +-- foobar(a) | | } <-+ | } <-+

Slide 44

Slide 44 text

Functions()

Slide 45

Slide 45 text

int func1(void) { return 1; +----------> } | [] | int func2(void) | +-> { | [[ | if (flag) start +-- +-- return flag; | ][ | return 2; | +-> } ]] | | int func3(void) +----------> { return 3; }

Slide 46

Slide 46 text

( Braces )

Slide 47

Slide 47 text

[( <-------------------------------- <------- if (a == b && (c == d || (e > f)) && x > y) --------------> --------------------------------> ])

Slide 48

Slide 48 text

/* Comments */

Slide 49

Slide 49 text

+-> +-> /* | [/ | * A comment about --+ [/ | +-- * wonderful life. | ]/ | */ <-+ | +-- foo = bar * 3; --+ | ]/ /* a short comment */ <-+

Slide 50

Slide 50 text

#ifdefs

Slide 51

Slide 51 text

+-> #ifdef USE_POPEN [# | fd = popen("ls", "r") % +-- #else ]# | fd = fopen("tmp", "w") +-> #endif

Slide 52

Slide 52 text

Code investigation

Slide 53

Slide 53 text

:set path+=your_project_includes [I [i ]I ]i [D [d ]D ]d [ ]

Slide 54

Slide 54 text

ctags/cscope

Slide 55

Slide 55 text

Ctrl-] v_Ctrl-] Ctrl-t g] v_g] g_Ctrl-] Ctrl-w_] Ctrl-w_f Ctrl-w_F Ctrl-w_gf Ctrl-w_gF

Slide 56

Slide 56 text

Quickfix

Slide 57

Slide 57 text

:copen :close :cwindow :cnext :cprev :make :grep makeprg

Slide 58

Slide 58 text

Diff mode

Slide 59

Slide 59 text

$ vimdiff :diffsplit :vertical diffsplit :diffthis :diffpatch [c ]c do dp

Slide 60

Slide 60 text

Versatile ][ motions

Slide 61

Slide 61 text

[[ ]] [] ][ [{ ]} [( ]) [c ]c [m ]m [s ]s [z ]z [' ]' [# ]# [/ ]/

Slide 62

Slide 62 text

Magic g modifier

Slide 63

Slide 63 text

g# g& g< gd gD gJ gR g] ga go gp gv gw

Slide 64

Slide 64 text

Command line

Slide 65

Slide 65 text

: q: c_Ctrl-c c_Ctrl-i c_Ctrl-d c_Ctrl-p c_Ctrl-n

Slide 66

Slide 66 text

Multi-language input

Slide 67

Slide 67 text

i_Ctrl-^ langmap

Slide 68

Slide 68 text

Minimal recommended config

Slide 69

Slide 69 text

:filetype plugin on :filetype indent on :syntax enable :set nocompatible :set ignorecase smartcase :set hlsearch incsearch nowrapscan :set foldmethod=syntax :set autoindent nocindent nosmartindent :set tabstop=4 shiftwidth=4 expandtab :set laststatus=2 :set showmode showcmd wildmenu :set listchars=eol:$,tab:>-,trail:. :set nowrap winminheight=0 novisualbell :set backup backupdir=~/.vim/backup :set undofile undodir=~/.vim/undo :set relativenumber :set confirm nohidden :set history=5000

Slide 70

Slide 70 text

Plugin extentions

Slide 71

Slide 71 text

Vim directory structure ~/.vim |-- after |-- autoload |-- colors |-- doc |-- ftplugin |-- plugin `-- syntax

Slide 72

Slide 72 text

Manual plugin management is not convenient

Slide 73

Slide 73 text

pathogen Revolution in vim plugin management Makes it super easy to install plugins in their own private directories Check out the how to and video tutorial on vimcasts.org

Slide 74

Slide 74 text

vundle Takes ideas behind pathogen and brings it to the next level Inspired by Ruby's bundler gem

Slide 75

Slide 75 text

vim-scripts.org Mirrors all vim plugins under git on Github vim-scripts.org + git submodules + pathogen OR vim-scripts.org + vundle = automatic plugin management, updates and synchronization

Slide 76

Slide 76 text

General purpose plugins

Slide 77

Slide 77 text

buffexplorer Quickly and easily switch between buffers

Slide 78

Slide 78 text

NERDTree Allows you to explore your filesystem and to open files and directories

Slide 79

Slide 79 text

Gundo Visualize your Vim undo tree

Slide 80

Slide 80 text

MRU Provides an easy access to a list of Most Recently Used files

Slide 81

Slide 81 text

FuzzyFinder Provides convenient ways to quickly reach the buffer, file, command, bookmark, tag you want, using fuzzy pattern matching

Slide 82

Slide 82 text

powerline Vim statusline on steroids:

Slide 83

Slide 83 text

grep Powerful integration with system's *grep utilities, including ability to grep through Vim buffers

Slide 84

Slide 84 text

yankstack Lightweight implementation of the Emacs 'kill ring' for Vim. It allows you to yank and delete things without worrying about losing the text that you yanked previously. It effectively turns your default register into a stack, and lets you cycle through the items in the stack after doing a paste.

Slide 85

Slide 85 text

EasyMotion Highlights all possible motion choices and allows you to press one key to jump directly to the target

Slide 86

Slide 86 text

MultipleSearch Display multiple searches at the same time with different color highlights

Slide 87

Slide 87 text

surround Easily delete, change and add surroundings in pairs (parentheses, brackets, quotes, XML tags, and more)

Slide 88

Slide 88 text

repeat Allows to repeat complex plugin's actions (for example surround) by remapping . command

Slide 89

Slide 89 text

Align Easily align text and program code in various ways, using multitude of predefined align-schemas or powerful manual control

Slide 90

Slide 90 text

DirDiff Performs a recursive diff on two directories and generates a diff window, similar to GUI diff tools like Kdiff3 or Kompare

Slide 91

Slide 91 text

SudoEdit Allows to read/write a file from inside vim with sudo privileges

Slide 92

Slide 92 text

gnupg Transparent editing of gpg encrypted files

Slide 93

Slide 93 text

file-line Allows to open files as file:line and place a cursor on chosen line

Slide 94

Slide 94 text

greplace Global Replace plugin allows you to search and replace a pattern across multiple files

Slide 95

Slide 95 text

VisIncr Facilitates making a column of increasing or decreasing numbers, dates, or day names

Slide 96

Slide 96 text

man Allows to read man pages directly from vim with :Man command This plugin is part of default vim distribution and can be enabled with runtime! ftplugin/man.vim command in .vimrc

Slide 97

Slide 97 text

info GNU info documentation browser

Slide 98

Slide 98 text

Programming related plugins

Slide 99

Slide 99 text

a Alternate between source files quickly, like .c ⇐⇒ .h etc.

Slide 100

Slide 100 text

Taglist Provides an overview of the structure of source code files and allows you to efficiently browse through source code files for many programming languages

Slide 101

Slide 101 text

Tagbar Similar to the Taglist plugin, but is superior in some ways and provides an ability to sort tags by scope

Slide 102

Slide 102 text

Tagselect A better :tselect and Ctrl-] commands Shows matched tags in a separate window, which can be searched and scrolled with ordinary vim commands

Slide 103

Slide 103 text

cscope_macros Handy mappings and commands to search tags with cscope

Slide 104

Slide 104 text

fugitive An awesome git integration into vim

Slide 105

Slide 105 text

OmniCppComplete C/C++ omni-completion with ctags database, a kind of intellisense for vim

Slide 106

Slide 106 text

clang-complete Uses Clang for completing C, C++, Objective-C and Objective-C++ You don't need any ctags for it to work It can complete complex things, which OmniCppComplete can't

Slide 107

Slide 107 text

EnhCommentify Automatically comment/uncomment lines of code in various programming languages

Slide 108

Slide 108 text

NERDCommenter Another one nice commenter, it complements EnhCommentify, adding some features which the latter doesn't have

Slide 109

Slide 109 text

snipMate Brings TextMate's snippets features in Vim for various programming languages

Slide 110

Slide 110 text

delimitMate Provides automatic closing of quotes, parenthesis, brackets, etc., besides some other related features that should make your time in insert mode a little bit easier

Slide 111

Slide 111 text

errormarker Highlights and sets error markers for lines with compile errors

Slide 112

Slide 112 text

camelcasemotion Motion through CamelCaseWords and underscore_notation

Slide 113

Slide 113 text

argtextobj Text-object like motion for function's arguments

Slide 114

Slide 114 text

BlockDiff Shows diff between two arbitrary blocks of text

Slide 115

Slide 115 text

DoxygenToolkit Simplify creation of Doxygen documentation in C/C++ projects

Slide 116

Slide 116 text

Conque-Shell Run interactive commands, such as bash, inside a Vim buffer

Slide 117

Slide 117 text

Syntastic It's a syntax checking plugin that runs files through external syntax checkers and displays any resulting errors to the user This can be done automatically or on demand

Slide 118

Slide 118 text

git_patch_tags Provides shortcuts for adding tag lines for git commits, like Reviewed-by: Tested-by: etc. with automatic user-name and email substitution

Slide 119

Slide 119 text

patchreview Simplify the process of reviewing multi-file patches, by showing each file changes in a diffsplit in separate vim tab

Slide 120

Slide 120 text

Other mics plugins

Slide 121

Slide 121 text

Marks-Browser Shows list of set marks (including special) for the current file in a separate window

Slide 122

Slide 122 text

ShowMarks Visually shows the location of marks by placing a sign in the leftmost column of the buffer

Slide 123

Slide 123 text

diffchanges Show changes, made to current buffer since the last save, in a diff mode

Slide 124

Slide 124 text

xml.vim Makes editing xml (and html) files a kid's play

Slide 125

Slide 125 text

DrawIt Ascii drawing plugin: lines, ellipses, arrows, fills, and more

Slide 126

Slide 126 text

deb Allows to browse debian package in the same way you can browse .tar and .zip files

Slide 127

Slide 127 text

Eternal question:

Slide 128

Slide 128 text

Vim vs Emacs . .

Slide 129

Slide 129 text

It doesn't matter, just choose one of them but vim is better anyway ; )

Slide 130

Slide 130 text

Give it a try ;) Check out my .vimrc config on github To try my vim configuration just do the following: $ git clone git://github.com/chumakd/vim-runtime.git $ cd vim-runtime $ git submodule update --init $ cd .. $ MYVIMRC=./vim-runtime/vimrc VIMHOME=./vim-runtime \ gvim ./vim-runtime/vimrc

Slide 131

Slide 131 text

F!N