Your SlideShare is downloading. ×
0
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Vim Script Programming
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Vim Script Programming

12,623

Published on

Published in: Technology, Education
0 Comments
21 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
12,623
On Slideshare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
191
Comments
0
Likes
21
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Vim Script Programming Vim Script (c9s) Fork Me on Github http://github.com/c9s
  • 2. • Programmable interface • vim script • Perl / Python / Ruby / Mzscheme ...
  • 3. Outline - Vim Script • Comment • Looping • Variable • Command • Variable scope • Mapping • Special variable • Completion • Function • Autocommand • function scope • Autogroup • built-in function • Utility • Condition • vim-makefile
  • 4. Prepare
  • 5. Region Eval http://gist.github.com/444528 * Press ‘V’ then select region * Press ‘e’ to evaluate region
  • 6. To run script :source [filename] :source % # current file
  • 7. Debugging :messages :set verbose=10 “ verbose mode :verbose *command*
  • 8. Help section :help *section* option :help ‘option_name’ mode :help [icv]_..... command :help :command_name
  • 9. Alias • source => so :so • function => func :func Foo(bar) • endfunction => endf :endf
  • 10. Variable let variable = 123 let string = “string” let list = [1,2,3] let strlist = [ “bar” , “foo” ] let dict = { ‘phone’: ‘01234567’ } let dict.name = “Chopin” echo dict
  • 11. Variable Scope • non-prefix = global • g: global • s: script • b: buffer • v: vim built-in • a: function arguments
  • 12. Variable Scope • let var = “string” • let g:var_global = “global” • let s:var_script = “script” • let b:var_buffer = “buffer”
  • 13. Condition if boo > 2 elseif str == “string” elseif str =~ ‘[a-z]+’ endif
  • 14. Looping while running == 1 echo “Run...” endwhile for i in [1,2,3,4] endfor
  • 15. Looping for i in range(1,10) “ i = 1 ~ 10 endfor
  • 16. Override Function Uppercase fun! Test() .. blah endf
  • 17. Override Function Uppercase fun! Test() .. blah endf call Test() “ no return value
  • 18. Override Function Uppercase fun! Test() .. blah return 3 endf let ret = Test() Return 3
  • 19. Function arguments fun! Foo(bar) echo a:bar endf fun! Foo(...) echo a:000 echo a:001 endf
  • 20. Function arguments fun! Foo(bar) echo a:bar endf non-modifiable fun! Foo(...) echo a:000 echo a:001 endf
  • 21. Function arguments fun! Foo(bar) echo a:bar endf non-modifiable fun! Foo(...) echo a:000 count of args echo a:001 endf
  • 22. Function arguments fun! Foo(bar) echo a:bar endf non-modifiable fun! Foo(...) echo a:000 count of args echo a:001 endf arg1
  • 23. Function Scope fun! s:Foo() endf Script Scope fun! g:Foo() endf Global Scope fun! b:Foo() endf Buffer Scope
  • 24. Built-in Functions • List related: add() , remove() , filter() , map (), len() , sort(), empty(), join(), range() ... • Dictionary related: keys() , values() , has_key() , has_value(), extend() ... • String related: stridx(), strridx(), strlen(), substitute() , submatch(), strpart(), expand () ...
  • 25. Built-in Functions • List related: add() , remove() , filter() , map (), len() , sort(), empty(), join(), range() ... • Dictionary related: keys() , values() , has_key() , has_value(), extend() ... • String related: stridx(), strridx(), strlen(), substitute() , submatch(), strpart(), expand () ... *function-list*
  • 26. Built-in Function • Buffer related: bufnr() , bufexists() , buflisted () , bufname() ... etc • Window related: winbufnr(), bufwinnr(), winnr() • Misc: getreg(), setreg(), system(), eventhandler () , getpid() ...
  • 27. Autoload function Define your library function: ~/.vim/autoload/foo.vim fun! foo#blah() endf In your script: call foo#blah()
  • 28. Command com! -range DoWrite :write flags command name execute
  • 29. Command Define line range for command: -range -range=% -range=N -count=N
  • 30. Command Other options: -bang -bar -register -buffer -complete=[type]
  • 31. Command Template arguments: <line1>,<line2> <count> <bang> <reg> <args> <f-args> <q-args> <lt>
  • 32. Syntax • syn list • syn keyword [ID] .... • syn match [ID] .... • syn region [ID] ... • hi [ID] [Attributes]
  • 33. Runtime Directory /Users/c9s/.vim/ |-- after |-- autoload |-- colors |-- doc |-- ftdetect |-- ftplugin | |-- c | |-- cabal | |-- cg .... |-- indent |-- plugin |-- syntax | |-- c | |-- javascript | `-- perl
  • 34. Utilities • vim-makefile • vim-uploader • Vimana
  • 35. Vim Makefile • make install • make uninstall • make link • make dist
  • 36. Thanks http://github.com/c9s

×