Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Power of Vim

0267a9537b3d4a87082052f98fc7d487?s=47 Dima Chumak
February 10, 2013

The Power of Vim

The idea behind this slides is to provide overview and reference of most useful vim commands, many of which are not known to or forgotten by an average vim user. It also describes a "must have" and "best of" vim plugins (general-purpose and targeted for C/C++ programming) of my choice.

0267a9537b3d4a87082052f98fc7d487?s=128

Dima Chumak

February 10, 2013
Tweet

Transcript

  1. The Power of V!M by Dima Chumak chumakd@gmail.com February 10,

    2013
  2. None
  3. 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
  4. Documentation :help help-context :help :h :help $ vimtutor vimdoc.sf.net/htmldoc

  5. Core functionality

  6. . .

  7. Modes

  8. i I gi a A o O R gh gH

    v_Ctrl-g v V Ctrl-v
  9. Motion commands

  10. None
  11. 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 ` ' [ ] %
  12. Change operators

  13. c d y ~ g~ gu gU ! = <

    > gq gw g?
  14. Change commands

  15. r R dl x D dd Y yy p P

    [p [P s S C cc J
  16. Text objects

  17. 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`
  18. Undo/Redo

  19. u Ctrl-r U g+ g-

  20. Text completion

  21. 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
  22. Macros

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

  24. Search/Replace

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

    g& :g/XXX/command
  26. Scrolling

  27. Ctrl-f Ctrl-b Ctrl-d Ctrl-u Ctrl-e Ctrl-y zt zz zb zl

    zh zL zH
  28. Buffers

  29. :ls :bN :bufdo Ctrl-^

  30. Windows

  31. 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
  32. Tabs

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

  34. Jumps

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

  36. Marks

  37. two ways of jumping: ` '

  38. named marks (user): `{a-z} `{A-Z} [` ]` special marks (auto):

    `{0-9} `` `" `^ `. `[ `] `< `> `( `) `{ `}
  39. Folding

  40. :set foldmethod=syntax zo zO zc zC za zA zr zR

    zm zM zv zj zk [z ]z
  41. Moving through source code [ ] %

  42. { Code blocks }

  43. function(int a) +-> { | if (a) | +-> {

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

  45. int func1(void) { return 1; +----------> } | [] |

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

  47. [( <-------------------------------- <------- if (a == b && (c ==

    d || (e > f)) && x > y) --------------> --------------------------------> ])
  48. /* Comments */

  49. +-> +-> /* | [/ | * A comment about

    --+ [/ | +-- * wonderful life. | ]/ | */ <-+ | +-- foo = bar * 3; --+ | ]/ /* a short comment */ <-+
  50. #ifdefs

  51. +-> #ifdef USE_POPEN [# | fd = popen("ls", "r") %

    +-- #else ]# | fd = fopen("tmp", "w") +-> #endif
  52. Code investigation

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

    [<Tab> ]<Tab>
  54. ctags/cscope

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

    Ctrl-w_gF
  56. Quickfix

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

  58. Diff mode

  59. $ vimdiff :diffsplit :vertical diffsplit :diffthis :diffpatch [c ]c do

    dp
  60. Versatile ][ motions

  61. [[ ]] [] ][ [{ ]} [( ]) [c ]c

    [m ]m [s ]s [z ]z [' ]' [# ]# [/ ]/
  62. Magic g modifier

  63. g# g& g< gd gD gJ gR g] ga go

    gp gv gw
  64. Command line

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

  66. Multi-language input

  67. i_Ctrl-^ langmap

  68. Minimal recommended config

  69. :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
  70. Plugin extentions

  71. Vim directory structure ~/.vim |-- after |-- autoload |-- colors

    |-- doc |-- ftplugin |-- plugin `-- syntax
  72. Manual plugin management is not convenient

  73. 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
  74. vundle Takes ideas behind pathogen and brings it to the

    next level Inspired by Ruby's bundler gem
  75. 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
  76. General purpose plugins

  77. buffexplorer Quickly and easily switch between buffers

  78. NERDTree Allows you to explore your filesystem and to open

    files and directories
  79. Gundo Visualize your Vim undo tree

  80. MRU Provides an easy access to a list of Most

    Recently Used files
  81. FuzzyFinder Provides convenient ways to quickly reach the buffer, file,

    command, bookmark, tag you want, using fuzzy pattern matching
  82. powerline Vim statusline on steroids:

  83. grep Powerful integration with system's *grep utilities, including ability to

    grep through Vim buffers
  84. 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.
  85. EasyMotion Highlights all possible motion choices and allows you to

    press one key to jump directly to the target
  86. MultipleSearch Display multiple searches at the same time with different

    color highlights
  87. surround Easily delete, change and add surroundings in pairs (parentheses,

    brackets, quotes, XML tags, and more)
  88. repeat Allows to repeat complex plugin's actions (for example surround)

    by remapping . command
  89. Align Easily align text and program code in various ways,

    using multitude of predefined align-schemas or powerful manual control
  90. DirDiff Performs a recursive diff on two directories and generates

    a diff window, similar to GUI diff tools like Kdiff3 or Kompare
  91. SudoEdit Allows to read/write a file from inside vim with

    sudo privileges
  92. gnupg Transparent editing of gpg encrypted files

  93. file-line Allows to open files as file:line and place a

    cursor on chosen line
  94. greplace Global Replace plugin allows you to search and replace

    a pattern across multiple files
  95. VisIncr Facilitates making a column of increasing or decreasing numbers,

    dates, or day names
  96. 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
  97. info GNU info documentation browser

  98. Programming related plugins

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

    etc.
  100. 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
  101. Tagbar Similar to the Taglist plugin, but is superior in

    some ways and provides an ability to sort tags by scope
  102. Tagselect A better :tselect and Ctrl-] commands Shows matched tags

    in a separate window, which can be searched and scrolled with ordinary vim commands
  103. cscope_macros Handy mappings and commands to search tags with cscope

  104. fugitive An awesome git integration into vim

  105. OmniCppComplete C/C++ omni-completion with ctags database, a kind of intellisense

    for vim
  106. 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
  107. EnhCommentify Automatically comment/uncomment lines of code in various programming languages

  108. NERDCommenter Another one nice commenter, it complements EnhCommentify, adding some

    features which the latter doesn't have
  109. snipMate Brings TextMate's snippets features in Vim for various programming

    languages
  110. 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
  111. errormarker Highlights and sets error markers for lines with compile

    errors
  112. camelcasemotion Motion through CamelCaseWords and underscore_notation

  113. argtextobj Text-object like motion for function's arguments

  114. BlockDiff Shows diff between two arbitrary blocks of text

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

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

    buffer
  117. 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
  118. 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
  119. patchreview Simplify the process of reviewing multi-file patches, by showing

    each file changes in a diffsplit in separate vim tab
  120. Other mics plugins

  121. Marks-Browser Shows list of set marks (including special) for the

    current file in a separate window
  122. ShowMarks Visually shows the location of marks by placing a

    sign in the leftmost column of the buffer
  123. diffchanges Show changes, made to current buffer since the last

    save, in a diff mode
  124. xml.vim Makes editing xml (and html) files a kid's play

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

  126. deb Allows to browse debian package in the same way

    you can browse .tar and .zip files
  127. Eternal question:

  128. Vim vs Emacs . .

  129. It doesn't matter, just choose one of them but vim

    is better anyway ; )
  130. 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
  131. F!N