SlideShare a Scribd company logo
1 of 45
Download to read offline
OSSF




       Vim Hacks
                 (Cornelius)

       cornelius.howl@gmail.com
        http://c9s.blogspot.com/
        c9s@(plurk|twitter).com
Demo
To get Vim installed


• on Debian/Ubuntu: $ sudo apt-get install
  vim vim-gnome
• on MacOS: $ sudo port install vim vim-app
To compile your Vim
•   some ./configure options:

•     --with-features=tiny,normal,big,huge

•     --enable-perlinterp

•     --enable-rubyinterp

•     --enable-pythoninterp

•     --enable-multibyte

•     --enable-gui , --enable-cscope etc ...
To compile your Vim
$ ./configure --prefix=/opt/local 
     --enable-rubyinterp 
     --enable-perlinterp 
     --with-features=huge 
     --enable-multibyte 
     --enable-cscope 
     --enable-mzschemeinterp

$ make
$ make install
Basic Editing
             Normal Mode

ESC

      Command Mode (start with ‘:’)
          Insert Mode (i,o,a)
         Visual Mode (v,V,c-v)
Basic Editing
1. $ vim file
2. type h,j,k,l to move around.
3. type i to insert some text
4. <ESC> to go back normal mode
5. :w         to save file.
6. repeat 3-5 step
7. :wq
Edit your .vimrc file
$ vim ~/.vimrc

“iset nu<ESC>”

“:wq”

$ vim ~/.vimrc
Basic Options
set nocompatible
syntax on
filetype on
filetype plugin on
filetype indent on
set nu
set wrap
set shiftwidth=4
set tabstop=4
Basic GUI Options (.gvimrc)
set langmenu=en_US.utf-8
language mes en_US.UTF-8

if has('gui_mac') && has(‘gui_running’)
  set gfn=Monaco:h12
else
  "set gfn=Dejavu Sans Mono 9
  "set gfn=Andale Mono:h14
  set gfn=Bitstream Vera Sans Mono 10
endif
set guioptions+=c    “use console dialog instead
set guioptions-=e    “no gui tab
set guioptions-=T    “no Toolbar
set guioptions-=m    “no menu
set guioptions-=r    “no right-hand scrollbar

" downlaod a colorscheme you like to ~/.vim/colors/
" colors billw
Insert Mode

• iI
• aA
• oO
Visual Mode

•v
•V
• Ctrl-v
Basic Motion
C-d    (half-page down)
C-u    (half-page up)
C-f    (full-page down)
C-b    (full-page up)
gg     (goto the first line)
G      (goto the last line)
30gg
:10
10%
Basic Motion
b,w,e
B,W,E

f[x]    F[x]   ;   ,

( )        sentence
{ }        paragraph
[ ]        section
Buffer
$ vim file1 file2 file3
:bufdo tab split
:bufdo %s!pattern!string!g
:bufdo mkview
:[n]buffer
    :bn
    :bp
    :sb
  :buffers
 :buffers!
Window
Ctrl-W   v   Ctrl-W _
Ctrl-W   s   Ctrl-W |
Ctrl-W   h   Ctrl-W q
Ctrl-W   j
Ctrl-W   k   :wincmd w
Ctrl-W   l   :wincmd v
Ctrl-W   x   :wincmd s
Ctrl-W   w
For
 MacOS
nmap   <silent>   <D-->   :resize -5<CR>
nmap   <silent>   <D-=>   :resize +5<CR>
nmap   <silent>   <D-]>   :vertical resize +5<CR>
nmap   <silent>   <D-[>   :vertical resize -5<CR>



For Unix-like
set winaltkeys=yes

nmap   <silent>   <M-->   :resize -5<CR>
nmap   <silent>   <M-=>   :resize +5<CR>
nmap   <silent>   <M-]>   :vertical resize +5<CR>
nmap   <silent>   <M-[>   :vertical resize -5<CR>
Tabpage
:[n]tabdo   :tabnew
:tabn       :tabclose
:tabp       :tabfirst
:sb         :tabfind
:tabs       :tablast
:tabs!
nmap   tn :tabnew<CR>
nmap   tl gt
nmap   th gT
nmap   te :tabedit

“ split current buffer to tabpage
nnoremap <silent> ty :tab split<CR>
nnoremap <silent> td :exec 'tabedit '.expand('%')<CR>

“ close tab ( equal to <C-w>q )
nnoremap <silent> tq :tabclose<CR>

“ open new tab
nnoremap <silent> tn    :tabnew<CR>
“ open help in new page
nnoremap <silent> th :tab help<CR>

“ move tab
nnoremap <silent> tmh
   :exec ':tabmove ' . ( tabpagenr()-2 )<CR>
nnoremap <silent> tml
   :exec ':tabmove ' . tabpagenr()<CR>
Syntax
syntax.txt
Macro
*macro*
Mapping
map.txt
Autocommand
  autocmd.txt
Cases
Case 1: Copy & Paste


• copy text between terminal vim and gui
• Solution: fakeclip plugin
Case 2: Browsing File


• Solution: nerd tree plugin
• e to open nerd tree window
Case 3: Switching Buffer



• Solution: bufexplorer.zip
• be to open buffer explorer
Case 4: reformating code


• Problem: Coding Style Problem
• Solution: ‘equalprg’ option
• setlocal equalprg=/path/to/your/format_prg
Case 5: code snippets



• Problem:
• Solution:   snipmate.vim
Case 6: completion


• Problem:            C-x C-n
  completion
• Solution:   autocomplpop.vim
VimL
• variable
• function
• condition
• looping
• vim built-in functions
• command
• vim runtime path
• $VIM/
• $VIMRUNTIME/
See Also

• Vim.org
• Vim Tips wiki
• :tab help
Utilities


• Vimana
• VIM::Packager
Selected Help Section

• ‘C-editing’
• ‘completion’
• ‘tips.txt’
• ‘autocmd’
• ‘eval.txt’
vim script authors
      on github.com
• http://github.com/c9s
• http://github.com/kana
• http://github.com/mattn
• http://github.com/tpope
• etc...

More Related Content

What's hot

App-o-Lockalypse now!
App-o-Lockalypse now!App-o-Lockalypse now!
App-o-Lockalypse now!Oddvar Moe
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingDan Morrill
 
我在豆瓣使用Emacs
我在豆瓣使用Emacs我在豆瓣使用Emacs
我在豆瓣使用Emacs董 伟明
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Zyxware Technologies
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Toolschrismdp
 
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
 
Scroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォントScroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォントYuriko IKEDA
 

What's hot (20)

dplyr
dplyrdplyr
dplyr
 
Unix cheatsheet
Unix cheatsheetUnix cheatsheet
Unix cheatsheet
 
App-o-Lockalypse now!
App-o-Lockalypse now!App-o-Lockalypse now!
App-o-Lockalypse now!
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
 
我在豆瓣使用Emacs
我在豆瓣使用Emacs我在豆瓣使用Emacs
我在豆瓣使用Emacs
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
 
Groovy
GroovyGroovy
Groovy
 
Shell Script
Shell ScriptShell Script
Shell Script
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Tools
 
Os Secoske
Os SecoskeOs Secoske
Os Secoske
 
Unix shell scripting
Unix shell scriptingUnix shell scripting
Unix shell scripting
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
 
Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
Paexec -- distributed tasks over network or cpus
Paexec -- distributed tasks over network or cpusPaexec -- distributed tasks over network or cpus
Paexec -- distributed tasks over network or cpus
 
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
 
Scroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォントScroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォント
 
Iteration
IterationIteration
Iteration
 

Similar to Vim Hacks (OSSF)

Unix shell talk - RIT SSE
Unix shell talk - RIT SSEUnix shell talk - RIT SSE
Unix shell talk - RIT SSEMatt Mokary
 
Coding with Vim
Coding with VimCoding with Vim
Coding with VimEnzo Wang
 
我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具dennis zhuang
 
Terminal linux commands_ Fedora based
Terminal  linux commands_ Fedora basedTerminal  linux commands_ Fedora based
Terminal linux commands_ Fedora basedNavin Thapa
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidoraJinyuan Loh
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Ultimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationUltimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationJacobMenke1
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementLubomir Rintel
 
Basic command for linux
Basic command for linuxBasic command for linux
Basic command for linuxgt0ne
 
Adrian Mouat - Docker Tips and Tricks
 Adrian Mouat - Docker Tips and Tricks Adrian Mouat - Docker Tips and Tricks
Adrian Mouat - Docker Tips and TricksKevin Cross
 

Similar to Vim Hacks (OSSF) (20)

Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Unix shell talk - RIT SSE
Unix shell talk - RIT SSEUnix shell talk - RIT SSE
Unix shell talk - RIT SSE
 
screen and tmux
screen and tmuxscreen and tmux
screen and tmux
 
Coding with Vim
Coding with VimCoding with Vim
Coding with Vim
 
我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具
 
tmux
tmuxtmux
tmux
 
Kick my mouse away
Kick my mouse awayKick my mouse away
Kick my mouse away
 
Terminal linux commands_ Fedora based
Terminal  linux commands_ Fedora basedTerminal  linux commands_ Fedora based
Terminal linux commands_ Fedora based
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidora
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Gashuku Presen
Gashuku PresenGashuku Presen
Gashuku Presen
 
Gashuku Presen
Gashuku PresenGashuku Presen
Gashuku Presen
 
Ultimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationUltimate Unix Meetup Presentation
Ultimate Unix Meetup Presentation
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
 
Vim再入門
Vim再入門Vim再入門
Vim再入門
 
Basic command for linux
Basic command for linuxBasic command for linux
Basic command for linux
 
FreeBSD: Dev to Prod
FreeBSD: Dev to ProdFreeBSD: Dev to Prod
FreeBSD: Dev to Prod
 
Top ESXi command line v2.0
Top ESXi command line v2.0Top ESXi command line v2.0
Top ESXi command line v2.0
 
Adrian Mouat - Docker Tips and Tricks
 Adrian Mouat - Docker Tips and Tricks Adrian Mouat - Docker Tips and Tricks
Adrian Mouat - Docker Tips and Tricks
 
EC2
EC2EC2
EC2
 

More from Lin Yo-An

Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
Getting merged
Getting mergedGetting merged
Getting mergedLin Yo-An
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
OSDC.TW 2014 building popular open source projects
OSDC.TW 2014   building popular open source projectsOSDC.TW 2014   building popular open source projects
OSDC.TW 2014 building popular open source projectsLin Yo-An
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1Lin Yo-An
 
Secret sauce of building php applications
Secret sauce of building php applicationsSecret sauce of building php applications
Secret sauce of building php applicationsLin Yo-An
 
LazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLin Yo-An
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script ProgrammingLin Yo-An
 
CPAN 模組二三事
CPAN 模組二三事CPAN 模組二三事
CPAN 模組二三事Lin Yo-An
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaLin Yo-An
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 

More from Lin Yo-An (12)

Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Getting merged
Getting mergedGetting merged
Getting merged
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
OSDC.TW 2014 building popular open source projects
OSDC.TW 2014   building popular open source projectsOSDC.TW 2014   building popular open source projects
OSDC.TW 2014 building popular open source projects
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1
 
Secret sauce of building php applications
Secret sauce of building php applicationsSecret sauce of building php applications
Secret sauce of building php applications
 
LazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHP
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script Programming
 
CPAN 模組二三事
CPAN 模組二三事CPAN 模組二三事
CPAN 模組二三事
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 

Vim Hacks (OSSF)

  • 1. OSSF Vim Hacks (Cornelius) cornelius.howl@gmail.com http://c9s.blogspot.com/ c9s@(plurk|twitter).com
  • 3. To get Vim installed • on Debian/Ubuntu: $ sudo apt-get install vim vim-gnome • on MacOS: $ sudo port install vim vim-app
  • 4. To compile your Vim • some ./configure options: • --with-features=tiny,normal,big,huge • --enable-perlinterp • --enable-rubyinterp • --enable-pythoninterp • --enable-multibyte • --enable-gui , --enable-cscope etc ...
  • 5. To compile your Vim $ ./configure --prefix=/opt/local --enable-rubyinterp --enable-perlinterp --with-features=huge --enable-multibyte --enable-cscope --enable-mzschemeinterp $ make $ make install
  • 6. Basic Editing Normal Mode ESC Command Mode (start with ‘:’) Insert Mode (i,o,a) Visual Mode (v,V,c-v)
  • 7. Basic Editing 1. $ vim file 2. type h,j,k,l to move around. 3. type i to insert some text 4. <ESC> to go back normal mode 5. :w to save file. 6. repeat 3-5 step 7. :wq
  • 8. Edit your .vimrc file $ vim ~/.vimrc “iset nu<ESC>” “:wq” $ vim ~/.vimrc
  • 9. Basic Options set nocompatible syntax on filetype on filetype plugin on filetype indent on set nu set wrap set shiftwidth=4 set tabstop=4
  • 10. Basic GUI Options (.gvimrc) set langmenu=en_US.utf-8 language mes en_US.UTF-8 if has('gui_mac') && has(‘gui_running’) set gfn=Monaco:h12 else "set gfn=Dejavu Sans Mono 9 "set gfn=Andale Mono:h14 set gfn=Bitstream Vera Sans Mono 10 endif set guioptions+=c “use console dialog instead set guioptions-=e “no gui tab set guioptions-=T “no Toolbar set guioptions-=m “no menu set guioptions-=r “no right-hand scrollbar " downlaod a colorscheme you like to ~/.vim/colors/ " colors billw
  • 13. Basic Motion C-d (half-page down) C-u (half-page up) C-f (full-page down) C-b (full-page up) gg (goto the first line) G (goto the last line) 30gg :10 10%
  • 14. Basic Motion b,w,e B,W,E f[x] F[x] ; , ( ) sentence { } paragraph [ ] section
  • 16. $ vim file1 file2 file3
  • 20. :[n]buffer :bn :bp :sb :buffers :buffers!
  • 22. Ctrl-W v Ctrl-W _ Ctrl-W s Ctrl-W | Ctrl-W h Ctrl-W q Ctrl-W j Ctrl-W k :wincmd w Ctrl-W l :wincmd v Ctrl-W x :wincmd s Ctrl-W w
  • 23. For MacOS nmap <silent> <D--> :resize -5<CR> nmap <silent> <D-=> :resize +5<CR> nmap <silent> <D-]> :vertical resize +5<CR> nmap <silent> <D-[> :vertical resize -5<CR> For Unix-like set winaltkeys=yes nmap <silent> <M--> :resize -5<CR> nmap <silent> <M-=> :resize +5<CR> nmap <silent> <M-]> :vertical resize +5<CR> nmap <silent> <M-[> :vertical resize -5<CR>
  • 25. :[n]tabdo :tabnew :tabn :tabclose :tabp :tabfirst :sb :tabfind :tabs :tablast :tabs!
  • 26. nmap tn :tabnew<CR> nmap tl gt nmap th gT nmap te :tabedit “ split current buffer to tabpage nnoremap <silent> ty :tab split<CR> nnoremap <silent> td :exec 'tabedit '.expand('%')<CR> “ close tab ( equal to <C-w>q ) nnoremap <silent> tq :tabclose<CR> “ open new tab nnoremap <silent> tn :tabnew<CR>
  • 27. “ open help in new page nnoremap <silent> th :tab help<CR> “ move tab nnoremap <silent> tmh :exec ':tabmove ' . ( tabpagenr()-2 )<CR> nnoremap <silent> tml :exec ':tabmove ' . tabpagenr()<CR>
  • 32. Cases
  • 33. Case 1: Copy & Paste • copy text between terminal vim and gui • Solution: fakeclip plugin
  • 34. Case 2: Browsing File • Solution: nerd tree plugin • e to open nerd tree window
  • 35. Case 3: Switching Buffer • Solution: bufexplorer.zip • be to open buffer explorer
  • 36. Case 4: reformating code • Problem: Coding Style Problem • Solution: ‘equalprg’ option • setlocal equalprg=/path/to/your/format_prg
  • 37. Case 5: code snippets • Problem: • Solution: snipmate.vim
  • 38. Case 6: completion • Problem: C-x C-n completion • Solution: autocomplpop.vim
  • 39. VimL
  • 40. • variable • function • condition • looping • vim built-in functions • command
  • 41. • vim runtime path • $VIM/ • $VIMRUNTIME/
  • 42. See Also • Vim.org • Vim Tips wiki • :tab help
  • 44. Selected Help Section • ‘C-editing’ • ‘completion’ • ‘tips.txt’ • ‘autocmd’ • ‘eval.txt’
  • 45. vim script authors on github.com • http://github.com/c9s • http://github.com/kana • http://github.com/mattn • http://github.com/tpope • etc...