SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
Text Expansion In Vim
These slides accompanied the 2013-09-17
NoVA Vim meetup and have since been
edited. They’re still a bit more of an outline,
but have a few gems of content.
@mattboehm github.com/mattboehm
Rationale
One of the most frequently cited reasons for
using vim is that it saves you time/keystrokes,
yet many people do not use any kind of input
expansion.
* type faster
* save keystrokes (prevent RSI)
* avoid common typos
imap
● instantly replaces characters typed
● works even in the middle of a word
● if you start typing characters that happen to
be part of a map, the text doesn’t display on
the screen til you finish the map or type a
differing character
● no easy way to undo?
● (you probably don’t want this for most cases)
iabbrev
● triggered when you finish typing a word and
hit space
● great for common strings like email
addresses and urls
● no easy way to un-expand? =(
Snippets
Many snippet plugins, but the two I’m most
familar with are:
* Snipmate: port of textmate’s snippet behavior
* Ultisnips: inspired by textmate/snipmate.
Added functionality, but requires vim compiled
with a modern python.
My Ultisnips Configuration
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsSnippetDirectories=["mysnippets"]
I recommend copying the stock snippets into a
separate directory and changing them to meet
your needs.
Quickly edit snippets
I used to have a snippet plugin installed, but never used it
because editing/listing them was too hard. Make editing
snippets effortless.
nnoremap <leader>vs :call g:EditMySnippets()
<CR>
function! g:EditMySnippets()
let ft = &ft
tabe ~/.vim/bundle/mbsnippets/mysnippets/
call search(ft)
endfunction
When i type ,vs this opens my snippet dir in NERDTree and
jumps to the first snippet containing the filetype of the
original file
Basic usage
snippet l "console.log"
console.log(“${1}”);
endsnippet
I type: l<tab>
Result: console.log(“|”)
snippet for "for (...) {...}"
for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) {
${3:$1[$2]}
};
endsnippet
I type “for<tab>” and get:
for (var i=0; i < Things.length; i++) {
Things[i]
};
“Things” is highlighted. As I type, it changes to what I’m
updating and all positions update in real time.
Visual replacement.
snippet if "if"
if (${1:condition}) {
${VISUAL}$0
}
endsnippet
I want to wrap code in an if block. I select it and
type <tab>if<tab>
Interpolation
snippet date "date"
the date is `date`
endsnippet
runs the bash date command and inserts its
result
snippet ver "pythonversion"
python version: `!p import sys;snip.rv=sys.version`
endsnippet
check out SirVer’s screencast for a better
example:http://ww.sirver.net/blog/2012/03/31/fourth-episode-of-ultisnips-screencast/
Zen Coding
Plugins exist for many editors
* zencoding (now emmet) is the initial popular
vim port
* sparkup adds some features and is what I
currently use
sparkup examples
body>div>em
becomes:
<body>
<div>
<em></em>
</div>
</body>
More Examples
#id
.classname
ul.classname
li*3>em
head>title<body
visit https://github.com/rstacruz/sparkup#examples for a better
presentation of examples
Sparkup Pros/Cons
● extended syntax
● jump between
insert locations
● not easily
configurable
● Main repo not
pathogen-friendly; I
use tristen’s branch
How can I productively use input
expansion?
Pick a small set of uses that come up a lot.
Practice using the expansions until they’re
ground into your brain then add more as
desired.
Do not look at the screen for feedback! You
need to be able to type your shortcuts with your
eyes closed while barely thinking about it.

Mais conteúdo relacionado

Mais procurados

Introduction to Vim, the text editor
Introduction to Vim, the text editorIntroduction to Vim, the text editor
Introduction to Vim, the text editorVysakh Sreenivasan
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneC4Media
 
Tmux quick intro
Tmux quick introTmux quick intro
Tmux quick introdantleech
 
What comments hide
What comments hideWhat comments hide
What comments hidePVS-Studio
 
Macro expansion techinical_report
Macro expansion techinical_reportMacro expansion techinical_report
Macro expansion techinical_reportSandun Perera
 
TechDays - IronRuby
TechDays - IronRubyTechDays - IronRuby
TechDays - IronRubyBen Hall
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introductionyangwm
 

Mais procurados (10)

Introduction to Vim, the text editor
Introduction to Vim, the text editorIntroduction to Vim, the text editor
Introduction to Vim, the text editor
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for Everyone
 
Tmux quick intro
Tmux quick introTmux quick intro
Tmux quick intro
 
What comments hide
What comments hideWhat comments hide
What comments hide
 
Macro expansion techinical_report
Macro expansion techinical_reportMacro expansion techinical_report
Macro expansion techinical_report
 
TechDays - IronRuby
TechDays - IronRubyTechDays - IronRuby
TechDays - IronRuby
 
Ruby.new @ VilniusRB
Ruby.new @ VilniusRBRuby.new @ VilniusRB
Ruby.new @ VilniusRB
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
Vim basic
Vim basicVim basic
Vim basic
 

Semelhante a Text expansion in vim

Eff Plsql
Eff PlsqlEff Plsql
Eff Plsqlafa reg
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfInSync2011
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 

Semelhante a Text expansion in vim (20)

Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt9
ppt9ppt9
ppt9
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 

Último

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...ScyllaDB
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfUK Journal
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
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...Skynet Technologies
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?Paolo Missier
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
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!.pdfSrushith Repakula
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 

Último (20)

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...
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
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...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
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
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 

Text expansion in vim

  • 1. Text Expansion In Vim These slides accompanied the 2013-09-17 NoVA Vim meetup and have since been edited. They’re still a bit more of an outline, but have a few gems of content. @mattboehm github.com/mattboehm
  • 2. Rationale One of the most frequently cited reasons for using vim is that it saves you time/keystrokes, yet many people do not use any kind of input expansion. * type faster * save keystrokes (prevent RSI) * avoid common typos
  • 3. imap ● instantly replaces characters typed ● works even in the middle of a word ● if you start typing characters that happen to be part of a map, the text doesn’t display on the screen til you finish the map or type a differing character ● no easy way to undo? ● (you probably don’t want this for most cases)
  • 4. iabbrev ● triggered when you finish typing a word and hit space ● great for common strings like email addresses and urls ● no easy way to un-expand? =(
  • 5. Snippets Many snippet plugins, but the two I’m most familar with are: * Snipmate: port of textmate’s snippet behavior * Ultisnips: inspired by textmate/snipmate. Added functionality, but requires vim compiled with a modern python.
  • 6. My Ultisnips Configuration let g:UltiSnipsExpandTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<tab>" let g:UltiSnipsJumpBackwardTrigger="<s-tab>" let g:UltiSnipsSnippetDirectories=["mysnippets"] I recommend copying the stock snippets into a separate directory and changing them to meet your needs.
  • 7. Quickly edit snippets I used to have a snippet plugin installed, but never used it because editing/listing them was too hard. Make editing snippets effortless. nnoremap <leader>vs :call g:EditMySnippets() <CR> function! g:EditMySnippets() let ft = &ft tabe ~/.vim/bundle/mbsnippets/mysnippets/ call search(ft) endfunction When i type ,vs this opens my snippet dir in NERDTree and jumps to the first snippet containing the filetype of the original file
  • 8. Basic usage snippet l "console.log" console.log(“${1}”); endsnippet I type: l<tab> Result: console.log(“|”)
  • 9. snippet for "for (...) {...}" for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) { ${3:$1[$2]} }; endsnippet I type “for<tab>” and get: for (var i=0; i < Things.length; i++) { Things[i] }; “Things” is highlighted. As I type, it changes to what I’m updating and all positions update in real time.
  • 10. Visual replacement. snippet if "if" if (${1:condition}) { ${VISUAL}$0 } endsnippet I want to wrap code in an if block. I select it and type <tab>if<tab>
  • 11. Interpolation snippet date "date" the date is `date` endsnippet runs the bash date command and inserts its result snippet ver "pythonversion" python version: `!p import sys;snip.rv=sys.version` endsnippet check out SirVer’s screencast for a better example:http://ww.sirver.net/blog/2012/03/31/fourth-episode-of-ultisnips-screencast/
  • 12. Zen Coding Plugins exist for many editors * zencoding (now emmet) is the initial popular vim port * sparkup adds some features and is what I currently use
  • 15. Sparkup Pros/Cons ● extended syntax ● jump between insert locations ● not easily configurable ● Main repo not pathogen-friendly; I use tristen’s branch
  • 16. How can I productively use input expansion? Pick a small set of uses that come up a lot. Practice using the expansions until they’re ground into your brain then add more as desired. Do not look at the screen for feedback! You need to be able to type your shortcuts with your eyes closed while barely thinking about it.