Wednesday, 24 June 2009
Vim: Including a register's contents in a substitute
"sub "fred" with contents of register "a" (Control R)
:s/fred/<c-r>a/g
or from the paste buffer
s/fred/<c-r>*/g
Here you actually do a Control-R.
It is often preferable to do use the following
:s/fred/\=@a/g : better alternative as register not displayed
unfortunately the \=@a must be at the beginning of replacement string
zzapper
:s/fred/<c-r>a/g
or from the paste buffer
s/fred/<c-r>*/g
Here you actually do a Control-R.
It is often preferable to do use the following
:s/fred/\=@a/g : better alternative as register not displayed
unfortunately the \=@a must be at the beginning of replacement string
zzapper
Labels: substitute, vim
Saturday, 20 June 2009
vim dat cat with yat or dat
I've been using the following HEAVILY recently as I've been working on some spaghetti html pages with mysql,php,Javascript and HTML sprinkled sometimes on the same line. The following help me to precisely "grab" the code I need to alter. I've been favoring VISUAL MODE as this confirms or otherwise that I've selected just what I intend.
Note how the "a" and "i" inner variants differ the 'i' grabs less than
the outer 'a'
vat,dat,yat,cat (visualize,delete,yank,change) a tag
ie dat will delete a whole table if cursor anywhere over < table>
ie yat will yank a whole table row if cursor over < tr>
vit,dit,yit,cit will empty a tag pair
da< just deletes a single tag
di< empties a tag
:help text-objects
seems to work with XML as well
Also quote based text objects (single line only though for some odd reason)
va"
da"
va'
da'
vi"
di"
vi'
di'
di<
and don't forget
di(
da{
etc
zzapper
Note how the "a" and "i" inner variants differ the 'i' grabs less than
the outer 'a'
vat,dat,yat,cat (visualize,delete,yank,change) a tag
ie dat will delete a whole table if cursor anywhere over < table>
ie yat will yank a whole table row if cursor over < tr>
vit,dit,yit,cit will empty a tag pair
da< just deletes a single tag
di< empties a tag
:help text-objects
seems to work with XML as well
Also quote based text objects (single line only though for some odd reason)
va"
da"
va'
da'
vi"
di"
vi'
di'
di<
and don't forget
di(
da{
etc
zzapper
Labels: html, text objects, vim, xml
Subscribe to Posts [Atom]