About: Using parameterized snippet inserts   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

For example, I often use in my scripts a command sequence like this to optionally initialize some script local variable from a global one: let s:name = "value" if exists( "g:global_name" ) let s:name = g:global_name endif Here "name" is some variable name and "value" is the default value it will assume. Now, instead of explicitely hunting for "name" 4 times each time the snippet was inserted, I make them VPars variables by including them in "<| .. |>" delimiters, like this: let s:<|name|> = "<|value|>" if exists( "g:global_<|name|>" ) let s:<|name|> = g:global_<|name|> endif

AttributesValues
rdfs:label
  • Using parameterized snippet inserts
rdfs:comment
  • For example, I often use in my scripts a command sequence like this to optionally initialize some script local variable from a global one: let s:name = "value" if exists( "g:global_name" ) let s:name = g:global_name endif Here "name" is some variable name and "value" is the default value it will assume. Now, instead of explicitely hunting for "name" 4 times each time the snippet was inserted, I make them VPars variables by including them in "<| .. |>" delimiters, like this: let s:<|name|> = "<|value|>" if exists( "g:global_<|name|>" ) let s:<|name|> = g:global_<|name|> endif
Version
  • n/a
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1437(xsd:integer)
Category
  • Automated Text Insertion
Author
  • Bernd Pol
Complexity
  • intermediate
Created
  • 2006(xsd:integer)
ID
  • 1438(xsd:integer)
NEXT
  • 1439(xsd:integer)
Rating
  • 2(xsd:integer)
abstract
  • For example, I often use in my scripts a command sequence like this to optionally initialize some script local variable from a global one: let s:name = "value" if exists( "g:global_name" ) let s:name = g:global_name endif Here "name" is some variable name and "value" is the default value it will assume. Now, instead of explicitely hunting for "name" 4 times each time the snippet was inserted, I make them VPars variables by including them in "<| .. |>" delimiters, like this: let s:<|name|> = "<|value|>" if exists( "g:global_<|name|>" ) let s:<|name|> = g:global_<|name|> endif This snippet will then be saved in a suitable register (I use m for 'macro'). And in another register (the q register comes in very handy for this purpose), I put the following commands. Just type and then copy this sequence into the q register by "qy or equivalent: 0"mPV4j,jj This could as well be accomplished using the q keystroke recording function, which however would require a final to get back to command mode again in order to stop recording. Unfortunately, this gets recorded as well, causing Vim to later drop out of insert mode when executing the macro. Now all I have to do is to position the cursor at the line where the snippet is to be inserted, and then issue @q. Vim will insert the snippet and call VPars with the ",jj" shortcut. VPars in turn will stop at the first variable (# denotes the cursor): let s:<|#name|> = "<|value|>" and wait there, in insert mode already, for some replacement value. Just type it in and press the function key (or use the ,jj shortcut). VPars will substitute <|name|> for this text at all occurrences immediately, and then wait for a <|value|> replacement. Enter text, press , and VPars will after substitution put the cursor at the end of the snippet. There you may issue @q again and repeat the game as many times as wanted.
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software