|
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. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- 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 |
|
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 |
|
On Fri, May 11, 2012 at 2:25 PM, Christian Brabandt <[hidden email]> wrote:
> This is way too complicated, :set allows to toggle values by itself > (:h :set-!), so this should work: > > :nnoremap <f2> :set nu! paste!<cr> > Thanks, Christian, that is very helpful! However I am having trouble with the Insert version. I am trying this code: :inoremap <F2> <Esc>:set nu! paste!<cr> However, when I press F2 in Insert mode I get the text <F2> inserted into the document! Also, I will have trouble with reentering Insert mode, because if I use "i" or "a" then I will have troubles at the end or beginning of text lines. Is there a workaround for that? Thanks! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- 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 |
|
Hi Dotan!
On Fr, 11 Mai 2012, Dotan Cohen wrote: > However I am having trouble with the Insert version. I am trying this code: > :inoremap <F2> <Esc>:set nu! paste!<cr> > > However, when I press F2 in Insert mode I get the text <F2> inserted > into the document! Well, by definition in paste mode, mappings aren't executed (:h 'paste') > Also, I will have trouble with reentering Insert mode, because if I > use "i" or "a" then I will have troubles at the end or beginning of > text lines. Is there a workaround for that? :h i_CTRL-\_CTRL-O regards, Christian -- 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 |
|
On Fri, May 11, 2012 at 2:58 PM, Christian Brabandt <[hidden email]> wrote:
>> However I am having trouble with the Insert version. I am trying this code: >> :inoremap <F2> <Esc>:set nu! paste!<cr> >> >> However, when I press F2 in Insert mode I get the text <F2> inserted >> into the document! > > Well, by definition in paste mode, mappings aren't executed (:h 'paste') > That makes perfect sense! Thanks. >> Also, I will have trouble with reentering Insert mode, because if I >> use "i" or "a" then I will have troubles at the end or beginning of >> text lines. Is there a workaround for that? > > :h i_CTRL-\_CTRL-O > Thanks, that is exactly what I need. Have a terrific weekend. Thank you for the advice! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- 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 |
|
Hi, Dotan Cohen wrote: > On Fri, May 11, 2012 at 2:58 PM, Christian Brabandt <[hidden email]> wrote: >>> However I am having trouble with the Insert version. I am trying this code: >>> :inoremap <F2> <Esc>:set nu! paste!<cr> >>> >>> However, when I press F2 in Insert mode I get the text <F2> inserted >>> into the document! >> >> Well, by definition in paste mode, mappings aren't executed (:h 'paste') >> > > That makes perfect sense! Thanks. have a look at :help 'pastetoggle' although this won't help you at resetting the 'number' option: :inoremap <F2> <Esc>:set nu! paste!<cr> :set pastetoggle=<F2> Regards, Jürgen -- Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin) -- 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 |
|
On Fri, May 11, 2012 at 3:09 PM, Jürgen Krämer <[hidden email]> wrote:
> have a look at > > :help 'pastetoggle' > > although this won't help you at resetting the 'number' option: > > :inoremap <F2> <Esc>:set nu! paste!<cr> > :set pastetoggle=<F2> > > Regards, > Jürgen > Thank you Jürgen. As you mention, though, that only solves half the issue! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- 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 |
| Powered by Nabble | Edit this page |
