How to copy with vim mode?

@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.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.