Hi
I'm developing a plugin which transforms <Space> into a useful key. (Cf. http://skota.org/spiff/vim/plugin/space.vim) The idea is that for some movement commands, such as searches, quickfix commands and some other motions, pressing <Space> will repeat the last movement, and <S-Space> (or <BS>) will do the reverse. Thus, after having pressed ']c', pressing <Space> will issue a ']c', and pressing <S-Space> will issue a '[c'. The only method I could think of to hook into these commands was to remap them all. I'm using <expr> mappings that call the hook function and then execute the original command. Apart from being a little tedious to implement, this method works very well. Now, as you all know, the otherwise useful option 'foldopen' is disabled when a command affected by 'foldopen' is part of a mapping. (This is true for all commands I've tested except 'f', 'F', 't' and 'T', for some reason.) Since space.vim remaps all commands it hooks into, it will also disable 'foldopen' for these commands. :h 'foldopen claims that you can "Add the |zv| command to the mapping to get the same effect." This is true in most cases, but if you are in Visual mode you have to use a trick. Consider an 'n' command moving into a closed fold. To emulate 'foldopen', you'd issue the command sequence 'nzv'. Very well, but with the way Visual mode works, the selection will cover the _whole_ fold you moved into. To work around this behaviour, it is possible to instead issue the command ':<C-u>normal gvnzv'. This command will, for some reason, open the fold before extending the visual selection to the search hit. The behaviour is reproducable, and applies to all normal commands I've tested. The example below uses ']m' instead of 'n': --- /* * 'vim -u NONE -U NONE -N' * :filetype on<CR> * :syntax on<CR> * :set ft=c<CR> * :set fdm=syntax<CR> * :set fdo-=block<CR> * zo * ]] * v]mzv * <Esc> * zc * [[ * v:<C-u>normal gv]mzv<CR> */ int bar(int foo) { if (foo) { return 0; } else { return 1; } } --- I suspect that this is not the intended behaviour, and that how it works when using :normal is wrong, even though I very much prefer that behaviour. I'm currently using gVim 7.2.77 for Win32, but I'm quite certain that this behaviour has not changed since then. It has also been confirmed with several users on #...@freenode. As a final note, I'll just conclude that manually emulating 'foldopen' in conjunction with Visual mode perfectly is, if not hard, then extremely difficult. I realise that there is a reason for disabling 'foldopen' in mappings, but I wish it were possible to override this behaviour. If anyone has suggestions on how to improve space.vim in this respect, feel free to mail me. In any case, try the plugin out; it rocks! Regards, Henrik. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
