SlideShare a Scribd company logo
1 of 36
Download to read offline
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

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
brian_dailey
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
niklal
 

What's hot (20)

Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
 
Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go Painless Data Storage with MongoDB & Go
Painless Data Storage with MongoDB & Go
 
x86
x86x86
x86
 
Inheritance compiler support
Inheritance compiler supportInheritance compiler support
Inheritance compiler support
 
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
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
node ffi
node ffinode ffi
node ffi
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
Txjs
TxjsTxjs
Txjs
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
Troubleshooting Puppet
Troubleshooting PuppetTroubleshooting Puppet
Troubleshooting Puppet
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with Go
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 

Viewers also liked

VIM入门与进阶
VIM入门与进阶VIM入门与进阶
VIM入门与进阶
pan weizeng
 
How to become a practical Vim user
How to become a practical Vim userHow to become a practical Vim user
How to become a practical Vim user
Kana Natsuno
 

Viewers also liked (20)

digital marketing training in bangalore
digital marketing training in bangaloredigital marketing training in bangalore
digital marketing training in bangalore
 
Sqlmap
SqlmapSqlmap
Sqlmap
 
VIM入门与进阶
VIM入门与进阶VIM入门与进阶
VIM入门与进阶
 
SQLmap
SQLmapSQLmap
SQLmap
 
SQL injection and SQLMap Introduction
SQL injection and SQLMap IntroductionSQL injection and SQLMap Introduction
SQL injection and SQLMap Introduction
 
Vim week
Vim weekVim week
Vim week
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads Up
 
Sql Injection - Vulnerability and Security
Sql Injection - Vulnerability and SecuritySql Injection - Vulnerability and Security
Sql Injection - Vulnerability and Security
 
Vim再入門
Vim再入門Vim再入門
Vim再入門
 
SQL injection exploitation internals
SQL injection exploitation internalsSQL injection exploitation internals
SQL injection exploitation internals
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
 
How to become a practical Vim user
How to become a practical Vim userHow to become a practical Vim user
How to become a practical Vim user
 
VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) Programmers
 
Advanced Topics On Sql Injection Protection
Advanced Topics On Sql Injection ProtectionAdvanced Topics On Sql Injection Protection
Advanced Topics On Sql Injection Protection
 
Vim Rocks!
Vim Rocks!Vim Rocks!
Vim Rocks!
 
sqlmap - security development in Python
sqlmap - security development in Pythonsqlmap - security development in Python
sqlmap - security development in Python
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
sqlmap - Under the Hood
sqlmap - Under the Hoodsqlmap - Under the Hood
sqlmap - Under the Hood
 
Heuristic methods used in sqlmap
Heuristic methods used in sqlmapHeuristic methods used in sqlmap
Heuristic methods used in sqlmap
 
Sql injection with sqlmap
Sql injection with sqlmapSql injection with sqlmap
Sql injection with sqlmap
 

Similar to Vim Script Programming

Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
Cloudflare
 

Similar to Vim Script Programming (20)

Ruby is an Acceptable Lisp
Ruby is an Acceptable LispRuby is an Acceptable Lisp
Ruby is an Acceptable Lisp
 
Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Golang勉強会
Golang勉強会Golang勉強会
Golang勉強会
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Scala in practice - 3 years later
Scala in practice - 3 years laterScala in practice - 3 years later
Scala in practice - 3 years later
 
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Gun make
Gun makeGun make
Gun make
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Server Side Swift
Server Side SwiftServer Side Swift
Server Side Swift
 
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 

More from Lin Yo-An (10)

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
 
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
 
CPAN 模組二三事
CPAN 模組二三事CPAN 模組二三事
CPAN 模組二三事
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)
 
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
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Vim Script Programming