SlideShare a Scribd company logo
Vim Script
Programming
Vim Script
             (c9s)



                     Fork Me on Github
                       http://github.com/c9s
• Programmable interface
 • vim script
 • Perl / Python / Ruby / Mzscheme ...
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
Prepare
Region Eval
http://gist.github.com/444528

* Press ‘V’ then select region
* Press ‘e’ to evaluate region
To run script

:source [filename]

:source %   # current file
Debugging

:messages

:set verbose=10 “ verbose mode

:verbose *command*
Help

section      :help *section*

 option    :help ‘option_name’

 mode        :help [icv]_.....

command   :help :command_name
Alias

• source => so
     :so
• function => func
     :func Foo(bar)
• endfunction => endf
     :endf
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
Variable Scope
• non-prefix = global
• g: global
• s: script
• b: buffer
• v: vim built-in
• a: function arguments
Variable Scope

• let var = “string”
• let g:var_global = “global”
• let s:var_script = “script”
• let b:var_buffer = “buffer”
Condition
if boo > 2

elseif str == “string”

elseif str =~ ‘[a-z]+’

endif
Looping
while running == 1
   echo “Run...”
endwhile

for i in [1,2,3,4]

endfor
Looping
for i in range(1,10)
   “ i = 1 ~ 10

endfor
Override    Function
           Uppercase
  fun! Test()
     .. blah
  endf
Override    Function
           Uppercase
  fun! Test()
     .. blah
  endf

  call Test()     “ no return value
Override        Function
               Uppercase
  fun! Test()
     .. blah
     return 3
  endf

  let ret = Test()


    Return 3
Function arguments
fun! Foo(bar)
     echo a:bar
endf

fun! Foo(...)
      echo a:000
      echo a:001
endf
Function arguments
fun! Foo(bar)
     echo a:bar
endf
                   non-modifiable
fun! Foo(...)
      echo a:000
      echo a:001
endf
Function arguments
fun! Foo(bar)
     echo a:bar
endf
                   non-modifiable
fun! Foo(...)
      echo a:000    count of args
      echo a:001
endf
Function arguments
fun! Foo(bar)
     echo a:bar
endf
                   non-modifiable
fun! Foo(...)
      echo a:000    count of args
      echo a:001
endf                arg1
Function Scope
fun! s:Foo()
endf           Script Scope

fun! g:Foo()
endf           Global Scope

fun! b:Foo()
endf           Buffer Scope
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
  () ...
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*
Built-in Function

• Buffer related: bufnr() , bufexists() , buflisted
  () , bufname() ... etc
• Window related: winbufnr(), bufwinnr(),
  winnr()
• Misc: getreg(), setreg(), system(), eventhandler
  () , getpid() ...
Autoload function
Define your library function:
    ~/.vim/autoload/foo.vim
                               fun! foo#blah()

                               endf

In your script:
     call foo#blah()
Command

com! -range DoWrite       :write


    flags   command name     execute
Command
Define line range for command:


        -range
        -range=%
        -range=N
        -count=N
Command
    Other options:

-bang
-bar
-register
-buffer
-complete=[type]
Command
Template arguments:

   <line1>,<line2>
   <count>
   <bang>
   <reg>
   <args>
   <f-args>
   <q-args>
   <lt>
Syntax

• syn list
• syn keyword [ID] ....
• syn match [ID] ....
• syn region [ID] ...
• hi [ID] [Attributes]
Runtime Directory
 /Users/c9s/.vim/
 |-- after
 |-- autoload
 |-- colors
 |-- doc
 |-- ftdetect
 |-- ftplugin
 |   |-- c
 |   |-- cabal
 |   |-- cg
         ....
 |-- indent
 |-- plugin
 |-- syntax
 |   |-- c
 |   |-- javascript
 |   `-- perl
Utilities

• vim-makefile
• vim-uploader
• Vimana
Vim Makefile

• make install
• make uninstall
• make link
• make dist
Thanks
http://github.com/c9s

More Related Content

What's hot (20)

PDF
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Steven Francia
 
PDF
Painless Data Storage with MongoDB & Go
Steven Francia
 
PPTX
x86
Wei-Bo Chen
 
PPT
Inheritance compiler support
Syed Zaid Irshad
 
ODP
DevChatt 2010 - *nix Cmd Line Kung Foo
brian_dailey
 
PDF
Having Fun Programming!
Aaron Patterson
 
PDF
Ruby 1.9
Wen-Tien Chang
 
PDF
Quick tour of PHP from inside
julien pauli
 
ODP
PHP5.5 is Here
julien pauli
 
PDF
node ffi
偉格 高
 
ODP
Programming Under Linux In Python
Marwan Osman
 
PPT
Unix Shell Scripting Basics
Dr.Ravi
 
PDF
Quick start bash script
Simon Su
 
PDF
Unleash your inner console cowboy
Kenneth Geisshirt
 
PDF
Learning Python from Data
Mosky Liu
 
KEY
Txjs
Peter Higgins
 
PDF
High Performance tDiary
Hiroshi SHIBATA
 
PPTX
Troubleshooting Puppet
Thomas Howard Uphill
 
PDF
Getting Started with Go
Steven Francia
 
PDF
Python utan-stodhjul-motorsag
niklal
 
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Steven Francia
 
Painless Data Storage with MongoDB & Go
Steven Francia
 
Inheritance compiler support
Syed Zaid Irshad
 
DevChatt 2010 - *nix Cmd Line Kung Foo
brian_dailey
 
Having Fun Programming!
Aaron Patterson
 
Ruby 1.9
Wen-Tien Chang
 
Quick tour of PHP from inside
julien pauli
 
PHP5.5 is Here
julien pauli
 
node ffi
偉格 高
 
Programming Under Linux In Python
Marwan Osman
 
Unix Shell Scripting Basics
Dr.Ravi
 
Quick start bash script
Simon Su
 
Unleash your inner console cowboy
Kenneth Geisshirt
 
Learning Python from Data
Mosky Liu
 
High Performance tDiary
Hiroshi SHIBATA
 
Troubleshooting Puppet
Thomas Howard Uphill
 
Getting Started with Go
Steven Francia
 
Python utan-stodhjul-motorsag
niklal
 

Viewers also liked (20)

PDF
digital marketing training in bangalore
Venus Tech Inc.
 
PDF
VIM入门与进阶
pan weizeng
 
PDF
SQL injection and SQLMap Introduction
Billy Yang
 
KEY
Vim week
RookieOne
 
PPT
SQLMAP Tool Usage - A Heads Up
Mindfire Solutions
 
PDF
Sql Injection - Vulnerability and Security
Sandip Chaudhari
 
PDF
Vim再入門
bleis tift
 
PDF
SQL injection exploitation internals
Bernardo Damele A. G.
 
PPTX
Vim survival guide
Ben McCormick
 
KEY
How to become a practical Vim user
Kana Natsuno
 
PDF
VIM for (PHP) Programmers
ZendCon
 
PPT
Advanced Topics On Sql Injection Protection
amiable_indian
 
PDF
Vim Rocks!
Kent Chen
 
PDF
sqlmap - security development in Python
Miroslav Stampar
 
PDF
Vim Hacks
Lin Yo-An
 
PDF
sqlmap - Under the Hood
Miroslav Stampar
 
PDF
Heuristic methods used in sqlmap
Miroslav Stampar
 
PDF
Sql injection with sqlmap
Herman Duarte
 
digital marketing training in bangalore
Venus Tech Inc.
 
VIM入门与进阶
pan weizeng
 
SQL injection and SQLMap Introduction
Billy Yang
 
Vim week
RookieOne
 
SQLMAP Tool Usage - A Heads Up
Mindfire Solutions
 
Sql Injection - Vulnerability and Security
Sandip Chaudhari
 
Vim再入門
bleis tift
 
SQL injection exploitation internals
Bernardo Damele A. G.
 
Vim survival guide
Ben McCormick
 
How to become a practical Vim user
Kana Natsuno
 
VIM for (PHP) Programmers
ZendCon
 
Advanced Topics On Sql Injection Protection
amiable_indian
 
Vim Rocks!
Kent Chen
 
sqlmap - security development in Python
Miroslav Stampar
 
Vim Hacks
Lin Yo-An
 
sqlmap - Under the Hood
Miroslav Stampar
 
Heuristic methods used in sqlmap
Miroslav Stampar
 
Sql injection with sqlmap
Herman Duarte
 
Ad

Similar to Vim Script Programming (20)

TXT
Sdl Basic
roberto viola
 
PDF
Vim Hacks
Vagner Rodrigues
 
PDF
Coding with Vim
Enzo Wang
 
PDF
vimshell made other shells legacy
ujihisa
 
PDF
Introduction to GNU Make Programming Language
Shih-Hsiang Lin
 
KEY
Start Vim script @Ujihisa.vim 2011/11/19
Akihiro Okuno
 
PDF
Unit VI
Bhavsingh Maloth
 
PDF
Programming in Linux Environment
Dongho Kang
 
PDF
Gnubs pres-foss-cdac-sem
Sagun Baijal
 
PDF
Gnubs-pres-foss-cdac-sem
Sagun Baijal
 
PDF
The Ring programming language version 1.9 book - Part 43 of 210
Mahmoud Samir Fayed
 
PPTX
Gun make
psychesnet Hsieh
 
PDF
Style guideshell
blaap
 
PDF
Vim and Python
Python Ireland
 
PPT
Linux operating system by Quontra Solutions
QUONTRASOLUTIONS
 
PDF
PerlScripting
Aureliano Bombarely
 
PDF
Command Line Tools
David Harris
 
PDF
Getting started erlang
Kwanzoo Dev
 
PDF
5_File_Handling_Commands__vi_editor_and_environment_variables
Gautam Raja
 
PDF
Marc’s (bio)perl course
Marc Logghe
 
Sdl Basic
roberto viola
 
Vim Hacks
Vagner Rodrigues
 
Coding with Vim
Enzo Wang
 
vimshell made other shells legacy
ujihisa
 
Introduction to GNU Make Programming Language
Shih-Hsiang Lin
 
Start Vim script @Ujihisa.vim 2011/11/19
Akihiro Okuno
 
Programming in Linux Environment
Dongho Kang
 
Gnubs pres-foss-cdac-sem
Sagun Baijal
 
Gnubs-pres-foss-cdac-sem
Sagun Baijal
 
The Ring programming language version 1.9 book - Part 43 of 210
Mahmoud Samir Fayed
 
Style guideshell
blaap
 
Vim and Python
Python Ireland
 
Linux operating system by Quontra Solutions
QUONTRASOLUTIONS
 
PerlScripting
Aureliano Bombarely
 
Command Line Tools
David Harris
 
Getting started erlang
Kwanzoo Dev
 
5_File_Handling_Commands__vi_editor_and_environment_variables
Gautam Raja
 
Marc’s (bio)perl course
Marc Logghe
 
Ad

More from Lin Yo-An (10)

PDF
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
PDF
Getting merged
Lin Yo-An
 
PDF
OSDC.TW - Gutscript for PHP haters
Lin Yo-An
 
PDF
OSDC.TW 2014 building popular open source projects
Lin Yo-An
 
PDF
Secret sauce of building php applications
Lin Yo-An
 
PDF
LazyRecord: The Fast ORM for PHP
Lin Yo-An
 
PDF
CPAN 模組二三事
Lin Yo-An
 
PDF
Vim Hacks (OSSF)
Lin Yo-An
 
PDF
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
 
PDF
Perl.Hacks.On.Vim
Lin Yo-An
 
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Getting merged
Lin Yo-An
 
OSDC.TW - Gutscript for PHP haters
Lin Yo-An
 
OSDC.TW 2014 building popular open source projects
Lin Yo-An
 
Secret sauce of building php applications
Lin Yo-An
 
LazyRecord: The Fast ORM for PHP
Lin Yo-An
 
CPAN 模組二三事
Lin Yo-An
 
Vim Hacks (OSSF)
Lin Yo-An
 
Perl.Hacks.On.Vim Perlchina
Lin Yo-An
 
Perl.Hacks.On.Vim
Lin Yo-An
 

Recently uploaded (20)

PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 

Vim Script Programming