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 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...
 
Scala in practice - 3 years later
Scala in practice - 3 years laterScala in practice - 3 years later
Scala in practice - 3 years later
 
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

CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 

Recently uploaded (20)

Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 

Vim Script Programming