Re: Altering and Restoring Options
- On 2008-02-13, crjjrc <crjjrc@...> wrote:
> Hi. I've got a function defined in my .vimrc that automaticallyAnother way to avoid the automatic insertion of the comment leader
> inserts some lines of text. It enters insert mode by means of "normal
> o" and usually works great. The only glitch occurs when the cursor is
> on a commented line, which causes the line opened below it to start
> with a comment character, which I want to suppress.
> The workaround I've found is to temporarily blank the comments option:
> " We don't want any comment characters carrying to the next line,
> " turn comments off temporarily. We'll need to restore the value
> " done.
> let prev_comments=&comments
> set comments=
> normal o
> [ do the rest of the function ]
> " RHS can't have unescaped spaces.
> execute "set comments=" . escape(prev_comments, ' ')
> The part I don't like is that last line. I need prev_comments to be
> evaluated, so I have to use execute. But the value of the comments
> option might contain spaces, so I need to escape them.
> Is there a better way to do this? The essential thing I need to do is
> temporarily alter an option and then restore its value, which may or
> may not be the default value. Thanks for any ideas.
would be to use the :put command to add your lines instead of
entering insert mode.
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php