t9md / atom-vim-mode-plus

vim-mode improved
https://atom.io/packages/vim-mode-plus
MIT License
1.4k stars 111 forks source link

Feature: Consistent Commands for Moving Over Folds between vmp and vim #1032

Open kiryph opened 6 years ago

kiryph commented 6 years ago

I want to use following mappings from vim in vmp as well :h [z:

MOVING OVER FOLDS ~
                            *[z*
[z      Move to the start of the current open fold.  If already at the
        start, move to the start of the fold that contains it.  If
        there is no containing fold, the command fails.
        When a count is used, repeats the command [count] times.

                            *]z*
]z      Move to the end of the current open fold.  If already at the
        end, move to the end of the fold that contains it.  If there
        is no containing fold, the command fails.
        When a count is used, repeats the command [count] times.

                            *zj*
zj      Move downwards to the start of the next fold.  A closed fold
        is counted as one fold.
        When a count is used, repeats the command [count] times.
        This command can be used after an |operator|.

                            *zk*
zk      Move upwards to the end of the previous fold.  A closed fold
        is counted as one fold.
        When a count is used, repeats the command [count] times.
        This command can be used after an |operator|.

In order to achieve this, my keymap.cson looks like:

'atom-text-editor.vim-mode-plus.normal-mode':

  '] ]' : 'vim-mode-plus:move-to-next-fold-start'
  '[ [' : 'vim-mode-plus:move-to-previous-fold-end'

  '[ z' : 'vim-mode-plus:move-to-previous-fold-start'
  '] z' : 'vim-mode-plus:move-to-next-fold-end'
  'z j' : 'vim-mode-plus:move-to-next-fold-start'
  'z k' : 'vim-mode-plus:move-to-previous-fold-end'

Consider following example python file

class Mapping:                              
    def __init__(self, iterable):
        pass

    def update(self, iterable):
        pass

    __update = update                       

class Reverse:                              
    def __init__(self, data):               
        self.data = data
        self.index = len(data)              

    def __iter__(self):                     
        return self                         

    def __next__(self):                     
        if self.index == 0:
            raise StopIteration
        self.index = self.index - 1
        return self.data[self.index]        

class MappingSubclass(Mapping):             

    def update(self, keys, values):
        pass

SimpylFold generates following folds in vim (see foldcolumn): screen shot 2018-02-19 at 18 07 30

Quite similar in Atom (except that there is another foldlevel for the if-clause): screen shot 2018-02-19 at 17 52 48

Differences between vmp and vim

Editor and system information

❯ atom --version
Atom    : 1.24.0
Electron: 1.6.16
Chrome  : 56.0.2924.87
Node    : 7.4.0

vim-mode-plus version: 1.28.1

OS: macOS Sierra 10.12.6

Check list

You have to check all before open issue.

t9md commented 6 years ago

I think I understand your motivation. What you want is to make vmp respect current indent-level to determine what's next/previous fold.

I once implemented it in that way(respecting indent level to determine enclosed fold), but not released it. I just find current behavior is useful for me. I partially agree that in-python and in-coffee-script, you requested behavior might be usefull. But I didn't choose differentiate behavior based on language.

Btw, don't you use vmp's default [ and ] which is mapped to move-up-to-edge, move-down-to-edge. Which is more general purpose and IMO well fit motion especially like python and coffee-script(significant indentation language).

kiryph commented 6 years ago

Thanks for your response. I think you got me right 😃.

Any chance you add two additional functions for people like me which provide this feature?

And thanks for your note about move-up-to-edge and move-down-to-edge. I will now use:

  '] ]' : 'vim-mode-plus:move-down-to-edge'
  '[ [' : 'vim-mode-plus:move-up-to-edge'