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)

PDF
Ruby is an Acceptable Lisp
Astrails
 
PDF
Hamamatsu.swift @浜松IT合同勉強会
Takuya Ogawa
 
PDF
Vim Hacks
Vagner Rodrigues
 
PDF
Golang勉強会
Shin Sekaryo
 
PDF
The Swift Compiler and Standard Library
Santosh Rajan
 
PDF
Programming in Linux Environment
Dongho Kang
 
PDF
JRuby 9000 - Optimizing Above the JVM
Charles Nutter
 
PDF
Denis Lebedev, Swift
Yandex
 
PDF
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Thoughtworks
 
PDF
Scala in practice - 3 years later
patforna
 
PDF
An Introduction to Go
Cloudflare
 
PPTX
Gun make
psychesnet Hsieh
 
PPTX
Should i Go there
Shimi Bandiel
 
PDF
Unleash your inner console cowboy
Kenneth Geisshirt
 
PPTX
Server Side Swift
Chad Moone
 
PDF
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
GeeksLab Odessa
 
PDF
TDOH x 台科 pwn課程
Weber Tsai
 
PDF
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Puppet
 
PDF
scala-gopher: async implementation of CSP for scala
Ruslan Shevchenko
 
PDF
A Few of My Favorite (Python) Things
Michael Pirnat
 
Ruby is an Acceptable Lisp
Astrails
 
Hamamatsu.swift @浜松IT合同勉強会
Takuya Ogawa
 
Vim Hacks
Vagner Rodrigues
 
Golang勉強会
Shin Sekaryo
 
The Swift Compiler and Standard Library
Santosh Rajan
 
Programming in Linux Environment
Dongho Kang
 
JRuby 9000 - Optimizing Above the JVM
Charles Nutter
 
Denis Lebedev, Swift
Yandex
 
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Thoughtworks
 
Scala in practice - 3 years later
patforna
 
An Introduction to Go
Cloudflare
 
Should i Go there
Shimi Bandiel
 
Unleash your inner console cowboy
Kenneth Geisshirt
 
Server Side Swift
Chad Moone
 
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
GeeksLab Odessa
 
TDOH x 台科 pwn課程
Weber Tsai
 
Loops and Unicorns - The Future of the Puppet Language - PuppetConf 2013
Puppet
 
scala-gopher: async implementation of CSP for scala
Ruslan Shevchenko
 
A Few of My Favorite (Python) Things
Michael Pirnat
 
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
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 

Vim Script Programming