About: Replace a builtin command using cabbrev   Sponge Permalink

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

This tip shows how to replace a built-in command using :cabbrev to automatically replace the existing command when it is typed. For example, you may want to change the behavior of a built-in command like :e. Or, you may make a common typo, like using :w1 instead of :w!. For whatever reason, if you want to change the behavior of a built-in command, you can't just use :command to override it, because user-defined commands must begin with a capital letter. Suppose you have a user-defined :E command that you want to use to override the default :e command. You could do the following: help ].

AttributesValues
rdfs:label
  • Replace a builtin command using cabbrev
rdfs:comment
  • This tip shows how to replace a built-in command using :cabbrev to automatically replace the existing command when it is typed. For example, you may want to change the behavior of a built-in command like :e. Or, you may make a common typo, like using :w1 instead of :w!. For whatever reason, if you want to change the behavior of a built-in command, you can't just use :command to override it, because user-defined commands must begin with a capital letter. Suppose you have a user-defined :E command that you want to use to override the default :e command. You could do the following: help ].
Version
  • n/a
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1282(xsd:integer)
Category
  • Usage
Text
  • CommandAlias
  • altercmd
  • ambicmd
  • cmdalias
Author
  • Yakov Lerner
Complexity
  • intermediate
Created
  • 2006(xsd:integer)
ID
  • 746(xsd:integer)
  • 1285(xsd:integer)
  • 2675(xsd:integer)
  • 3879(xsd:integer)
  • 4250(xsd:integer)
NEXT
  • 1286(xsd:integer)
Rating
  • 29(xsd:integer)
abstract
  • This tip shows how to replace a built-in command using :cabbrev to automatically replace the existing command when it is typed. For example, you may want to change the behavior of a built-in command like :e. Or, you may make a common typo, like using :w1 instead of :w!. For whatever reason, if you want to change the behavior of a built-in command, you can't just use :command to override it, because user-defined commands must begin with a capital letter. Suppose you have a user-defined :E command that you want to use to override the default :e command. You could do the following: :cabbrev e =(getcmdtype()==':' && getcmdpos()==1 ? 'E' : 'e') The (getcmdtype()==':' && getcmdpos()) makes sure the replacement happens only in the first column of the command line (i.e. not later in the line, where it is most likely NOT intended to be used as a command, and not on the search line, which is also affected by cabbrev). If you do this a lot, it would be useful to define a function to do it for you. Use this to quickly and easily define lowercase abbreviations for whatever command you want: function! CommandCabbr(abbreviation, expansion) execute 'cabbr ' . a:abbreviation . ' =getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"' endfunction command! -nargs=+ CommandCabbr call CommandCabbr() " Use it on itself to define a simpler abbreviation for itself. CommandCabbr ccab CommandCabbr This not only creates the function, but also provides the (lowercase!) command :ccab to define such abbreviations "on the fly". Note that because of the use of <f-args></f-args>, you will need to escape ("\ "), or use <space></space>, to include literal spaces in your expansion. This is explained in [help ].
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