Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Not an editor command ":nHead" #1

Open
HaleTom opened this issue Jan 23, 2022 · 22 comments
Open

Not an editor command ":nHead" #1

HaleTom opened this issue Jan 23, 2022 · 22 comments

Comments

@HaleTom
Copy link

HaleTom commented Jan 23, 2022

I've got the .obsidian.vimrc lines:

nmap [[ :pHead
nmap ]] :nHead

When I type ]], I see:

Not an editor command ":nHead"

This plugin is installed and enabled through Obsidian's settings. v0.0.1

How would I go about debugging this?

@hhhapz
Copy link
Owner

hhhapz commented Jan 23, 2022

I think this problem stems from Obsidian's code mirror version being updated, and causing the api used to create the commands to now be incorrect.

If you are interesting in solving the issue, I'd most likely look at the Vimrc plugin and see how they changed things with registration of commands, and emulate the changes to this plugin.

If not, I'll see if I can get to this some time soon :)

@huyz
Copy link

huyz commented Feb 16, 2022

Seems this is the crux of the changes needed: esm7/obsidian-vimrc-support@c7253f1#diff-564c860307257bfac9176f554a35aa858c350a59d75c0dcd0a5d63a480805bd0R76-R159

And then just a bunch of search and replace.

@HaleTom
Copy link
Author

HaleTom commented Feb 19, 2022

Revisiting this, is it just me or do any features of this plugin currently work?

Typing :g0 I get:

Not an editor command ":g0"

Cheers for the gj and gk mappings - they're super useful!

@hhhapz
Copy link
Owner

hhhapz commented Feb 19, 2022

When this plugin originally was released, commands worked well. However, at the moment, I don't use obsidian anymore, and I don't have enough time to fix this at the time being :(. Huyz has provided a nice reference that could be used to fixup this plugin.

@huyz
Copy link

huyz commented Feb 20, 2022

I guess I can take a crack at it

@huyz
Copy link

huyz commented Feb 20, 2022

I got most of it to work, but g0 and gHead don't work because I get goLineLeftSmart is not implemented and goLineRight is not implemented. I'm not familiar enough with CodeMirror to know why.

@HaleTom
Copy link
Author

HaleTom commented Feb 21, 2022

@huyz Thanks for giving it a good go with some improvements! Could they be merged in?

@huyz
Copy link

huyz commented Feb 21, 2022

I shouldn't say "most". I only got the [[ and ]] to work. g0 and gHead are busted. There's something messed up about Obsidian's CodeMirror and vim.js where versions seem mismatched: there's code that's invoking functions that don't exist in the app but do exist online in published code.
My guess is we'll have to wait for some updates to Obsidian's CodeMirror dependencies.
Anyway, what I've done doesn't help much so I can't merge that in.

@kemonprogrammer
Copy link

kemonprogrammer commented Jun 24, 2022

The author of the vimrc-support-plugin has added a file with a tutorial on how to achieve this: https://github.com/esm7/obsidian-vimrc-support/blob/master/JsSnippets.md

You need to

  1. Add the file mdHelpers.js in the vault folder (kinda annoying, because the file will always be displayed in the file explorer)
  2. Add the snippet to your vimrc file
  3. Activate "Support JS commands" in the vimrc plugin settings (and update the plugin before if you haven't)
  4. Reload obsidian

@apotenza92
Copy link

FYI I got around the annoying aspect of 1 by just putting it in my .obsidian folder and changing the exmap to /.obsidian/mdHelpers.js.

@huyz
Copy link

huyz commented Jul 10, 2022

Now if someone could also write a g0 and gHead equivalent using JS snippets, that would be great

@shreve
Copy link

shreve commented Mar 16, 2023

I'm not really concerned about getting [[ and ]] to work. I think they're already defined to work like gg and G. I was able to get what I really wanted out of this plugin inside just the vimrc though.

nmap j gj
nmap k gk
vmap j gj
vmap k gk
exmap 0 goLineLeftSmart
exmap $ goLineRight

@alythobani
Copy link
Collaborator

alythobani commented Apr 20, 2024

FWIW it looks like as of today, codemirror-vim now has g0, g^, and g$ implemented, so you can just directly remap your keys to those commands in your .obsidian.vimrc without any exmaps needed (for those, at least).

nnoremap 0 g^
nnoremap $ g$
nnoremap H g^
nnoremap L g$
nnoremap I g^i
nnoremap A g$a

(And goLineLeftSmart is no longer available, it looks like, but shouldn't be needed anymore)

@hhhapz
Copy link
Owner

hhhapz commented Apr 20, 2024

It seems this plugin is mostly obsolete, I don't use Obsidian anymore and haven't for a long time. If you'd like to update the README with more info/context regarding this, it would be more than welcome :)

@alythobani
Copy link
Collaborator

Hey @hhhapz :) sure happy to update things here.

I also did a little more digging and was able to get your plugin's implementation of pHead and pNext working with CM6 (just needed to use (window as any).CodeMirrorAdapter?.Vim) instead of CodeMirror.Vim). I figured it could still be nice for people to simply be able to install a plugin and have those commands available, rather than needing to write their own JS snippets and store them in their vaults.

So, your repo may not be obsolete, for that use case. But you don't need to maintain it if you don't want to anymore—we could either:

  • Add the fixed pHead / pNext functionality to this repo (and could also add other Obsidian-specific vim commands like moveDownSkipFold), and keep this repo active
  • Deprecate this repo, and I could either maintain a new fork of it, or see if @esm7 wants the commands to be exposed by his obsidian-vimrc-support plugin

Let me know if you'd prefer either one, I'm happy with anything

@hhhapz
Copy link
Owner

hhhapz commented Apr 22, 2024

I'm happy with anything, if you'd like to fork, that's fine with me, if you want commit access here, I'll be happy to give you that too.

@alythobani
Copy link
Collaborator

alythobani commented Apr 22, 2024

Okay cool, it could be simpler to just bring the changes into here, then. Other than I'm not quite sure how the release process works with the official Obsidian plugin directory, but briefly looking into it, it looks like I can maybe just do that through GitHub. Can look more into that when I get a chance :)

@esm7
Copy link

esm7 commented Apr 22, 2024

Hey @hhhapz :) sure happy to update things here.

I also did a little more digging and was able to get your plugin's implementation of pHead and pNext working with CM6 (just needed to use (window as any).CodeMirrorAdapter?.Vim) instead of CodeMirror.Vim). I figured it could still be nice for people to simply be able to install a plugin and have those commands available, rather than needing to write their own JS snippets and store them in their vaults.

So, your repo may not be obsolete, for that use case. But you don't need to maintain it if you don't want to anymore—we could either:

* Add the fixed `pHead` / `pNext` functionality to this repo (and could also add other Obsidian-specific vim commands like [`moveDownSkipFold`](https://github.com/esm7/obsidian-vimrc-support/blob/master/JsSnippets.md)), and keep this repo active

* Deprecate this repo, and I could either maintain a new fork of it, or see if @esm7 wants the commands to be exposed by his [obsidian-vimrc-support](https://github.com/esm7/obsidian-vimrc-support/) plugin

Let me know if you'd prefer either one, I'm happy with anything

I'm perfectly good with adding these to obsidian-vimrc-support, if you wish. Whatever you think would be better :)

@alythobani
Copy link
Collaborator

@esm7 Oh nice, yeah if you're happy to do that, I think that'd be best from a user perspective too, just needing to install a single plugin :)

@esm7
Copy link

esm7 commented Apr 22, 2024

Mind opening a pull request for that? It'll probably take me a couple of weeks to review, as I'll use the opportunity to also review other issues and release an updated version, but we can definitely get it done.

@alythobani
Copy link
Collaborator

Sure sounds good :) I'll work on writing that up

@alythobani
Copy link
Collaborator

Sorry for the delay here, got busy with some other stuff, but just put up a PR for obsidian-vimrc-support to provide these (and a couple other) motions/commands. If that looks good and gets merged, we can probably go ahead and deprecate this plugin

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants