Skip to content

[Vim] Handles motions and add mappings #772

Closed

Description

@camilledejoye

Phpactor doesn't provide any mapping.
Not all plugins should, but I think in this case it's would actually be better.
Plus, the actual functions from the vim plugin doesn't handle motions.
Which feels pretty bad, it's awkward to change the way I work when I want to use a functionality of phpactor thant the way I work with vim the rest of the time.

What I mean is that if I want to to extract an expression as a variable, it will feel more natural to use an operator followed by a motion to represent what to extract.

In that spirit I propose a little rework around the ExtractMethod and ExtractExpression of the vim plugin and some "standard" mappings.
As well as organizing the mapping on a buffer level and providing <Plug> mapping to the user so he can customize them.

This is what I did so far:
https://github.com/elythyr/phpactor/tree/mappings

The mappings are disabled by default.
A configuration variable is used to enable them.
Some mapping that overlaps with vim's mapping needs to be explicitly activated with another variable.

Function Mapping Modes Reason
phpactor#ExtractException cv Normal, Visual* Change into Variable
phpactor#ExtractMethod cv Normal, Visual* Change into Method
phpactor#ExtractConstant cc Normal* Change into Constant
phpactor#UseAdd yu Normal, Visual* Yank Use statement
phpactor#GotoDefinition <C-]> Normal* Phpactor replace tags system, shoudl use the same mappings for consistency
phpactor#GotoDefinitionVSplit <C-w>] Normal* Same

The modes with an * are the ones overlapping with vim.
I choose to use the c to represent the fact that we are changing the buffer.
But in visual mode they prevent to change a selection with the value of the next character of each mapping.
I think it's worth it since s make more sense to me in those cases but its a personal opinion.
The y is used for the import because we don't modify the buffer by changing anything around the cursor but by adding some new text.
The tags shortcut make sense to me, I'm used to them from my time before phpactor and I always have remap them since I use phpactor.

There is some other things with the commits, like providing a function to easily create a mapping.
The mappings are defined with an auto-command for each buffer with a php filetype.
So the mappings like <C-]> are still available, in the help window and other language for example.

Let me know what is your feeling about mappings, I'm open to suggestions of course.

Activity

  1. dantleech commented on Jun 8, 2019

    @dantleech
    Collaborator

    I chose to not include default mappings as:

    • I don't want a plugin to change VIM's behavior when it's loaded (I can see they're optional here)
    • I don't want the plugin to have an opinion.
    • Everybody has they're own preferences?

    We provide suggested defaults in the documentation. Is it quite likely that even if we did have mappings by default, that the user would need to read some documentation in anycase, and also they will need to modify their VIM RC to install Phpactor in the first place.

    So ... do we need defaults in the plugin? or:

    • Improve the installation instructions to better link to the default shortcuts?
    • Improve the shortcuts in the documentation? (we can ceratinly do this).

    For me personally, I just like to explicitly introduce key mappings, and it annoys me when plugins do it automatically (which I guess your suggestion would not do) - and I like that the user manually adds their own mappings without the plugin's help.

    But open to discussion :)

  2. camilledejoye commented on Jun 8, 2019

    @camilledejoye
    ContributorAuthor

    I understand your opinion but for the pleasure of arguing

    * I don't want a plugin to change VIM's behavior when it's loaded (I can see they're optional here)
    

    In most situations I agree with you, in the case of Phpactor I think it's tolerable.
    It's such an important part of our workflow, mappings are mandatory at this point.
    I can't imagine anyone playing around witch call phpactor#UseAdd() and all.
    For me Phpactor is more than just a plugin, it's an entire extension to Vim when I work in PHP.

    * I don't want the plugin to have an opinion.
    

    I will argue that the most important thing is that the user can still decide.
    As soon as I install a tool I know that I will need to configure it to my needs.
    And I think that not all Vim users have a good idea of what is Vim grammar, therefore it might also be the responsibility of the plugin to lead them on the right path.

    * Everybody has they're own preferences?
    

    Absolutely, but we can also agree that standards allow for so much more.
    For instance peer-programing, if everyone uses their own mapping it became really hard to do.
    If the plugin provide some reasonable mappings that everyone can agree on it's even better.
    I don't claim that my propositions are the bests, just a starting point.

    I like that the user manually adds their own mappings without the plugin's help.
    Unfortunately not all Vim users are willing to take the time to understand how mappings works.
    How many of them will just make global mappings that will disable vim functionalities, even in different filetypes, just because they are not aware of the possibilities ?
    I feel like we can help them by providing those mappings.
    Like the phpactor#mapping#map() function and g:phpactorCustomMappings variable.
    They can still do their own mappings but they don't have to handle all the <buffer> and filetype autocmd loading.

    It's indeed a sensitive subject and personal opinion is really important.
    I hope we will have more feedback about Phpactor users.

    A little bit of reading for curious people:
    http://vimcasts.org/blog/2014/02/follow-my-leader/
    AndrewRadev/splitjoin.vim#14

    That basically resume things to: mappings should not be a default in plugins, but really important one deserve a few

  3. dantleech commented on Jun 8, 2019

    @dantleech
    Collaborator

    And I think that not all Vim users have a good idea of what is Vim grammar, therefore it might also be the responsibility of the plugin to lead them on the right path.

    Absolutely, but we can also agree that standards allow for so much more.

    The least we can do is update and improve the documented defaults - I assume that this is where users get's their mappings?

  4. camilledejoye commented on Jun 8, 2019

    @camilledejoye
    ContributorAuthor

    Absolutely, I planned to updates the doc anyway once we would have figure out what we kept.
    But I'm still a developer so I'm really lazy and if I have to choose between copy/paste a bunch of mappings or copy paste one line to activate them I choose the latest.

    I think we can do both.
    Provide some defaults mappings for the most used functionalities and gave a way to activate them out of the box.
    And add some other in the documentation as an example.

  5. camilledejoye commented on Jun 22, 2019

    @camilledejoye
    ContributorAuthor

    Doesn't seems we will have more specific feeds back than some thumbs up, soo what should we keep ?

    1. The rework to handle motions
    2. The <Plug> mappings for a better user experience
    3. The helper functions to create/add mappings
    4. The default mappings

    I would say:

    N° Include in PR Reason(s)
    1 Yes It's just so much more convenient and in the Vim spirit
    2 Yes Again, going into the Vim direction and hiding some implementation details
    3 Yes Ensure mappings are enabled on buffers only, doesn't override anything if wanted, etc.
    4 Yes Not activated by default, will not disturb any user without his will
  6. dantleech commented on Jun 22, 2019

    @dantleech
    Collaborator

    My opinion: If the mapings are deactivated by default, the user has to enable them. I don't really see the difference in effort between copy-and-pasting the mappings explicitly, or switching a flag (both require reading the docs). But with a flag, the mappings are hidden in the plugin, whereas copy-pasting you can clearly see what the mappings are and customize them as you want.

  7. camilledejoye commented on Jun 22, 2019

    @camilledejoye
    ContributorAuthor

    So no 4, but OK the rest ?
    I will update the doc with the new mappings propositions and remove them from the plugin.

  8. dantleech commented on Jun 22, 2019

    @dantleech
    Collaborator

    If we remove the mappings from the PR, Then I don't currently understand the other functionalities in the branch (what does<Plug> do?), maybe open the PR to further the discussion?

  9. greg0ire commented on Jul 20, 2019

    @greg0ire
    Contributor

    Regarding phpactor#GotoDefinition, I don't think we should override the existing mapping because in some rare situations where phpactor fails, it can still be useful, for instance if an ancestor class is defined in a phar.

  10. camilledejoye commented on Oct 13, 2019

    @camilledejoye
    ContributorAuthor

    I close this issue since the mappings are not in the picture anymore.
    I opened a new PR to merge some work that will allow the use of motions inside vim for some functions: #823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions