How to copy with vim mode?

I don’t think this is working.
At least not on my system, for me it only works when I use the context menu to copy/paste.
Tested it both in Insert and Normal mode.
Edit: Actually pasting works, copying doesn’t.

What doesn’t work?

I just saw your edit. You are saying that copying doesn’t work at all for you, in Insert Mode?

Also, if you reply, please make sure to use the correct terms so everything can be clear. Regular copying is called Copy. In Vim, it is called Yanking, and it goes to Vim registers, not to your system clipboard. (In Obsidian, as of now.)

3 posts were split to a new topic: Copying by hotkey doesn’t work when Vim plugin enabled

hey guys any updates or workaround on this?

No. As far as I know, there have been no changes to any features with regards to the Vim bindings in Obsidian.

As far as I can tell, it is simply provided through Code Mirror’s Vim bindings, and that is not being developed on the Code Mirror side.

The workaround right now - if you want to use your system clipboard - is to use Copy, rather than Yanking. You can Copy just fine in Normal Mode, and it copies to the system clipboard. You can even Copy when using a Visual selection in Vim mode.


I’ll say it again to be clear: If you are actually having trouble Copying (Ctrl-C), please specifically say so. Copying (Ctrl-C) should work. Yanking (y, etc.) will not go to the system clipboard. Copying should.

1 Like

got you, thanks for the help. @rigmarole I just found this excellent workaround

it works great but of course needs to be done everytime obsidian restarts
Here’s what I’m doing in case anyone else find it useful:

  1. Open Inspector (linux/windows shortcut) ctrl+shift+i

  2. Click on “console” tab

  3. Paste the following code CodeMirror.Vim.unmap('<C-c>')

That’s it

Since this needs to be done everytime you restart obsidian. I’m setting up a text expander shortcuts so that it’s easy to set up every time

hope it helps!

5 Likes

Are you saying that Ctrl-C does not work for you in Vim Normal mode? It does for me, by default without any workaround. (MacOS, every version of Obsidian I’ve tested.)

No one has said specifically yet, so I’ll ask again for emphasis: @santi Does Ctrl-C copy not work for you in Vim Normal mode?

(Maybe we’re working off different assumptions if it only works in Mac and no other OS?)

2 Likes

That’s interesting @rigmarole I didn’t consider that for some people it works without workarounds depending on their operating system.

I use obsidian in Linux (Manjaro) and ctrl+c in Vim normal Mode doesn’t work there, unless I do the workaround I mentioned above.

I just borrowed a mac to test it there, and it seems to work without the need of any workarounds.

I don’t have access to a Windows PC so I’m not sure what the situation is there.

The clipboard system in Mac is to my understanding very different to Windows and Linux, it’s good to know that it works for Mac users.

1 Like

@rigmarole
I’m using Windows 10 and Ctrl+C in Vim normal mode do not copy into the clipboard. What’s why workaround was made.

4 Likes

that makes sense, apparently it’s mostly a problem for Windows and Linux users.

For this @mrjackphil 's woraround works great, it’d just be a matter of waiting for the official API to be able to use it as a plug in

1 Like

Now that we have a Vim plugin, I’ve verified that adding unmap <C-c> to the .obsidian.vimrc file does the trick.

8 Likes

yes!!! that’s amazing I don’t know why I didn’t try that already. I was getting used to putting it in the console. This is perfect thanks for the tip, this just made my day!

@blairfrandeen I just realized that unmap <C-c> eventhough it works, it shows a constant annoying error at the end of the screen, when using regular obsidian shortcuts. such as “navigate back”

error-vimrc
any ideas on how to avoid the error from showing, while still making ctrl+c work like normal in obsidian with vim mode? Thanks!

I noticed this too, and had to remove the line that I stated above from my .vimrc file. My workaround for now is to simply type the command in normal mode when I start Obsidian–type : to get to the Vim console, and then unmap <C-c> to have the same effect.

I think the issue stems from the way the vim extension plugin is written, in that it seems to run the commands every time a note is brought into focus. I took a look at the source code but I’m not proficient enough in TypeScript or the CodeMirror Vim module to implement a more effective fix. Looks like you’ve already raised the issue on Github, thank you for doing that.

4 Likes

thanks for the help @blairfrandeen and for contributing to that GitHub issue.

Just for a quick summary for anyone else who might find this post and wants to achieve regular ctrl+c shortcut while in vim mode.

Everything works great now thanks to @esm90, the shortcut ctrl+c works without any error mesages from version 0.1.1 of the community plugin “vimrc support” by putting
unmap <C-c>
in the .obsidian.vimrc file which is a hidden file (dot file) located in your vault

here’s the github issue solved for anyone else who might find it useful.

Thank you so much @esm90 and @blairfrandeen

9 Likes

I’d like to add to what others have said, the specific behavior of Ctrl+C on Windows and Linux is that it does nothing in normal mode, and in insert mode it exits back to normal mode without copying to the system clipboard.

Even with the unmap <C-c> fix, copying is fixed in normal mode but in insert mode it still exits to normal mode without copying.

As an alternative (or addition) to unmap <C-c>, one can set clipboard=unnamed to yank to system clipboard. It still requires the obsidian-vimrc plugin.

3 Likes

Why I click Ctrl+C in insert mode, it ‘esc’ to normal mode, then there is nothing happend, it seems it has been intercepted.

1 Like

I find it pretty annoying that I can’t yank to the system clipboard with "*y. I don’t want to destroy my clipboard any time I yank, delete, etc. in codemirror. Anyone have a workaround for this?

4 Likes

Oddly enough, in Win 10, if you select some text in Obsidian, right click, and then choose “Copy” from the popup menu, that works perfectly well in Windows. It is only the keystroke that is screwed up. I suspect another workaround would be an Autohotkey macro that sent the right-click copy sequence to an Obsidian window. That ought to work in both insert and normal mode.

1 Like

I noticed that when I use Ctrl-C in vim mode it doesn’t do anything at all (Manjaro Linux). If I disable vim mode the shortcut works as expected.

However, selected text is still copied to the primary selection and can be pasted with the mouse-middle-click default in vim mode.