-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'wrap' and other IDE-backed options #795
Add 'wrap' and other IDE-backed options #795
Conversation
39648d2
to
21599fb
Compare
I'm going to try again to add some more context without writing a massive essay 😁 Key points about the implementation:
|
21599fb
to
c896205
Compare
c896205
to
be61576
Compare
This PR is now ready for review. I've implemented all of the Vim options that have an equivalent IntelliJ implementation. The only exceptions are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the massive change! Generally, I'm ready to merge it, but there are a few things I'd like to discuss.
I left two comments on the code where I'm confused about how the explicit option set works with changing the options in IntelliJ UI.
Generally, I believe two approaches would be good in case the user explicitly sets the option while it conflicts with the other source (IJ or Vim). Let's assume, the user has set nu
in ~/.ideavimrc
and tries to untick the checkbox in IJ settings:
-
First way is to disable line numbers in all editors. Because if the user changes a setting like that, they must expect it to come into effect immediately. This would be confusing the the setting is changed, but in the editor nothing happened. The
~/.ideavimrc
file is not often modified, so it's easy to forget that it contains an explicitset nu
.
However, as I understand, this would be a bit complicated to implement because Vim still has an explicit value of thenumber
option. -
Second, probably more preferable way - avoid complications and disable IJ setting. We don't have this feature in the platform, but in case the user has an explicit
set nu
, we can turn off the setting in UI and add some tooltip explaining that this option is disabled because of Vim.
Generally, as I understand, this PR is mostly not about how the user actions in UI are processed, but how Vim processes the state of the IntelliJ settings regardless of how they are set. The chosen approach looks good to me, but I'm worried about the UX interaction for the user. I think this is confusing if the user changes an option in the settings and it doesn't change anything. Also, if you have explicit set nu
and you right-click line numbers -> appearance -> untick show line numbers, the line numbers will be disabled in the current editor but not in the other editors. And the general option in IJ setting will be disabled, what usually means that all editors should not have the line numbers.
Also, I can't quite catch it, how were you able to turn off update of the editors when the setting in IJ changes?...
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimOptionGroupBase.kt
Outdated
Show resolved
Hide resolved
The right click in the gutter for line numbers can be a little confusing, because it's only showing the global value of the setting, while the line numbers might be enabled by the View | Active Editor | Show Line Numbers local setting, which is what IdeaVim sets. It's better to test with the "show line numbers" options in Search Everywhere, because you can see what the global and effective values are for the current editor. If we use these actions, the current editor correctly updates when either local or global value is set, including when the Vim option has been explicitly set. Setting the local value is correctly reflected in the line numbers and the Vim option. Setting the global value will either set it to match the current local value (so no update) or also update the local value, and the line numbers and Vim option reflect this. However, setting the global option with these actions does not necessarily affect other open windows. If the Vim option has been explicitly set, or if the user has set View | Active Editor | Show Line Numbers, the local value is already set, so changes to the global value have no effect, and only the current editor's local value is reset by the platform. Setting the global option in the Settings dialog does not even update the current editor. Because of this, Vim options are essentially "opt-in". Once explicitly set, either in I was under the impression that there was no notification when a setting is changed, but I realise I was only looking at However, I'm not sure on expected behaviour. Vim doesn't have a way to reset local options in all open windows, and IntelliJ does not reset the local values in all open windows either. On the other hand, this PR makes use of local values more than the average IntelliJ user would, so perhaps the least surprising thing would be to treat it as though there were no local values and reset them. We might also be able to tell when a local IntelliJ value is not an explicitly local value, but a local value set to support IdeaVim. I'll have a think about how this could be implemented, and if the behaviour would be more intuitive. |
I've been thinking about the different approaches we can take when the global IntelliJ setting changes, and I think the best thing we can do is to start tracking when the option is set. If it's last set from If the value is set interactively, then you're explicitly saying you want it set locally, and changing the global IntelliJ value shouldn't modify this window/buffer. If the user sets the value from IntelliJ, with something like View | Active Editor, then they're setting it as a local value, and global changes won't modify it. IntelliJ currently works like this, and we won't be changing that. If the user sets it through IdeaVim, with Interactively sourcing or reloading I think I'm pretty happy with this. It feels like a good compromise between existing IntelliJ behaviour (explicitly set, don't override) and expected user behaviour (forgotten it's set in Also, what shall we do about this PR? Do you want to merge it and have these changes as a separate PR? I'm not likely to get this done before the end of next week. |
Yes, this sounds good to me, at least from the description. |
Okay. I'm going to rebase and force push before I do any more, fix that conflict, etc. |
a0ba209
to
9562133
Compare
Force pushed with new updates. IdeaVim updates the editor's local override of settings when a Vim option changes, instead of changing the persistent global value. When the user changes the global value of an IDE setting with the Settings dialog, IdeaVim will now reset the editor's local setting override if:
Essentially, if the user has explicitly and interactively set the effective value of a local option, or the local value of a global-local value, we respect that and do not modify the editor's local setting override. If the value was set during startup, then it's easy to consider that a global value, and it should be updated when the IDE's actual global value is changed. |
I've updated the |
5e83bd1
to
ce1327a
Compare
Fixes VIM-2748
Fixes VIM-267
Also supports overriding local-to-buffer options with IDE values, ensuring that changes to the option/IDE value are applied to all editors for the buffer. Fixes VIM-1310
IntelliJ ties the hard wrap right margin guide with the other visual guides, and it's not possible to show one without the other. In Vim, you can show the hard wrap margin by adding "+0" to 'colorcolumn', so in IdeaVim, we automatically add this.
While they are core Vim options, they are implemented by the host, not by the engine. If another host wants to support these options, they can add them in their implementation layer.
It now shows visual lines relative to the caret's visual line, rather than relative to the caret's logical line. This still isn't correct, and we should be showing the relative count of Vim logical lines (buffer lines + fold lines) but this matches movement so is more helpful
No tests, as I don't know how to test interaction with saving to disk
No tests, as I don't know how to test interaction with saving to disk
No tests, as I don't know how to test interaction with saving to disk
Fixes VIM-3110
String and number/toggle options have different and opposite behaviour for `:set {option}<` and `:setlocal {option}<`. This change matches Vim's behaviour.
Fixes VIM-3110
Options are not reset if they've been explicitly set by the user (e.g. `:set list` or _View | Active Editor | Show Whitespaces_). They are reset if they were explicitly set in `~/.ideavimrc`. Also bumps the IDE build number to 233.11799.241 in order to use EditorSettingsExternalizable.PropNames
ce1327a
to
aa512ad
Compare
This was epic, thank you! |
This PR adds support for various Vim options that map to IntelliJ settings, such as
'wrap'
and'textwidth'
. These options are implemented by the IntelliJ editor, rather than IdeaVim/vim-engine. It can also support options that are implemented by IdeaVim, but have equivalent settings in IntelliJ, such as'scrolloff'
.'wrap'
option to toggle soft wraps - VIM-1265'breakindent'
option to toggle indenting soft wraps to match the initial indent - VIM-2748'list'
option to toggle showing whitespace - VIM-267'cursorline'
option to toggle highlighting the current line'textwidth'
option. This is a local-to-buffer option and setting it will update the value in all open editors for the window. This Vim option maps to two IntelliJ settings - enabling wrap on type and the right margin value. It does not modify or reset the right margin when setting'textwidth'
to0
, mainly because the right margin visual guide is always displayed, and moving or hiding it would be unexpected for the user - VIM-1310'colorcolumn'
option to control visual guides. In Vim, you can add "+0" to the option to show the'textwidth'
value. IntelliJ ties the hard wrap margin visual guide to visibility of other visual guides, so we add this automatically. That is, if you:set colorcolumn=10,20,30
, then the result ofset colorcolumn?
will always becolorcolumn=10,20,30,+0
. You can disable visual guides, including the hard wrap right margin with:set colorcolumn=
.'number'
and'relativenumber'
to IntelliJ's number settings.'fileformat'
,'bomb'
and'fileencoding'
options. Vim will use these settings while saving, but IdeaVim will use IntelliJ's own actions to modify the file immediately.'scrolloff'
/'scrolljump'
and'sidescrolloff'
/'sidescroll'
to their equivalent IntelliJ settings - VIM-3110Other important changes:
'number'
and'relativenumber'
options have been moved out ofvim-engine
, and placed in the mainIdeaVIM
module. There isn't an IdeaVim implementation of these options, only an integration with a host implementation. Fleet will need to provide it's own integration, and also register the options itself.:set[local] {option}<
to reset an option back to the global value.Mapping an IntelliJ setting to a Vim option is intended to behave intuitively for the user. When setting the Vim option, the equivalent IntelliJ setting is only updated if the Vim option is being set as a result of
:set
or:setlocal
- when setting the default, the IntelliJ setting is not modified. When getting the option value for e.g.:set wrap?
, IdeaVim will always use the current IntelliJ setting value. This means Vim options are effectively opt-in. Unless the user explicitly sets the option through the command line or in~/.ideavimrc
, then the current IntelliJ setting is used as normal, including when IdeaVim uses current option values to initialise new windows.