Saturday, May 22, 2010

Re: insert without using mappings/abbreviations

Hi,

On Fri, May 21, 2010 at 4:05 AM, Tim Chase <vim@tim.thechases.com> wrote:
> On 05/21/2010 05:29 AM, Roald de Vries wrote:
>>
>> I frequently want to insert text without using mappings and
>> abbreviations. How can I do that?
>
> While a mapping or abbreviation is the most common way to insert text, you
> can also stash things in your named registers "a"-"z", though you'd have to
> remember where you put each piece of content.  I do this occasionally, but
> my brain doesn't retain more than about 5 at a time, usually using a
> particular letter as a mnemonic.
>

Instead of using a register, you can insert the contents from a Vim variable.
For example, a Vim variable (mytxt) is defined as below:

let mytxt = "<HTML>\n"
let mytxt .= "<HEAD>\n"
let mytxt .= "<TITLE>Sample</TITLE>\n"
let mytxt .= "</HEAD>\n"
let mytxt .= "</HTML>"

You can insert the contents of the variable (mytxt), using CTRL-R =mytxt<Enter>
This will allow you define several templates and by using proper variable names,
you can easily remembers the template names.

You can set the variable using several different ways. You can use a list to set
multiple lines:

let mytxt = ["<HTML>", "<HEAD>", "<TITLE>Sample</TITLE>", "</HEAD>", "</HTML>"]

For more information about this, read

:help quote=

- Yegappan

> You can then insert the register's contents in various modes (for the
> examples below, I'll assume you've stashed the content in the "x" register,
> and denote control+R as "^R"):
>
>  Normal Mode:
>  "xp
>  "xP
>
>  Insert Mode:
>  ^Rx        " insert the text
>  ^R^Rx      " insert the text, even if it includes ctrl chars
>  ^R^Ox      " insert without autoindent
>  ^R^Px      " insert the text and fix the indent
>
> You can read about the details of the ^R modes at
>
>  :help i_CTRL-R
>
> and following.
>
> Another option that occurs to me is to record your insertions into a macro
> for playback that inserts the desired text; but that burns a register as
> well, can only be readily used in normal mode, and doesn't really gain
> anything in my estimation.
>
>> - I want to copy snippets from an HTML page, and paste it into vim
>
> So I'd copy the various snippets into named registers
>
>  :help registers
>
> and the paste in the desired snippet in one of the above-mentioned ways.
>
> -tim
>
>
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment