How to copy with vim mode?

How can I make copying and pasting with vim mode work? In my .vimrc I have set clipboard+=unnamedplus but obsidian doesn’t seem to be reading that file. How can I accomplish the same in obsidian?

7 Likes

To copy you can highlight the text and they hit ‘y.’ To paste you then hit ‘p.’ To yank a whole line hit ‘y’ twice, then ‘p’ again to paste. I think vim mode is written into Obsidian and doesn’t use vim, so it probably doesn’t use .vimrc.

I don’t know what’s all built into vim mode but you could try some of these other options:

1 Like

I suspect you can’t do that yet. When I have a selection, if I try to yank to the system clipboard, as soon as I hit y, it copies and deselects. So it doesn’t wait for a specific register.

But you can use Cmd-C and Cmd-V on MacOS. I assume Ctrl-C and Ctrl-V work as well on Windows. So when you are in Vim mode, and you make a visual selection (either with the mouse or with text object movements), Ctrl-C works just fine. But then you have to paste with Ctrl-V. The “put” register does not read what you Copy.

ie. Yanking and Copying and Putting and Pasting seem to be completely separate at the moment, but you are free to copy while you have a visual selection in Vim mode.

(As far as I have tested.)

What version of Obsidian are you on? In v0.8.2 yank and paste work fine. You have to be in escape mode, which is normal vim behavior.

@kbrede I believe he is talking about yanking to the system clipboard.

Ah, missed that part. I thought he was just trying to troubleshoot getting copy/paste to work.

Thank you very much for replying!

I am indeed asking how I can copy from Obsidian and into other applications and vice versa. Copying/yanking and pasting within Obsidian itself works as I expect, but I can’t copy/yank form Obsidian and paste that into my code editor.

Yes you can copy to other applications… No you can’t yank to other applications.

1 Like

Thanks again for replying. My question is then whether a setting that allows me to yank (in vim mode: y) and paste (in vim mode: p) using the system clipboard can be added to Obsidian. This setting should preferably work the same way as clipboard+=unnamedplus does with “normal” vim/nvim.

2 Likes

I’d suggest reposting this in Feature Requests so it doesn’t get lost. I’ll vote for it, for sure!

I’ve never used that .vimrc option you are mentioning, though I’m going to consider adding it. But it would make sense to have in Obsidian. And it would also be great to yank and put to the system clipboard like this:

"+y
"+d
"+p

That’s how I currently do it in Vim. Further, I set "+y to <leader>y and "+p to <leader>p

3 Likes

Did you figure out how to copy paste between obsidian and other apps?

Regular system copy/paste works normally. (Ctrl-C, Ctrl-V)

There is currently no way to yank from Vim Mode and make it go to your system clipboard.

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