-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Read key remappings from .vimrc #3908
Conversation
I would love to see this feature go live! Is anyone with permission to merge going to say anything about this? I think this is a easy solution for something that a lot of people want |
At this point, I figure I should rebase the branch and replace the |
@rdnlsmith Sorry the team is so backed up on PRs. I'm definitely interested in this - will skim now and revisit later. |
@@ -743,6 +752,7 @@ | |||
"appdirectory": "0.1.0", | |||
"diff-match-patch": "1.0.4", | |||
"lodash": "4.17.15", | |||
"fs": "0.0.1-security", |
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.
As you mentioned, vscode.workspace.fs
seems to be preferred
package.json
Outdated
}, | ||
"vim.vimrcPath": { | ||
"type": "string", | ||
"description": "Path to a Vim configuration file. If unset, it will check for $HOME/.vimrc or $HOME/_vimrc" |
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.
What about $XDG_CONFIG_HOME/nvim/init.vim
? (https://neovim.io/doc/user/starting.html#vimrc)
Feel free to disagree, but my I think my preferred approach for this is have vim.vimrcPath
default to an empty string. Then note here that if it's unset, we fall back on default locations (like $HOME/.vimrc
, $HOME/_vimrc
, and $XDG_CONFIG_HOME/nvim/init.vim
) and then link to the part of the README
which lists these locations.
A nice-to-have would be a pop up the first time it defaults to a location (which is probably immediately after you enable this feature) that says something like "We couldn't find your .vimrc. Click here to set the location" or "We found a .vimrc here: /path/to/.vimrc. Click here to use it"
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.
What about
$XDG_CONFIG_HOME/nvim/init.vim
? (https://neovim.io/doc/user/starting.html#vimrc)
I skipped this initially because $XDG_CONFIG_HOME
wasn't set by default on my Ubuntu machine. But, I can certainly add it, plus the default paths from your link.
Feel free to disagree, but my I think my preferred approach for this is have
vim.vimrcPath
default to an empty string. Then note here that if it's unset, we fall back on default locations (like$HOME/.vimrc
,$HOME/_vimrc
, and$XDG_CONFIG_HOME/nvim/init.vim
) and then link to the part of theREADME
which lists these locations.
I'm not sure I understand how this is different from what I did?
A nice-to-have would be a pop up the first time it defaults to a location (which is probably immediately after you enable this feature) that says something like "We couldn't find your .vimrc. Click here to set the location" or "We found a .vimrc here: /path/to/.vimrc. Click here to use it"
I like this idea! I'll see what I can do.
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.
I'm not sure I understand how this is different from what I did?
Sorry about that - I think we should support more default locations and list them externally (with a link in the description).
@J-Fields Do you prefer |
Up to you |
|
src/configuration/vimrc.ts
Outdated
|
||
// Don't override a mapping present in settings.json; those are more specific to VSCodeVim. | ||
if (!collection.some(r => _.isEqual(r.before, mapping!.keyRemapping.before))) { | ||
collection.push(mapping.keyRemapping); |
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.
What if duplicates are added? What if there is a malformed remapping -- can we have these settings undergo src/configuration/validators/remappingValidator.ts
?
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.
If things go wrong, how do users debug this?
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.
Actually, I don't think it's possible that a bad remapping could be generated, based on what's currently being validated in remappingValidator
. That said, remappings from .vimrc are added to the config before the config is validated.
for (const line of lines) { | ||
VimrcImpl.tryKeyRemapping(configuration, line); | ||
} | ||
} |
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.
Should we save the updated vscodevim configuration? Otherwise, we'll need to do this re-syncing every time vscode is launched.
If i update my vimrc, I'll need to re-launch vscode? Is that what most users will expect? Changes to the vscodevim settings on the otherhand don't require a restart.
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.
We could re-evaluate the vimrc if the user saves it from VSCode. We could also have a "source" command to manually re-evaluate
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.
Thanks for your PR 🎆
@rdnlsmith it doesn't matter. we'll squash when we merge the PR :) |
Let us know when the PR is ready for review again. |
Read key remapping commands from $HOME/.vimrc, $HOME/_vimrc, or a user-specified Vim configuration file. For each, build an IKeyRemapping object and append it to the appropriate collection, _if_ doing so will not override a remapping specified in the VS Code settings. Partially addresses #463. This implementation borrows heavily from Sheepolution/vimrc-to-json.
@jpoon I've fixed most of the issues that were brought up. Another round of review would be great when you get the chance. |
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.
We should add some docs that is specifically for key mappings in the .vimrc
(ie. not everything)
import { vimrcKeyRemappingBuilder } from '../../src/configuration/vimrcKeyRemappingBuilder'; | ||
|
||
suite('VimrcKeyRemappingBuilder', () => { | ||
test('Build IKeyRemapping objects from .vimrc lines', () => { |
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.
maybe a test case with a multi-line vimrc? and with other options that are ignored?
@J-Fields Hey, I'm sorry I never got back to this—it's been a busy month+ and time got away from me. I'm glad to see that you're fixing it up! |
No worries @rdnlsmith, thanks for getting the ball rolling on this feature! |
README.md currently says:
With this change we can remove this right? And perhaps add a small section on how to let it read your .vimrc file. |
@Sheepolution Yeah, there are still a few small changes I need to make, thanks for pointing that out. |
Travis tests have failedHey @rdnlsmith, Node.js: 8if [[ $(git diff-index HEAD -- *.js *.ts *.md) ]]; then git diff; echo "Prettier Failed. Run `gulp forceprettier` and commit changes to resolve."; exit 1; fi
npm test
TravisBuddy Request Identifier: eec554a0-0353-11ea-86a0-93c38a831c21 |
What this PR does / why we need it:
Reads key remapping commands from $HOME/.vimrc, $HOME/_vimrc, or a user-specified Vim configuration file. For each, builds an IKeyRemapping object and appends it to the appropriate collection, if doing so will not override a remapping specified in the VS Code settings.
Which issue(s) this PR fixes
Partially addresses #463.
Special notes for your reviewer:
This implementation borrows heavily from Sheepolution/vimrc-to-json.
I haven't done much with node or TypeScript before this, so apologies in advance if I've made any "obvious" mistakes.