On 2009-12-10, Tim Johnson wrote:
> Let's say I select some text in vim using visual mode, and I want to
> place a '/*' at the beginning of the selected text and I want to to
> place a '*/' at the end of the selected text.
>
> Were there any existing scripts to do that, I'd love to be pointed
> to them, or to those scripts who might serve as relevant examples,
> otherwise pointers to vim and other documentation would be
> appreciated.
Here are some ideas. If the selected text is all on one line, you
can execute the following key strokes:
s/* <C-R>- */<Esc>
where <C-R> and <Esc> mean the single keys Ctrl-R and Esc,
respectively. That substitutes the selected text (s) with the
string "/* " followed by the contents of the - register, which
contains the text just deleted by the s, and the string " */". See
:help quote-
:help quote1
You could also create a command using the `< and `> marks, which
mark the first and last character of the last visually-selected
region, so you could do something like
<Esc>`<i/* <Esc>`>a */<Esc>
to insert "/* " before the first character of the region and append
" */" after the last character of the region. See
:help `<
:help `>
You can, of course, map those key sequences to a function key or
whatever as you see fit.
HTH,
Gary
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php