Vim Hacks
Upcoming SlideShare
Loading in...5
×
 

Vim Hacks

on

  • 53,996 views

Vim Hacks @ COSCUP

Vim Hacks @ COSCUP

Statistics

Views

Total Views
53,996
Views on SlideShare
42,652
Embed Views
11,344

Actions

Likes
248
Downloads
2,018
Comments
22

84 Embeds 11,344

http://c9s.blogspot.tw 2442
http://blog.superbil.info 2015
http://c9s.blogspot.com 1682
http://www.techgig.com 810
http://hsian-studio.blogspot.tw 757
http://kewang.pixnet.net 637
http://dreamtails.pixnet.net 557
http://svn.cd.cienet.com.cn 360
http://nckuhuahua.pixnet.net 358
http://www.slideshare.net 247
http://hsian-studio.blogspot.com 211
http://wandachiang.blogspot.tw 202
http://blogue-un.blogspot.hk 155
http://blogue-un.blogspot.com 121
http://zeroplex.blogspot.com 98
http://blog.lifetaiwan.net 91
http://chunchaichang.blogspot.com 49
http://chunchaichang.blogspot.tw 45
http://c9s.blogspot.hk 44
http://webcache.googleusercontent.com 41
http://rockymic.blogspot.com 39
http://www.plurk.com 38
http://superbil.blogspot.tw 37
http://blogueun.wordpress.com 34
http://yoyojacky.vicp.net 31
http://c9s.blogspot.jp 31
http://chunghe.blogspot.com 24
http://disp.cc 17
http://zeroplex.blogspot.tw 13
http://wandachiang.blogspot.com 11
http://localhost 10
http://c9s.blogspot.com.au 10
http://www.njuopen.com 9
http://c9s.blogspot.ca 8
http://c9s.blogspot.de 7
http://yuanotes.com 7
http://szchenghuang.blogspot.com 6
http://pscyberessays.blogspot.com 5
http://pscyberessays.blogspot.tw 5
http://www.disp.cc 4
http://c9s.blogspot.fr 4
http://74.125.153.132 4
http://cswang.org 4
http://s.deeeki.com 4
http://203.208.39.132 3
http://chunchaichang.blogspot.jp 3
http://wandachiang.blogspot.hk 2
http://www.techgig.timesjobs.com 2
http://wandachiang.blogspot.de 2
http://chunchaichang.blogspot.hk 2
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

110 of 22 Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…

110 of 22

Post Comment
Edit your comment

    Vim Hacks Vim Hacks Presentation Transcript

    • VIM Hacks Why Vim Vim c9s / Cornelius AIINK.com
    • It doesn’t matter
    • It does matter
    • ...
    • Microsoft Visual Studio
    • Eclipse
    • Code Block
    • Notepad++
    • ....
    • ....
    • • • IDE , Editor
    • • • IDE , Editor • XXX Editor ..
    • • • IDE , Editor • XXX Editor .. • ....
    • Microsoft Windows ...
    • GEdit
    • Emacs
    • TextMate
    • VIM
    • #!/usr/bin/env perl my $hppiness = COS::CUP();
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); Oops! “a”
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP(); xN
    • #!/usr/bin/env perl my $hppiness = COS::CUP();
    • #!/usr/bin/env perl my $happiness = COS::CUP();
    • #!/usr/bin/env perl my $happiness = COS::CUP(); ?
    • #!/usr/bin/env perl my $happiness = COS::CUP(); ?
    • The VIM way...
    • VIM: #!/usr/bin/env perl my $hppiness = COS::CUP(); F h
    • VIM: #!/usr/bin/env perl my $happiness = COS::CUP(); a ppend a
    • VIM
    • VIM
    • IDE
    • ...
    • ...
    • !!!
    • !!! !!!
    • VIM
    • VI Improved
    • Learning Curve
    • Vim
    • Vim • Vim
    • Vim • Vim • gVim
    • Vim • Vim • gVim • gVim Easy
    • Vim • Vim • gVim • gVim Easy • MacVim
    • Vim • Vim • gVim • gVim Easy • MacVim • Vi in Emacs
    • Vim • Vim • gVim • gVim Easy • MacVim • Vi in Emacs • Vi in Bash
    • Vim • Vim • gVim • gVim Easy • MacVim • Vi in Emacs • Vi in Bash • etc ...
    • Features
    • 1. Mode
    • INSERT NORMAL VISUAL SELECT ... et cetera
    • ESC [Ii]NSERT NORMAL [Vv]ISUAL
    • 1.1 Normal Mode
    • Motion
    • HJKL ←↓↑→
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; Cursor } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # [{ my @outs = grep /pattern/ , @list; } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } f@ sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } $ sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } ^ sub func1 { }
    • # comments ... H foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; M } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } sub func1 { } L
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep } C Insert mode sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } sub func1 { }
    • # comments ... foreach my $foo ( @bar ) { # my @outs = grep /pattern/ , @list; } % sub func1 { }
    • :h motion.txt
    • 1.2 Insert Mode
    • Editing text
    • Insert Mode • i : Insert text before the cursor
    • Insert Mode • i : Insert text before the cursor • I : Insert text before the first non-blank in the line
    • Insert Mode • i : Insert text before the cursor • I : Insert text before the first non-blank in the line • a : Append text after the cursor
    • Insert Mode • i : Insert text before the cursor • I : Insert text before the first non-blank in the line • a : Append text after the cursor • A : Append text at the end of the line
    • 1.3 Visual Mode
    • Select region
    • Visual Mode • v : start Visual mode per character.
    • Visual Mode • v : start Visual mode per character. • V : start Visual mode linewise.
    • Visual Mode • v : start Visual mode per character. • V : start Visual mode linewise. • Ctrl-v : start Visual mode blockwise.
    • Visual Mode • v : start Visual mode per character. • V : start Visual mode linewise. • Ctrl-v : start Visual mode blockwise. operator y (yank) , d (delete) , c (change) ... etc
    • 2. Syntax Highlight Support
    • /opt/local/share/vim/vim72 $ ls -1 syntax/ | wc -l 520
    • Syntax
    • ~/.vim/syntax/[filetype].vim
    • ~/.vim/syntax/[filetype].vim syn match [id] [re] [options]
    • ~/.vim/syntax/[filetype].vim syn match [id] [re] [options] syn region [id] start=[re] end=[re]
    • ~/.vim/syntax/[filetype].vim syn match [id] [re] [options] syn region [id] start=[re] end=[re] syn keyword [id] [keyword] ...
    • ~/.vim/syntax/[filetype].vim syn match [id] [re] [options] syn region [id] start=[re] end=[re] syn keyword [id] [keyword] ... hi [id] guibg=[color] ctermfg=[color]
    • :help syntax.txt
    • 3. ENCODING
    • :set fencs=utf-8,gbk,big5,euc-jp,utf-16le :set fenc=utf-8 enc=utf-8 tenc=utf-8
    • :set fencs=utf-8,gbk,big5,euc-jp,utf-16le :set fenc=utf-8 enc=utf-8 tenc=utf-8
    • Vim :set fencs=utf-8,gbk,big5,euc-jp,utf-16le :set fenc=utf-8 enc=utf-8 tenc=utf-8
    • :set fencs=utf-8,gbk,big5,euc-jp,utf-16le :set fenc=utf-8 enc=utf-8 tenc=utf-8
    • :set fencs=utf-8,gbk,big5,euc-jp,utf-16le :set fenc=utf-8 enc=utf-8 tenc=utf-8
    • :set fencs=utf-8,gbk,big5,euc-jp,utf-16le :set fenc=utf-8 enc=utf-8 tenc=utf-8 Terminal
    • :help encoding
    • 4. Key Mapping
    • :map :nmap :vmap :imap :smap :xmap ... more
    • :map (all) :nmap (normal mode) :vmap (visual mode) :imap (insert mode) :smap (select mode) :xmap (visual , select mode) ... more
    • :map (all) :nmap (normal mode) :vmap (visual mode) :imap (insert mode) :smap (select mode) :xmap (visual , select mode) ... more
    • :nmap <C-c><C-c> :!gcc -Wall % -o %:r.out<CR> Ctrl C Ctrl C GCC .out
    • Normal Mode Tab Shift-Tab nmap <tab> v> nmap <s-tab> v< vmap <tab> >gv vmap <s-tab> <gv
    • nmap <tab> v> nmap <s-tab> v< vmap <tab> >gv vmap <s-tab> <gv Visual/Select Mode Tab Shift-Tab
    • nmap <tab> v> nmap <s-tab> v< When mappings and menus are defined with the |:vmap| or |:vmenu| command they work vmap <tab> >gv both in Visual mode and in Select mode. When these are used in Select mode Vim vmap <s-tab> <gv automatically switches to Visual mode, so that the same behavior as in Visual mode is effective. Visual/Select Mode Tab Shift-Tab
    • imap <F2> <C-R>=strftime("%c")<CR> Insert Mode F2
    • cmap <c-a> <home> cmap <c-e> <end> cnoremap <c-b> <left> cnoremap <c-d> <del> cnoremap <c-f> <right> cnoremap <c-n> <down> cnoremap <c-p> <up> cnoremap <esc><c-b> <s-left> cnoremap <esc><c-f> <s-right> Command Mode Bash Key Binding
    • :h map.txt
    • 5. TEXT OBJECT
    • Text Object • word • string ⇛ action • paragraph (yank,delete,change ...etc) • block
    • Operator Mapping v|c|d i|a { | [ | ( |“ |‘ visual Region change Inner Object {} delete An Object [] () ““ Operator ‘‘
    • va{
    • function ( blah , blah ) ci( function ( ) function ( new_args )
    • “Hello World” di” “” “Hello New World”
    • 6. TAB PAPGES
    • :tabnew
    • :tabnew :tabedit path/to/file
    • :tabnew :tabedit path/to/file :tabfind path/to/file
    • :help tabpage.txt
    • 7. FOLDS
    • FOLD IS
    • Fold Methods
    • Fold Methods Syntax Fold
    • Fold Methods Syntax Fold :set foldmethod=syntax $VIMRUNTIME/syntax/*.vim
    • Perl : /opt/local/share/vim/vim72/syntax/perl.vim if exists("perl_want_scope_in_variables") “ ..... if exists("perl_extended_vars") “ ..... if exists("perl_fold") “ ..... .vimrc (Fold) let perl_fold = 1 let perl_extended_vars = 1 “ .... etc
    • Fold Methods Syntax Fold Marker Fold
    • Fold Methods Syntax Fold Marker Fold :set foldmethod=marker “{{{“ “}}}”
    • # fold this {{{ function do_something { echo “COSCUP”; } # }}}
    • Fold Methods Syntax Fold Marker Fold Indent Fold
    • Fold Methods Syntax Fold Marker Fold Indent Fold :set foldmethod=indent
    • Fold Methods Syntax Fold Marker Fold Indent Fold Manual Fold
    • :set foldmethod=manual zf
    • autocmd BufWinLeave *.* silent mkview autocmd BufWinEnter *.* silent loadview autocmd mkview , loadview ~/.vim/view/
    • Fold Methods Syntax Fold Marker Fold Indent Fold Manual Fold Expr Fold (Custom Fold Function)
    • :set foldexpr=MyFoldLevel(v:lnum)
    • Fold Methods Syntax Fold Marker Fold Indent Fold Manual Fold Expr Fold (Custom Fold Function) Diff Fold
    • 8.Modeline & FileType
    • ModeLine
    • " vim:fdm=marker:sw=2:ts=2:et:fdl=0: "============================ " Author: Cornelius < cornelius.howl{at}gmail{dot}com >
    • " vim:fdm=marker:sw=2:ts=2:et:fdl=0: "============================ " Author: Cornelius < cornelius.howl{at}gmail{dot}com > Marker Tab Fold (Level 0 )
    • FileType
    • ~/.vim/ftplugin/ruby.vim vimrc
    • ~/.vim/filetype.vim filetype.vim
    • 9. FORMATTING
    • :set equalprg=perltidy
    • :set equalprg=perltidy “=” perltidy
    • autocmd Filetype perl :set equalprg=perltidy autocmd equalprg
    • autocmd Filetype c :set equalprg=indent C GNU Ident
    • SQL $ cat bin/sql-beautify.pl #!/usr/bin/env perl use warnings; use strict; use SQL::Beautify; local $/; my $sql = SQL::Beautify->new( query => <STDIN> , spaces => 4 , break => "n" ); print $sql->beautify; autocmd Filetype sql :set equalprg=sql-beautify.pl SQL Filter
    • 10. QuickFix
    • :grep & :make
    • :grep [pattern] [filepath]
    • :grep [pattern] [filepath] grepprg ( vimgrep) grep QuickFix
    • QuickFix Window
    • :set grepprg=/path/to/grep grepprg ( VIM grep)
    • :make
    • :make makeprg ( make) Makefile. compiler output parser
    • :set makeprg=gmake makeprg ( make)
    • Result ⇛ QuickFix Window
    • :copen QuickFix Window
    • :cclose QuickFix Window
    • :cnext Result
    • :cprevious Result
    • QuickFix Window Toggle com! -bang -nargs=? QFix cal QFixToggle(<bang>0) fu! QFixToggle(forced) if exists("g:qfix_win") && a:forced == 0 cclose unlet g:qfix_win else copen 10 let g:qfix_win = bufnr("$") en endf nn <leader>q :QFix<cr>
    • QuickFix Window Toggle com! -bang -nargs=? QFix cal QFixToggle(<bang>0) fu! QFixToggle(forced) if exists("g:qfix_win") && a:forced == 0 cclose unlet g:qfix_win else copen 10 let g:qfix_win = bufnr("$") en endf nn <leader>q :QFix<cr> nmap “q” , <leader> “”
    • 11. Plugin
    • SnipMate TextMate
    • snippet cla class .. initialize .. end class ${1:`substitute(Filename(), '^.', 'u&', '')`} def initialize(${2:args}) ${3} end end
    • DBExt.vim Oracle, Sybase, MSSQL , MySQL, DBI
    • xml.vim XML
    • FuzzyFinder.vim Fuzzy/Partial pattern explorer
    • The_NERD_TREE.vim
    • The NERD Commenter
    • taglist.vim ctags macro , function , variable
    • cscope C
    • autocomplpop.vim
    • MRU most recently used
    • bufexplorer.vim Buffer Explorer
    • Rails.vim
    • git-vim
    • !
    • !
    • Vimana Vim script Manager
    • • Vimball • Archive File ( zip , rar ) • .vim file
    • POWERED BY Perl
    • CPAN Vimana $ cpan Vimana
    • $ vimana search xml
    • $ vimana search xml rrd.vim - Edit RRD data with Vim. qt.vim - tiny tool for the uic used in Qt from Trolltech syntax-for-xul - Highlighting for XML User interface Language. maven2.vim - Compiler plugin for maven2 .... skip
    • script $ vimana info xml.vim
    • xml.vim $ vimana install xml.vim
    • $ vimana install xml.vim $ vimana install rails.vim $ vimana install the-nerd-tree.vim $ vimana install taglist.vim $ vimana install snipmate $ vimana install fuzzyfinder.vim etc ... ALL Works
    • Git Repository http://github.com/c9s/Vimana/tree/master
    • ENJOY
    • Thank You
    • Demo ....
    • Q &A