SlideShare a Scribd company logo
1 of 78
Download to read offline
VIM for (PHP)
Programmers
   Andrei Zmievski




  CodeWorks ⁓ 2009
  http://joind.in/764
who is this guy?
~   PHP core developer since 1999
~   Architect and lead developer of the Unicode
    and internationalization (i18n) in PHP 6
~   Author of PHP-GTK, Smarty, “PHP Developer’s
    Cookbook”
~   Linguistics semi-master
~   Twitter: @a
~   Beer lover (and brewer)
help

~   learn how to get help effectively
~   :help is your friend
~   use CTRL-V before a CTRL sequence command
~   use i_ and v_ prefixes to get help for CTRL
    sequences in Insert and Visual modes
~   use CTRL-] (jump to tag) and CTRL-T (go back)
    in help window
intro
~   how well do you know vim’s language?
~   what is the alphabet?
~   look at your keyboard
~   can you name what every key does?
~   modes - what are they?
~   how many do you know?
~   how many do you use?
intro
if you don’t like the language, change it
example: how do you quit vim quickly?
  ZZ (exit with saving)
  ZQ (exit without save)
  or
  :nmap ,w :x<CR>
  :nmap ,q :q!<CR>
tip: set showcmd to see partial commands as
you type them
where am i?

How do you tell where you are?
~   simple - CTRL-G
~   detailed - gCTRL-G
~   do yourself a favor and set ruler
~   shows line, column, and percentage in status line
~   or configure it however you want with
    ‘rulerformat’
moving

~   do you us h/j/k/l for moving?
~   or are you stuck in GUIarrowy world?
~   if you are, re-learn
~   save yourself countless miles of movement
    between home row and arrows
moving

How do you move to:
~   start/end of buffer? gg and G
~   line n? nG or ngg
~   n% into the file? n%
~   the first non-blank character in the line? ^
~   first non-blank character on next line? <CR>
~   first non-blank character on previous line? -
marks
~   we can bookmark locations in the buffer
~   m<letter> sets mark named <letter> at
    current location
~   `<letter> jumps precisely to that mark
~   ‘<letter> jumps to the line with the mark
~   lowercase letter: mark is local to the buffer
~   uppercase letter: mark is global, your buffer will
    be switched to the file with the mark
~   :marks shows you your current marks
marks

~   marks are very handy for changing text
~   set a mark (let’s say ma)
~   then you can do:
    ~   c`a - change text from cursor to mark a
    ~   d`a - delete text from cursor to mark a
    ~   =’a - reformat lines from current one to the one
        with mark a
marks
~   let’s say you jump somewhere
~   how do you go back?
~   `` moves you between the last two locations
~   you can set ` (the context mark) explicitly:
    ~   m`, jump elsewhere, then come back with ``
    tip: CTRL-O and CTRL-I move between
    positions in the full jump history, but can’t be
    used as motions
    ‘. and `. - jump to the line or exact location of
    the last modification
insert


~   gi - incredibly handy
~   goes to Insert mode where you left it last time
~   scenario: edit something, exit Insert, go look at
    something else, then gi back to restart editing
insert
Some more goodies:
~   CTRL-Y and CTRL-E (avoid work if you can)
    ~   inserts chars from above or below the cursor
~   CTRL-A (oops, i want to do that again)
    ~   inserts previously inserted text
~   CTRL-R=<expr> (built-in calculator)
    ~   inserts anything vim can calculate
~   CTRL-T and CTRL-D (tab and de-tab)
    ~   inserts or deletes one shiftwidth of indent at the start of
        the line
delete


set your <Backspace> free
:set backspace=start,indent,eol
lets you backspace past the start of edit, auto-
indenting, and even start of the line
search

~   searching is essential
~   movement and information
~   how do you search?
~   f/F/t/T anyone?
~   how about * and #?
search
Search within the line:
~   f/F<char> jumps to the first <char> to the
    right/left and places cursor on it
~   t/T<char> jumps does the same, but stops
    one character short of it
~   df; - delete text from cursor to the first ; to
    the right
~   cT$ - change text from cursor up to the first
    $ to the left
search
~   often you want to find other instances of word
    under the cursor
    ~   */# - find next/previous instance of whole word
    ~   g*/g# - find next/previous instance of partial word
~   or find lines with a certain word:
    ~   [I and ]I - list lines with word under the cursor
    ~   more convenient to use a mapping to jump to a line:
         :map ,f [I:let nr = input("Which one: ")<Bar>exe
         "normal " . nr ."[t"<CR>
search

~   of course, there’s always regexp search
~   /<pattern> - search forward for <pattern>
~   ?<pattern> - search backward for <pattern>
~   n repeats the last search
~   N repeats it in the opposite direction
~   vim regexp language is too sophisticated to be
    covered here
search

Control your search options
~   :set wrapscan - to make search wrap around
~   :set incsearch - incremental search, <Enter>
    accepts, <Esc> cancels
~   :set ignorecase - case-insensitive search, or use
    this within the pattern:
    ~   c - force case-insensitive search
    ~   C - force case-sensitive search
search

~   remember that every search/jump can be used
    as a motion argument
~   d/^# - delete everything up to the next
    comment
~   y/^class/;?function - copy everything from
    current point to the first function before the
    first class
replace
~   :[range]s/<pattern>/<replace>/{flags}
    is the substitute command
~   used mainly with range addresses
~   range addresses are very powerful (read the
    manual)
~   but who wants to count out lines and do
    something like :-23,’ts/foo/bar/
~   in reality you almost always use a couple of
    shortcuts and Visual mode for the rest
replace
~   useful range addresses:
    ~   % - equal to 1,$ (the entire file)
    ~   . - current line
    ~   /<pattern>/ or ?<pattern>? - line where
        <pattern> matches
~   :%s/foo/bar/   - replace first foo in each
    matching line with bar in the entire file
~   :.,/</body>/s,<br>,<br/>,gc        - fix br tags
    from current line until the one with </body> in
    it, asking for confirmation (c - ‘cautious’ mode)
replace


~   & - repeat last substitution on current line
~   :&& - repeat it with the flags that were used
~   g& - repeat substitution globally, with flags
text objects

~   better know what they are
~   since they are fantastically handy
~   can be used after an operator or in Visual mode
~   come in “inner” and “ambient” flavors
~   inner ones always select less text than ambient
    ones
text objects
~   aw, aW - ambient word or WORD (see docs)
~   iw, iW - inner word or WORD (see docs)
~   as, is - ambient or inner sentence
~   ap, ip - ambient or inner paragraph
~   a{, i{ - whole {..} block or text inside it
~   a(, i( - whole (..) block or just text inside it
~   a<, i< - whole <..> block or just text inside it
text objects
~   there are some cooler ones
~   a’, i’    - single-quoted string or just the text
    inside
~   a”, i”    - double-quoted string or just the text
    inside
    ~   note that these are smart about escaped quotes
        inside strings
~   at, it- whole tag block or just text inside
    (HTML and XML tags)
text objects

examples:
 das - delete the sentence, including whitespace after
 ci( - change text inside (..) block
 yat - copy the entire closest tag block the cursor is
 inside
 gUi’ - uppercase text inside the single-quoted string
 vip - select the paragraph in Visual mode, without
 whitespace after
copy/delete/paste
~   you should already know these
~   y - yank (copy), d - delete, p - paste after, P -
    paste before
~   ]p, ]P - paste after/before but adjust the
    indent
~   Useful mappings to paste and reformat/reindent
     :nnoremap <Esc>P        P'[v']=
     :nnoremap <Esc>p        p'[v']=
registers

~   registers: your multi-purpose clipboard
~   you use them without even knowing
~   every y or d command copies to a register
~   unnamed or named
~   “<char> before a copy/delete/paste specifies
    register named <char>
registers
~   copying to uppercase registers append to their
    contents
    ~   useful for picking out bits from the buffers and
        pasting as a chunk
~   “wyy - copy current line into register w
~   “WD - cut the rest of the line and append it to
    the contents of register W
~   “wp - paste the contents of register w
~   CTRL-Rw - insert the contents of register w (in
    Insert mode)
registers

~   you can record macros into registers
    ~   q<char> - start recording typed text into register
        <char>
    ~   next q stops recording
    ~   @<char> executes macro <char>
    ~   @@ repeats last executed macro
~   use :reg to see what’s in your registers
undo

~   original vi had only one level of undo
~   yikes!
~   vim has unlimited (limited only by memory)
~   set ‘undolevels’ to what you need (1000
    default)
undo

~   simple case: u - undo, CTRL-R - redo
~   vim 7 introduces branched undo
~   if you undo something, and make a change, a
    new branch is created
~   g-, g+ - go to older/newer text state (through
    branches)
undo

~   you can travel through time
    ~   :earlier Ns,m,h - go to text state as it was N
        seconds, minutes, hours ago
    ~   :later Ns,m,h - go to a later text state similarly
~   :earlier 10m   - go back 10 minutes, before I
    drank a can of Red Bull and made all these crazy
    changes. Whew.
visual mode
~   use it, it's much easier than remembering
    obscure range or motion commands
~   start selection with:
    ~   v - characterwise,
    ~   V - linewise
    ~   CTRL-V - blockwise
~   use any motion command to change selection
~   can execute any normal or : command on the
    selection
visual mode
~   Visual block mode is awesome
~   especially for table-like text
    tip: o switches cursor to the other corner,
    continue selection from there
~   Once you are in block mode:
    ~   I<text><Esc> - insert <text> before block on every
        line
    ~   A<text><Esc> - append <text> after block on every line
    ~   c<text><Esc> - change every line in block to <text>
    ~   r<char><Esc> - replace every character with <char>
abbreviations

~   Real-time string replacement
~   Expanded when a non-keyword character is
    typed
    ~   :ab tempalte template - fix misspellings
    ~   more complicated expansion:
    ~   :iab techo <?php echo ?><Left><Left><Left>
windows

~   learn how to manipulate windows
~   learn how to move between them
~   :new, :sp should be at your fingertips
~   CTRL-W commands - learn essential ones for
    resizing and moving between windows
tab pages

~   vim 7 supports tab pages
~   :tabe <file> to edit file in a new tab
~   :tabc to close
~   :tabn, :tabp (or gt, gT to switch)
~   probably want to map these for easier
    navigation (if gt, gT are too difficult)
completion
~   vim is very completion friendly
~   just use <Tab> on command line
    ~   for filenames, set ‘wildmenu’ and ‘wildmode’ (I
        like "list:longest,full")
    ~   :new ~/dev/fo<Tab> - complete filename
    ~   :help ‘comp<Tab> - complete option name
    ~   :re<Tab> - complete command
    ~   hit <Tab> again to cycle, CTRL-N for next match,
        CTRL-P for previous
completion

~   CTRL-X starts completion mode in Insert mode
~   follow with CTRL- combos (:help ins-
    completion)
~   i mostly use filename, identifier, and omni
    completion
~   when there are multiple matches, a nice
    completion windows pops up
completion
~   CTRL-X CTRL-F     to complete filenames
~   CTRL-X CTRL-N     to complete identifiers
~   hey, that’s so useful I’ll remap <Tab>

      “ Insert <Tab> or complete identifier
      “ if the cursor is after a keyword character
      function MyTabOrComplete()
          let col = col('.')-1
          if !col || getline('.')[col-1] !~ 'k'
               return "<tab>"
          else
               return "<C-N>"
          endif
      endfunction

      inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
completion


~   omni completion is heuristics-based
~   guesses what you want to complete
~   specific to the file type you’re editing
~   more on it later
maps
~   maps for every mode and then some
~   tired of changing text inside quotes?
     :nmap X ci"
~   make vim more browser-like?
     :nmap <Space> <PageDown>
~   insert your email quickly?
     :imap ;EM me@mydomain.com
~   make <Backspace> act as <Delete> in Visual
    mode?
     :vmap <BS> x
options

~   vim has hundreds of options
~   learn to control the ones you need
~   :options lets you change options interactively
~   :options | resize is better (since there are
    so many)
sessions
~   a session keeps the views for all windows, plus
    the global settings
~   you can save a session and when you restore it
    later, the window layout looks the same.
~   :mksession <file> to write out session to a
    file
~   :source <file> to load session from a file
~   vim -S <file> to start editing a session
miscellaneous
~   gf - go to file under cursor (CTRL-W CTRL-F
    for new window)
~   :read in contents of file or process
    ~   :read foo.txt - read in foo.txt
    ~   :read !wc %:h - run wc on current file and insert
        result into the text
~   filter text: :%!sort, :%!grep, or use :! in visual
    mode
    ~   i like sorting lists like this: vip:!sort
miscellaneous

~   use command-line history
~   : and / followed by up/down arrows move
    through history
~   : and / followed by prefix and arrows restrict
    history to that prefix
~   q: and q/ for editable history (<Enter>
    executes, CTRL-C copies to command line)
miscellaneous
~   CTRL-A and CTRL-X to increment/decrement
    numbers under the cursor (hex and octal too)
~   ga   - what is this character under my cursor?
~   :set number to turn line numbers on
~   or use this to toggle line numbers:
     :nmap <silent> <F6> set number!<CR>
~   :set autowrite - stop vim asking if you want
    to write the file before leaving buffer
~   CTRL-E/CTRL-Y - scroll window down/up
    without moving cursor
miscellaneous
~   :set scroloff=N to start scrolling when
    cursor is N lines from the top/bottom edge
~   :set updatecount=50 to write swap file to
    disk after 50 keystrokes
~   :set showmatch matchtime=3 - when
    bracket is inserted, briefly jump to the matching
    one
~   in shell: fc invokes vim on last command, and
    runs it after vim exits (or fc N to edit
    command N in history)
~   vimdiff in shell (:help vimdiff)
miscellaneous


~   map CTRL-L to piece-wise copying of the line
    above the current one
     imap <C-L> @@@<ESC>hhkywjl?@@@<CR>P/@@@<CR>3s
customization
~   customize vim by placing files in you ~/.vim dir
~   filetype plugin on, filetype indent on
.vimrc - global settings
.vim/

 after/
 
 
 - files that are loaded at the very end

 
 ftplugin/

 
 plugin/

 
 syntax/

 
 ...

 autoload/

 - automatically loaded scripts

 colors/ 
 
 - custom color schemes

 doc/
 
 
 - plugin documentation

 ftdetect/

 - filetype detection scripts

 ftplugin/

 - filetype plugins

 indent/
 
 - indent scripts

 plugin/
 
 - plugins

 syntax/
 
 - syntax scripts
php: linting
~   vim supports arbitrary build/lint commands
~   if we set 'makeprg' and 'errorformat'
    appropriately..
     :set makeprg=php -l %
     :set errorformat=%m in %f on line %l
~   now we just type :make (and <Enter> a couple
    of times)
~   cursor jumps to line with syntax error
php: match pairs
~   you should be familiar with % command (moves
    cursor to matching item)
~   used with (), {}, [], etc
~   but can also be used to jump between PHP and
    HTML tags
~   use matchit.vim plugin
~   but syntax/php.vim has bugs and typos in the
    matching rule
~   i provide my own
php: block objects
~   similar to vim's built-in objects
    ~   aP - PHP block including tags
    ~   iP - text inside PHP block
    examples:
    ~   vaP - select current PHP block (with tags)
    ~   ciP - change text inside current PHP block
    ~   yaP - copy entire PHP block (with tags)
~   provided in my .vim/ftplugin/php.vim file
php: syntax options
~   vim comes with a very capable syntax plugin for
    PHP
~   provides a number of options
    ~   let php_sql_query=1 to highlight SQL syntax in
        strings
    ~   let php_htmlInStrings=1 to highlight HTML in
        string
    ~   let php_noShortTags = 1 to disable short tags
    ~   let php_folding = 1 to enable folding for
        classes and functions
php: folding

~   learn to control folding
    ~   zo - open fold (if the cursor is on the fold line)
    ~   zc - close closest fold
    ~   zR - open all folds
    ~   zM - close all folds
    ~   zj - move to the start of the next fold
    ~   zk - move to the end of the previous fold
php: tags
~   for vim purposes, tags are PHP identifiers
    (classes, functions, constants)
~   you can quickly jump to the definition of each
    tag, if you have a tags file
~   install Exuberant Ctags
~   it can scan your scripts and output tags file,
    containing identifier info
~   currently does not support class membership
    info (outputs methods as functions)
~   have to apply a third-party patch to fix
php: tags

~   use mapping to re-build tags file after editing
     nmap <silent> <F4>
              :!ctags -f ./tags
              --langmap="php:+.inc"
              -h ".php.inc" -R --totals=yes
              --tag-relative=yes --PHP-kinds=+cf-v .<CR>

     set tags=./tags,tags

~   all PHP files in current directory and under it
    recursively will be scanned
php: tags
~   CTRL-] - jump to tag under cursor
~   CTRL-W CTRL-] - jump to tag in a new window
~   :tag <ident> - jump to an arbitrary tag
~   :tag /<regexp> - jump to or list tags matching
    <regexp>
~   if multiple matches - select one from a list
~   :tselect <ident> or /<regexp> - list tags
    instead of jumping
~   CTRL-T - return to where you were
~   See also taglist.vim plugin
php: completion

~   vim 7 introduces powerful heuristics-based
    omni completion
~   CTRL-X CTRL-O starts the completion (i map it
    to CTRL-F)
~   completes classes, variables, methods in a smart
    manner, based on context
php: completion

~   completes built-in functions too
~   function completion shows prototype preview
    ~   array_<CTRL-X><CTRL-O> shows list of array
        functions
    ~   select one from the list, and the prototype shows in
        a preview window
    ~   CTRL-W CTRL-Z to close preview window
php: completion

~   switches to HTML/CSS/Javascript completion
    outside PHP blocks
~   see more:
    ~   :help ins-completion
    ~   :help popupmenu-completion
    ~   :help popupmenu-keys
    ~   :help ft-php-omni
plugins

~   vim can be infinitely customized and expanded
    via plugins
~   there are thousands already written
~   installation is very easy, usually just drop them
    into .vim/plugin
~   read instructions first though
netrw
~   makes it possible to read, write, and browse remote
    directories and files
~   i usually use it over ssh connections via scp
~   need to run ssh-agent to avoid continuous prompts for
    passphrase
~   don't use passphrase-less keys!
~   once set up:
    ~   vim scp://hostname/path/to/file
    ~   :new scp://hostname/path/to/dir/
NERDTree


~   similar to netrw browser but looks more like a
    hierarchical explorer
~   does not support remote file operations
    ~   :nmap <silent> <F7> :NERDTreeToggle<CR>
taglist

~   provides an overview of the source code
~   provides quick access to classes, functions,
    constants
~   automatically updates window when switching
    buffers
~   can display prototype and scope of a tag
~   requires Exuberant Ctags
taglist
~   stick this in ~/.vim/after/plugin/general.vim
let Tlist_Ctags_Cmd = "/usr/local/bin/ctags-ex"
let Tlist_Inc_Winwidth = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Process_File_Always = 1
let Tlist_Enable_Fold_Column = 0
let tlist_php_settings = 'php;c:class;d:constant;f:function'
if exists('loaded_taglist')
    nmap <silent> <F8> :TlistToggle<CR>
endif
snippetsEmu
~   emulates some of the functionality of TextMate
    snippets
~   supports many languages, including PHP/HTML/
    CSS/Javascript
~   by default binds to <Tab> but that's annoying
~   need to remap the key after it's loaded
~   put this in ~/.vim/after/plugin/general.vim
      if exists('loaded_snippet')
          imap <C-B> <Plug>Jumper
      endif
      inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
php documentor
~   inserts PHP Documentor blocks automatically
~   works in single or multi-line mode
~   doesn’t provide mappings by default
~   read documentation to set up default variables
    for copyright, package, etc
~   put this in ~/.vim/ftplugin/php.vim
inoremap <buffer> <C-P> <Esc>:call PhpDocSingle()<CR>i
nnoremap <buffer> <C-P> :call PhpDocSingle()<CR>
vnoremap <buffer> <C-P> :call PhpDocRange()<CR>
let g:pdv_cfg_Uses = 1
project


~   Provides IDE-like project file management
~   Lets you group files and access them quickly
~   Can grep through and execute custom
    commands
0scan

~   Tag-based search for a variety of information
~   Quick access to:
    ~   buffers, files, windows, tabs
    ~   objects, methods
    ~   things from ctags database
    ~   registers to paste text from
    ~   current file changes to move to
    ~   vim marks to jump to
xdebug-ger

~   allows debugging with xdebug through DBGp
    protocol
~   fairly basic, but does the job
~   vim needs to be compiled with +python feature
~   see resources section for documentation links
vcscommand



~   provides interface to CVS/SVN/git
~   install it, then :help vcscommand
conclusion

~   vim rules
~   this has been only a partial glimpse
~   from my very subjective point of view
~   don’t be stuck in an editor rut
~   keep reading and trying things out
resources
~   vim tips: http://www.vim.org/tips/
~   vim scripts: http://www.vim.org/scripts/index.php
~   Exuberant Ctags: http://ctags.sourceforge.net
~   PHP patch for ctags: http://www.live-emotion.com/memo/index.php?
    plugin=attach&refer=%CA%AA%C3%D6&openfile=ctags-5.6j-php.zip
~   article on xdebug and vim: http://2bits.com/articles/using-vim-and-
    xdebug-dbgp-for-debugging-drupal-or-any-php-application.html
~   more cool plugins:
    ~   Surround: http://www.vim.org/scripts/script.php?script_id=1697
    ~   ShowMarks: http://www.vim.org/scripts/script.php?script_id=152
    ~   Vim Outliner: http://www.vim.org/scripts/script.php?script_id=517
    ~   Tetris: http://www.vim.org/scripts/script.php?script_id=172
"As with everything, best not to
  look too deeply into this."
Thank You!


   http://joind.in/764
http://zmievski.org/talks/

More Related Content

What's hot

ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARDTia Ricci
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 
15 practical grep command examples in linux
15 practical grep command examples in linux15 practical grep command examples in linux
15 practical grep command examples in linuxTeja Bheemanapally
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressionsBen Brumfield
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionBharat17485
 
Beginning with vi text editor
Beginning with vi text editorBeginning with vi text editor
Beginning with vi text editorJose Pla
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
Regular expressions in Perl
Regular expressions in PerlRegular expressions in Perl
Regular expressions in PerlGirish Manwani
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsJesse Anderson
 

What's hot (18)

Awk essentials
Awk essentialsAwk essentials
Awk essentials
 
C Reference Card (Ansi) 2
C Reference Card (Ansi) 2C Reference Card (Ansi) 2
C Reference Card (Ansi) 2
 
ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARD
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
Lecture2 B
Lecture2 BLecture2 B
Lecture2 B
 
15 practical grep command examples in linux
15 practical grep command examples in linux15 practical grep command examples in linux
15 practical grep command examples in linux
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Learning Grep
Learning GrepLearning Grep
Learning Grep
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Beginning with vi text editor
Beginning with vi text editorBeginning with vi text editor
Beginning with vi text editor
 
C reference card
C reference cardC reference card
C reference card
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
vi cheat sheet
vi cheat sheetvi cheat sheet
vi cheat sheet
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Vi Cheat Sheet
Vi Cheat SheetVi Cheat Sheet
Vi Cheat Sheet
 
Regular expressions in Perl
Regular expressions in PerlRegular expressions in Perl
Regular expressions in Perl
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 

Viewers also liked

Architectural Analysis of Game Machines
Architectural Analysis of Game MachinesArchitectural Analysis of Game Machines
Architectural Analysis of Game MachinesPraveen AP
 
CS286: Motivation behind F/OSS
CS286: Motivation behind F/OSSCS286: Motivation behind F/OSS
CS286: Motivation behind F/OSSPraveen AP
 
Strategic Communications Bootcamp May 5 French
Strategic Communications Bootcamp May 5 FrenchStrategic Communications Bootcamp May 5 French
Strategic Communications Bootcamp May 5 FrenchCarolineKealey
 
Strategic Communications Bootcamp May 5 English
Strategic Communications Bootcamp May 5 English Strategic Communications Bootcamp May 5 English
Strategic Communications Bootcamp May 5 English CarolineKealey
 
Cloud computing @ slideshare
Cloud computing @ slideshareCloud computing @ slideshare
Cloud computing @ slideshareAkash Agrawal
 
Donation For Anna Hazare Movement in 2010 12
Donation For Anna Hazare Movement in 2010 12Donation For Anna Hazare Movement in 2010 12
Donation For Anna Hazare Movement in 2010 12Akash Agrawal
 
Gunmaweb#12 nuuk jam
Gunmaweb#12 nuuk jamGunmaweb#12 nuuk jam
Gunmaweb#12 nuuk jamivoryworks .
 
Cdn Graficos
Cdn GraficosCdn Graficos
Cdn Graficosxisspano
 
Problemas rurais no Brasil aula - 2011
Problemas rurais no Brasil   aula - 2011Problemas rurais no Brasil   aula - 2011
Problemas rurais no Brasil aula - 2011josafa santana
 

Viewers also liked (20)

Web Topics
Web TopicsWeb Topics
Web Topics
 
Architectural Analysis of Game Machines
Architectural Analysis of Game MachinesArchitectural Analysis of Game Machines
Architectural Analysis of Game Machines
 
cs286final
cs286finalcs286final
cs286final
 
CS286: Motivation behind F/OSS
CS286: Motivation behind F/OSSCS286: Motivation behind F/OSS
CS286: Motivation behind F/OSS
 
79379507 contexto-organizacional
79379507 contexto-organizacional79379507 contexto-organizacional
79379507 contexto-organizacional
 
Intuit Intern
Intuit InternIntuit Intern
Intuit Intern
 
TTS
TTSTTS
TTS
 
iPhone
iPhoneiPhone
iPhone
 
Strategic Communications Bootcamp May 5 French
Strategic Communications Bootcamp May 5 FrenchStrategic Communications Bootcamp May 5 French
Strategic Communications Bootcamp May 5 French
 
Strategic Communications Bootcamp May 5 English
Strategic Communications Bootcamp May 5 English Strategic Communications Bootcamp May 5 English
Strategic Communications Bootcamp May 5 English
 
Avid tv watcher
Avid tv watcherAvid tv watcher
Avid tv watcher
 
Cloud computing @ slideshare
Cloud computing @ slideshareCloud computing @ slideshare
Cloud computing @ slideshare
 
Donation For Anna Hazare Movement in 2010 12
Donation For Anna Hazare Movement in 2010 12Donation For Anna Hazare Movement in 2010 12
Donation For Anna Hazare Movement in 2010 12
 
ccalendar
ccalendarccalendar
ccalendar
 
Curso openmp
Curso openmpCurso openmp
Curso openmp
 
Gunmaweb#12 nuuk jam
Gunmaweb#12 nuuk jamGunmaweb#12 nuuk jam
Gunmaweb#12 nuuk jam
 
Crisis Marketing
Crisis MarketingCrisis Marketing
Crisis Marketing
 
ID Hotel Development
ID Hotel DevelopmentID Hotel Development
ID Hotel Development
 
Cdn Graficos
Cdn GraficosCdn Graficos
Cdn Graficos
 
Problemas rurais no Brasil aula - 2011
Problemas rurais no Brasil   aula - 2011Problemas rurais no Brasil   aula - 2011
Problemas rurais no Brasil aula - 2011
 

Similar to VIM for Programmers

VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) ProgrammersZendCon
 
Linux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxLinux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxKenny (netman)
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foobrian_dailey
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Tuffarsi in vim
Tuffarsi in vimTuffarsi in vim
Tuffarsi in vimsambismo
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchinaguestcf9240
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptxNiladriDey18
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaLin Yo-An
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
Hex file and regex cheat sheet
Hex file and regex cheat sheetHex file and regex cheat sheet
Hex file and regex cheat sheetMartin Cabrera
 
Cheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regexCheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regexKasper de Waard
 

Similar to VIM for Programmers (20)

VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) Programmers
 
Vim and Python
Vim and PythonVim and Python
Vim and Python
 
Linux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxLinux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regx
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Tuffarsi in vim
Tuffarsi in vimTuffarsi in vim
Tuffarsi in vim
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
Vim
VimVim
Vim
 
UNIX_TCL_SED_AWK.pptx
UNIX_TCL_SED_AWK.pptxUNIX_TCL_SED_AWK.pptx
UNIX_TCL_SED_AWK.pptx
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Hex file and regex cheat sheet
Hex file and regex cheat sheetHex file and regex cheat sheet
Hex file and regex cheat sheet
 
Cheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regexCheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regex
 

More from Akash Agrawal

More from Akash Agrawal (12)

2
22
2
 
10 slides with notes
10 slides with notes10 slides with notes
10 slides with notes
 
Leadership Lessons Learnt
Leadership Lessons LearntLeadership Lessons Learnt
Leadership Lessons Learnt
 
AWS Cost Cheat Sheet
AWS Cost Cheat SheetAWS Cost Cheat Sheet
AWS Cost Cheat Sheet
 
Expenditure For Anna Hazare Movement
Expenditure For Anna Hazare MovementExpenditure For Anna Hazare Movement
Expenditure For Anna Hazare Movement
 
Auto scaling
Auto scalingAuto scaling
Auto scaling
 
Call Forwarding
Call ForwardingCall Forwarding
Call Forwarding
 
Work Culture
Work CultureWork Culture
Work Culture
 
HUM-TUM
HUM-TUMHUM-TUM
HUM-TUM
 
Day13-Akash
Day13-AkashDay13-Akash
Day13-Akash
 
Day12 - Akash
Day12 - AkashDay12 - Akash
Day12 - Akash
 
ALEKH
ALEKHALEKH
ALEKH
 

VIM for Programmers

  • 1. VIM for (PHP) Programmers Andrei Zmievski CodeWorks ⁓ 2009 http://joind.in/764
  • 2. who is this guy? ~ PHP core developer since 1999 ~ Architect and lead developer of the Unicode and internationalization (i18n) in PHP 6 ~ Author of PHP-GTK, Smarty, “PHP Developer’s Cookbook” ~ Linguistics semi-master ~ Twitter: @a ~ Beer lover (and brewer)
  • 3. help ~ learn how to get help effectively ~ :help is your friend ~ use CTRL-V before a CTRL sequence command ~ use i_ and v_ prefixes to get help for CTRL sequences in Insert and Visual modes ~ use CTRL-] (jump to tag) and CTRL-T (go back) in help window
  • 4. intro ~ how well do you know vim’s language? ~ what is the alphabet? ~ look at your keyboard ~ can you name what every key does? ~ modes - what are they? ~ how many do you know? ~ how many do you use?
  • 5. intro if you don’t like the language, change it example: how do you quit vim quickly? ZZ (exit with saving) ZQ (exit without save) or :nmap ,w :x<CR> :nmap ,q :q!<CR> tip: set showcmd to see partial commands as you type them
  • 6. where am i? How do you tell where you are? ~ simple - CTRL-G ~ detailed - gCTRL-G ~ do yourself a favor and set ruler ~ shows line, column, and percentage in status line ~ or configure it however you want with ‘rulerformat’
  • 7. moving ~ do you us h/j/k/l for moving? ~ or are you stuck in GUIarrowy world? ~ if you are, re-learn ~ save yourself countless miles of movement between home row and arrows
  • 8. moving How do you move to: ~ start/end of buffer? gg and G ~ line n? nG or ngg ~ n% into the file? n% ~ the first non-blank character in the line? ^ ~ first non-blank character on next line? <CR> ~ first non-blank character on previous line? -
  • 9. marks ~ we can bookmark locations in the buffer ~ m<letter> sets mark named <letter> at current location ~ `<letter> jumps precisely to that mark ~ ‘<letter> jumps to the line with the mark ~ lowercase letter: mark is local to the buffer ~ uppercase letter: mark is global, your buffer will be switched to the file with the mark ~ :marks shows you your current marks
  • 10. marks ~ marks are very handy for changing text ~ set a mark (let’s say ma) ~ then you can do: ~ c`a - change text from cursor to mark a ~ d`a - delete text from cursor to mark a ~ =’a - reformat lines from current one to the one with mark a
  • 11. marks ~ let’s say you jump somewhere ~ how do you go back? ~ `` moves you between the last two locations ~ you can set ` (the context mark) explicitly: ~ m`, jump elsewhere, then come back with `` tip: CTRL-O and CTRL-I move between positions in the full jump history, but can’t be used as motions ‘. and `. - jump to the line or exact location of the last modification
  • 12. insert ~ gi - incredibly handy ~ goes to Insert mode where you left it last time ~ scenario: edit something, exit Insert, go look at something else, then gi back to restart editing
  • 13. insert Some more goodies: ~ CTRL-Y and CTRL-E (avoid work if you can) ~ inserts chars from above or below the cursor ~ CTRL-A (oops, i want to do that again) ~ inserts previously inserted text ~ CTRL-R=<expr> (built-in calculator) ~ inserts anything vim can calculate ~ CTRL-T and CTRL-D (tab and de-tab) ~ inserts or deletes one shiftwidth of indent at the start of the line
  • 14. delete set your <Backspace> free :set backspace=start,indent,eol lets you backspace past the start of edit, auto- indenting, and even start of the line
  • 15. search ~ searching is essential ~ movement and information ~ how do you search? ~ f/F/t/T anyone? ~ how about * and #?
  • 16. search Search within the line: ~ f/F<char> jumps to the first <char> to the right/left and places cursor on it ~ t/T<char> jumps does the same, but stops one character short of it ~ df; - delete text from cursor to the first ; to the right ~ cT$ - change text from cursor up to the first $ to the left
  • 17. search ~ often you want to find other instances of word under the cursor ~ */# - find next/previous instance of whole word ~ g*/g# - find next/previous instance of partial word ~ or find lines with a certain word: ~ [I and ]I - list lines with word under the cursor ~ more convenient to use a mapping to jump to a line: :map ,f [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[t"<CR>
  • 18. search ~ of course, there’s always regexp search ~ /<pattern> - search forward for <pattern> ~ ?<pattern> - search backward for <pattern> ~ n repeats the last search ~ N repeats it in the opposite direction ~ vim regexp language is too sophisticated to be covered here
  • 19. search Control your search options ~ :set wrapscan - to make search wrap around ~ :set incsearch - incremental search, <Enter> accepts, <Esc> cancels ~ :set ignorecase - case-insensitive search, or use this within the pattern: ~ c - force case-insensitive search ~ C - force case-sensitive search
  • 20. search ~ remember that every search/jump can be used as a motion argument ~ d/^# - delete everything up to the next comment ~ y/^class/;?function - copy everything from current point to the first function before the first class
  • 21. replace ~ :[range]s/<pattern>/<replace>/{flags} is the substitute command ~ used mainly with range addresses ~ range addresses are very powerful (read the manual) ~ but who wants to count out lines and do something like :-23,’ts/foo/bar/ ~ in reality you almost always use a couple of shortcuts and Visual mode for the rest
  • 22. replace ~ useful range addresses: ~ % - equal to 1,$ (the entire file) ~ . - current line ~ /<pattern>/ or ?<pattern>? - line where <pattern> matches ~ :%s/foo/bar/ - replace first foo in each matching line with bar in the entire file ~ :.,/</body>/s,<br>,<br/>,gc - fix br tags from current line until the one with </body> in it, asking for confirmation (c - ‘cautious’ mode)
  • 23. replace ~ & - repeat last substitution on current line ~ :&& - repeat it with the flags that were used ~ g& - repeat substitution globally, with flags
  • 24. text objects ~ better know what they are ~ since they are fantastically handy ~ can be used after an operator or in Visual mode ~ come in “inner” and “ambient” flavors ~ inner ones always select less text than ambient ones
  • 25. text objects ~ aw, aW - ambient word or WORD (see docs) ~ iw, iW - inner word or WORD (see docs) ~ as, is - ambient or inner sentence ~ ap, ip - ambient or inner paragraph ~ a{, i{ - whole {..} block or text inside it ~ a(, i( - whole (..) block or just text inside it ~ a<, i< - whole <..> block or just text inside it
  • 26. text objects ~ there are some cooler ones ~ a’, i’ - single-quoted string or just the text inside ~ a”, i” - double-quoted string or just the text inside ~ note that these are smart about escaped quotes inside strings ~ at, it- whole tag block or just text inside (HTML and XML tags)
  • 27. text objects examples: das - delete the sentence, including whitespace after ci( - change text inside (..) block yat - copy the entire closest tag block the cursor is inside gUi’ - uppercase text inside the single-quoted string vip - select the paragraph in Visual mode, without whitespace after
  • 28. copy/delete/paste ~ you should already know these ~ y - yank (copy), d - delete, p - paste after, P - paste before ~ ]p, ]P - paste after/before but adjust the indent ~ Useful mappings to paste and reformat/reindent :nnoremap <Esc>P P'[v']= :nnoremap <Esc>p p'[v']=
  • 29. registers ~ registers: your multi-purpose clipboard ~ you use them without even knowing ~ every y or d command copies to a register ~ unnamed or named ~ “<char> before a copy/delete/paste specifies register named <char>
  • 30. registers ~ copying to uppercase registers append to their contents ~ useful for picking out bits from the buffers and pasting as a chunk ~ “wyy - copy current line into register w ~ “WD - cut the rest of the line and append it to the contents of register W ~ “wp - paste the contents of register w ~ CTRL-Rw - insert the contents of register w (in Insert mode)
  • 31. registers ~ you can record macros into registers ~ q<char> - start recording typed text into register <char> ~ next q stops recording ~ @<char> executes macro <char> ~ @@ repeats last executed macro ~ use :reg to see what’s in your registers
  • 32. undo ~ original vi had only one level of undo ~ yikes! ~ vim has unlimited (limited only by memory) ~ set ‘undolevels’ to what you need (1000 default)
  • 33. undo ~ simple case: u - undo, CTRL-R - redo ~ vim 7 introduces branched undo ~ if you undo something, and make a change, a new branch is created ~ g-, g+ - go to older/newer text state (through branches)
  • 34. undo ~ you can travel through time ~ :earlier Ns,m,h - go to text state as it was N seconds, minutes, hours ago ~ :later Ns,m,h - go to a later text state similarly ~ :earlier 10m - go back 10 minutes, before I drank a can of Red Bull and made all these crazy changes. Whew.
  • 35. visual mode ~ use it, it's much easier than remembering obscure range or motion commands ~ start selection with: ~ v - characterwise, ~ V - linewise ~ CTRL-V - blockwise ~ use any motion command to change selection ~ can execute any normal or : command on the selection
  • 36. visual mode ~ Visual block mode is awesome ~ especially for table-like text tip: o switches cursor to the other corner, continue selection from there ~ Once you are in block mode: ~ I<text><Esc> - insert <text> before block on every line ~ A<text><Esc> - append <text> after block on every line ~ c<text><Esc> - change every line in block to <text> ~ r<char><Esc> - replace every character with <char>
  • 37. abbreviations ~ Real-time string replacement ~ Expanded when a non-keyword character is typed ~ :ab tempalte template - fix misspellings ~ more complicated expansion: ~ :iab techo <?php echo ?><Left><Left><Left>
  • 38. windows ~ learn how to manipulate windows ~ learn how to move between them ~ :new, :sp should be at your fingertips ~ CTRL-W commands - learn essential ones for resizing and moving between windows
  • 39. tab pages ~ vim 7 supports tab pages ~ :tabe <file> to edit file in a new tab ~ :tabc to close ~ :tabn, :tabp (or gt, gT to switch) ~ probably want to map these for easier navigation (if gt, gT are too difficult)
  • 40. completion ~ vim is very completion friendly ~ just use <Tab> on command line ~ for filenames, set ‘wildmenu’ and ‘wildmode’ (I like "list:longest,full") ~ :new ~/dev/fo<Tab> - complete filename ~ :help ‘comp<Tab> - complete option name ~ :re<Tab> - complete command ~ hit <Tab> again to cycle, CTRL-N for next match, CTRL-P for previous
  • 41. completion ~ CTRL-X starts completion mode in Insert mode ~ follow with CTRL- combos (:help ins- completion) ~ i mostly use filename, identifier, and omni completion ~ when there are multiple matches, a nice completion windows pops up
  • 42. completion ~ CTRL-X CTRL-F to complete filenames ~ CTRL-X CTRL-N to complete identifiers ~ hey, that’s so useful I’ll remap <Tab> “ Insert <Tab> or complete identifier “ if the cursor is after a keyword character function MyTabOrComplete() let col = col('.')-1 if !col || getline('.')[col-1] !~ 'k' return "<tab>" else return "<C-N>" endif endfunction inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
  • 43. completion ~ omni completion is heuristics-based ~ guesses what you want to complete ~ specific to the file type you’re editing ~ more on it later
  • 44. maps ~ maps for every mode and then some ~ tired of changing text inside quotes? :nmap X ci" ~ make vim more browser-like? :nmap <Space> <PageDown> ~ insert your email quickly? :imap ;EM me@mydomain.com ~ make <Backspace> act as <Delete> in Visual mode? :vmap <BS> x
  • 45. options ~ vim has hundreds of options ~ learn to control the ones you need ~ :options lets you change options interactively ~ :options | resize is better (since there are so many)
  • 46. sessions ~ a session keeps the views for all windows, plus the global settings ~ you can save a session and when you restore it later, the window layout looks the same. ~ :mksession <file> to write out session to a file ~ :source <file> to load session from a file ~ vim -S <file> to start editing a session
  • 47. miscellaneous ~ gf - go to file under cursor (CTRL-W CTRL-F for new window) ~ :read in contents of file or process ~ :read foo.txt - read in foo.txt ~ :read !wc %:h - run wc on current file and insert result into the text ~ filter text: :%!sort, :%!grep, or use :! in visual mode ~ i like sorting lists like this: vip:!sort
  • 48. miscellaneous ~ use command-line history ~ : and / followed by up/down arrows move through history ~ : and / followed by prefix and arrows restrict history to that prefix ~ q: and q/ for editable history (<Enter> executes, CTRL-C copies to command line)
  • 49. miscellaneous ~ CTRL-A and CTRL-X to increment/decrement numbers under the cursor (hex and octal too) ~ ga - what is this character under my cursor? ~ :set number to turn line numbers on ~ or use this to toggle line numbers: :nmap <silent> <F6> set number!<CR> ~ :set autowrite - stop vim asking if you want to write the file before leaving buffer ~ CTRL-E/CTRL-Y - scroll window down/up without moving cursor
  • 50. miscellaneous ~ :set scroloff=N to start scrolling when cursor is N lines from the top/bottom edge ~ :set updatecount=50 to write swap file to disk after 50 keystrokes ~ :set showmatch matchtime=3 - when bracket is inserted, briefly jump to the matching one ~ in shell: fc invokes vim on last command, and runs it after vim exits (or fc N to edit command N in history) ~ vimdiff in shell (:help vimdiff)
  • 51. miscellaneous ~ map CTRL-L to piece-wise copying of the line above the current one imap <C-L> @@@<ESC>hhkywjl?@@@<CR>P/@@@<CR>3s
  • 52. customization ~ customize vim by placing files in you ~/.vim dir ~ filetype plugin on, filetype indent on .vimrc - global settings .vim/ after/ - files that are loaded at the very end ftplugin/ plugin/ syntax/ ... autoload/ - automatically loaded scripts colors/ - custom color schemes doc/ - plugin documentation ftdetect/ - filetype detection scripts ftplugin/ - filetype plugins indent/ - indent scripts plugin/ - plugins syntax/ - syntax scripts
  • 53. php: linting ~ vim supports arbitrary build/lint commands ~ if we set 'makeprg' and 'errorformat' appropriately.. :set makeprg=php -l % :set errorformat=%m in %f on line %l ~ now we just type :make (and <Enter> a couple of times) ~ cursor jumps to line with syntax error
  • 54. php: match pairs ~ you should be familiar with % command (moves cursor to matching item) ~ used with (), {}, [], etc ~ but can also be used to jump between PHP and HTML tags ~ use matchit.vim plugin ~ but syntax/php.vim has bugs and typos in the matching rule ~ i provide my own
  • 55. php: block objects ~ similar to vim's built-in objects ~ aP - PHP block including tags ~ iP - text inside PHP block examples: ~ vaP - select current PHP block (with tags) ~ ciP - change text inside current PHP block ~ yaP - copy entire PHP block (with tags) ~ provided in my .vim/ftplugin/php.vim file
  • 56. php: syntax options ~ vim comes with a very capable syntax plugin for PHP ~ provides a number of options ~ let php_sql_query=1 to highlight SQL syntax in strings ~ let php_htmlInStrings=1 to highlight HTML in string ~ let php_noShortTags = 1 to disable short tags ~ let php_folding = 1 to enable folding for classes and functions
  • 57. php: folding ~ learn to control folding ~ zo - open fold (if the cursor is on the fold line) ~ zc - close closest fold ~ zR - open all folds ~ zM - close all folds ~ zj - move to the start of the next fold ~ zk - move to the end of the previous fold
  • 58. php: tags ~ for vim purposes, tags are PHP identifiers (classes, functions, constants) ~ you can quickly jump to the definition of each tag, if you have a tags file ~ install Exuberant Ctags ~ it can scan your scripts and output tags file, containing identifier info ~ currently does not support class membership info (outputs methods as functions) ~ have to apply a third-party patch to fix
  • 59. php: tags ~ use mapping to re-build tags file after editing nmap <silent> <F4> :!ctags -f ./tags --langmap="php:+.inc" -h ".php.inc" -R --totals=yes --tag-relative=yes --PHP-kinds=+cf-v .<CR> set tags=./tags,tags ~ all PHP files in current directory and under it recursively will be scanned
  • 60. php: tags ~ CTRL-] - jump to tag under cursor ~ CTRL-W CTRL-] - jump to tag in a new window ~ :tag <ident> - jump to an arbitrary tag ~ :tag /<regexp> - jump to or list tags matching <regexp> ~ if multiple matches - select one from a list ~ :tselect <ident> or /<regexp> - list tags instead of jumping ~ CTRL-T - return to where you were ~ See also taglist.vim plugin
  • 61. php: completion ~ vim 7 introduces powerful heuristics-based omni completion ~ CTRL-X CTRL-O starts the completion (i map it to CTRL-F) ~ completes classes, variables, methods in a smart manner, based on context
  • 62. php: completion ~ completes built-in functions too ~ function completion shows prototype preview ~ array_<CTRL-X><CTRL-O> shows list of array functions ~ select one from the list, and the prototype shows in a preview window ~ CTRL-W CTRL-Z to close preview window
  • 63. php: completion ~ switches to HTML/CSS/Javascript completion outside PHP blocks ~ see more: ~ :help ins-completion ~ :help popupmenu-completion ~ :help popupmenu-keys ~ :help ft-php-omni
  • 64. plugins ~ vim can be infinitely customized and expanded via plugins ~ there are thousands already written ~ installation is very easy, usually just drop them into .vim/plugin ~ read instructions first though
  • 65. netrw ~ makes it possible to read, write, and browse remote directories and files ~ i usually use it over ssh connections via scp ~ need to run ssh-agent to avoid continuous prompts for passphrase ~ don't use passphrase-less keys! ~ once set up: ~ vim scp://hostname/path/to/file ~ :new scp://hostname/path/to/dir/
  • 66. NERDTree ~ similar to netrw browser but looks more like a hierarchical explorer ~ does not support remote file operations ~ :nmap <silent> <F7> :NERDTreeToggle<CR>
  • 67. taglist ~ provides an overview of the source code ~ provides quick access to classes, functions, constants ~ automatically updates window when switching buffers ~ can display prototype and scope of a tag ~ requires Exuberant Ctags
  • 68. taglist ~ stick this in ~/.vim/after/plugin/general.vim let Tlist_Ctags_Cmd = "/usr/local/bin/ctags-ex" let Tlist_Inc_Winwidth = 1 let Tlist_Exit_OnlyWindow = 1 let Tlist_File_Fold_Auto_Close = 1 let Tlist_Process_File_Always = 1 let Tlist_Enable_Fold_Column = 0 let tlist_php_settings = 'php;c:class;d:constant;f:function' if exists('loaded_taglist') nmap <silent> <F8> :TlistToggle<CR> endif
  • 69. snippetsEmu ~ emulates some of the functionality of TextMate snippets ~ supports many languages, including PHP/HTML/ CSS/Javascript ~ by default binds to <Tab> but that's annoying ~ need to remap the key after it's loaded ~ put this in ~/.vim/after/plugin/general.vim if exists('loaded_snippet') imap <C-B> <Plug>Jumper endif inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
  • 70. php documentor ~ inserts PHP Documentor blocks automatically ~ works in single or multi-line mode ~ doesn’t provide mappings by default ~ read documentation to set up default variables for copyright, package, etc ~ put this in ~/.vim/ftplugin/php.vim inoremap <buffer> <C-P> <Esc>:call PhpDocSingle()<CR>i nnoremap <buffer> <C-P> :call PhpDocSingle()<CR> vnoremap <buffer> <C-P> :call PhpDocRange()<CR> let g:pdv_cfg_Uses = 1
  • 71. project ~ Provides IDE-like project file management ~ Lets you group files and access them quickly ~ Can grep through and execute custom commands
  • 72. 0scan ~ Tag-based search for a variety of information ~ Quick access to: ~ buffers, files, windows, tabs ~ objects, methods ~ things from ctags database ~ registers to paste text from ~ current file changes to move to ~ vim marks to jump to
  • 73. xdebug-ger ~ allows debugging with xdebug through DBGp protocol ~ fairly basic, but does the job ~ vim needs to be compiled with +python feature ~ see resources section for documentation links
  • 74. vcscommand ~ provides interface to CVS/SVN/git ~ install it, then :help vcscommand
  • 75. conclusion ~ vim rules ~ this has been only a partial glimpse ~ from my very subjective point of view ~ don’t be stuck in an editor rut ~ keep reading and trying things out
  • 76. resources ~ vim tips: http://www.vim.org/tips/ ~ vim scripts: http://www.vim.org/scripts/index.php ~ Exuberant Ctags: http://ctags.sourceforge.net ~ PHP patch for ctags: http://www.live-emotion.com/memo/index.php? plugin=attach&refer=%CA%AA%C3%D6&openfile=ctags-5.6j-php.zip ~ article on xdebug and vim: http://2bits.com/articles/using-vim-and- xdebug-dbgp-for-debugging-drupal-or-any-php-application.html ~ more cool plugins: ~ Surround: http://www.vim.org/scripts/script.php?script_id=1697 ~ ShowMarks: http://www.vim.org/scripts/script.php?script_id=152 ~ Vim Outliner: http://www.vim.org/scripts/script.php?script_id=517 ~ Tetris: http://www.vim.org/scripts/script.php?script_id=172
  • 77. "As with everything, best not to look too deeply into this."
  • 78. Thank You! http://joind.in/764 http://zmievski.org/talks/