I got it working, thanks Christian! /Oliver
On Fri, Aug 6, 2010 at 16:19, Christian Brabandt <[email protected]> wrote: > On Fri, August 6, 2010 8:31 am, Oliver wrote: >> Hello! >> >> I searched, :h-ed and asked in #vim on freenode, but nobody seemed to >> know a good way to use marks in :map without having a destructive >> effect on what was marked before in those registers. It is annoying to >> read scripts or :maps on the internet that say "will ruin your s >> register". The solution given in :h restore-position will do just >> that. >> >> Right now my solution is to map all these things to one register and >> never use it outside of these :maps, but that doesn't always work for >> plugins I've downloaded. The :h restore-position page says "For >> something more advanced see |winsaveview()| and |winrestview()|." This >> is apparently too advanced, as I've never seen it used. >> >> If nobody knows a solution for this, I think I'll send off a feature >> request for a special register dedicated for use inside :maps, a >> special mark set whenever a map is used, or an expanded :h >> restore-position page explaining how to use it in the context of >> simple :maps. I would prefer the first solution. >> >> If you are wonder why I can't use the `` mark, it is because my map >> does 99[(%v%= so I don't know how many jumps are executed. [( is a >> Slimv command which goes to the beginning of the () block the cursor >> is currently in, doing 99[( takes you to the outermost () block. > > So you want to use winsaveview() and winrestview(). You basically use them > like this: > > map <silent> <f2> :let a=winsaveview()<cr>...:call winrestview(a)<cr> > > The <silent> prevents, that your ex-commands will be echoed on the command > line and everything you'd like to do would be the ... part. I admit, this > can become very complex, so personally, I'd wrap everything in a function > which does everything (save and restore registers and positions and do > your action.) and simply call the function: > > map <silent> <f2> :call MyFunction()<cr> > > fun! MyFunction > :let a = winsaveview() > :let old_reg = @a " you could use getreg() > ... " Do your stuff here with register a > :call winrestview(a) > :let @a = old_reg " you could also use setreg() > :unlet a > endfun > > Additionally, if you want to keep your jump list, prefix every jump > command with the :keepjumps command. > > See :h keepjumps > :h map-silent > :h winsaveview() > :h winrestview() > :h setreg() > :h getreg() > :h getregtype() > > 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 > -- 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
