Repository navigation
Description
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
dantleech commentedon Jun 8, 2019
I chose to not include default mappings as:
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:
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 :)
camilledejoye commentedon Jun 8, 2019
I understand your opinion but for the pleasure of arguing
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 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.
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.
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
dantleech commentedon Jun 8, 2019
The least we can do is update and improve the documented defaults - I assume that this is where users get's their mappings?
camilledejoye commentedon Jun 8, 2019
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.
camilledejoye commentedon Jun 22, 2019
Doesn't seems we will have more specific feeds back than some thumbs up, soo what should we keep ?
<Plug>mappings for a better user experienceI would say:
dantleech commentedon Jun 22, 2019
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.
camilledejoye commentedon Jun 22, 2019
So no 4, but OK the rest ?
I will update the doc with the new mappings propositions and remove them from the plugin.
dantleech commentedon Jun 22, 2019
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?greg0ire commentedon Jul 20, 2019
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.camilledejoye commentedon Oct 13, 2019
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