Friday, May 11, 2012

Re: Toggle paste and nonu in one keystroke

Hi Dotan!

On Fr, 11 Mai 2012, Dotan Cohen wrote:

> Hi all, I am trying to write a function that will toggle the states
> "paste && nonu" and "nopaste && nu". I cobbled a few things together
> but although I figured this would be easy, it is eluding me. I need
> some sort of persistent variable to test state mode. I also need it to
> work in both Insert and Normal modes.
>
> noremap <F2> PasteMode()
> function! PasteMode()
> if exists(SOME_TYPE_OF_PERSISTENT_VARIABLE)
> unset PERSISTENT_VARIABLE
> set nopaste
> set nu
> else
> set PERSISTENT_VARIABLE
> set paste
> set nonu
> endif
> endfunction
>
> Thanks in advance for any advice.

This is way too complicated, :set allows to toggle values by itself
(:h :set-!), so this should work:

:nnoremap <f2> :set nu! paste!<cr>

regards,
Christian
--
Aller Größe Keim, er heißt Entsagung.
-- Theodor Fontane

--
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: