About: Creating new text objects   Sponge Permalink

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

For example, to visually select a quoted string (with the quotes), type va". To change the entire contents of a () group (without changing the parentheses themselves), type ci(. See [help text-objects] for more details. Occasionally, however, you will come across a situation where what you want to act on is a well-defined object, but is not a Vim-defined text object. Examples of this include all text of the same indent level, or all text within a fold. Vim's excellent mapping tools allow you to simulate the behavior of text objects for behavior you define. vnoremap af :silent! normal! [zV]z

AttributesValues
rdfs:label
  • Creating new text objects
rdfs:comment
  • For example, to visually select a quoted string (with the quotes), type va". To change the entire contents of a () group (without changing the parentheses themselves), type ci(. See [help text-objects] for more details. Occasionally, however, you will come across a situation where what you want to act on is a well-defined object, but is not a Vim-defined text object. Examples of this include all text of the same indent level, or all text within a fold. Vim's excellent mapping tools allow you to simulate the behavior of text objects for behavior you define. vnoremap af :silent! normal! [zV]z
Version
  • 7(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1554(xsd:integer)
Category
  • Map
  • Scripting
Text
  • CountJump
  • textobj-user
Author
  • Fritzophrenic
Subpage
  • /200804
Complexity
  • intermediate
Created
  • 2008(xsd:integer)
ID
  • 1555(xsd:integer)
  • 2100(xsd:integer)
  • 3130(xsd:integer)
NEXT
  • 1556(xsd:integer)
abstract
  • For example, to visually select a quoted string (with the quotes), type va". To change the entire contents of a () group (without changing the parentheses themselves), type ci(. See [help text-objects] for more details. Occasionally, however, you will come across a situation where what you want to act on is a well-defined object, but is not a Vim-defined text object. Examples of this include all text of the same indent level, or all text within a fold. Vim's excellent mapping tools allow you to simulate the behavior of text objects for behavior you define. A text object has two behaviors that need to be defined: visual mode, where it will select the appropriate text, and as a motion for an operator. So, you will need to use both a vmap and an omap to get the full text-object behavior. As a simple example, we will use a text object for operating on "a fold". We will start with visual mode, because it is simpler. We want to set the start of visual mode to the start of the fold, so we will first need to leave visual mode with (because will work no matter what the visual mode is) and then move the cursor to the start of the fold with [z. This command will fail if performed when already on the first line in a fold, so we need to wrap the command in :silent! normal! in order to continue the mapping even in the case of an error. Next, we need to re-enter visual mode. Folds are based on lines, so it makes most sense to enter visual line selection with V. The other option would be to use an mapping, and use the 'mode()' function to discover the visual mode, but this is inconsistent with the behavior of other text objects. Finally, we need to set the end of the visual selection to the end of the fold with ]z. The entire mapping looks like this (vnoremap is used to ensure we get the built-in functionality of all commands): vnoremap af :silent! normal! [zV]z Now that we have the visual mode mapping, we can actually use it to make our operator-pending mode mapping easier. Since a fold acts on entire lines, "a fold" should probably act on the entire fold (an "inner fold" is more open to interpretation...if it even makes sense). So, an easy way to accomplish an operation would be to visual line select the fold, then apply the operator. This can be done with: omap af :normal Vaf Here, we use omap and :normal without a bang (!) in order to make sure we use the remapped version of visual selection. With these two simple mappings, you will now be able to use af just like a normal text object to act on folded text! More complex applications such as an indent-level text object may require a function call to accomplish, but the concept is the same. Map an appropriate visual mapping, and if possible, use it to simplify the operator mapping.
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