Vim: Use editor.formatOnPaste setting

Created on 4 Feb 2017  路  6Comments  路  Source: VSCodeVim/Vim

The new editor.formatOnPaste setting in vscode 1.9 works when pasting with ctrl-v with not in vim mode's p, which should use that setting too to automatically format when pasting.

help wanted kinfeature sizS

Most helpful comment

The formatOnPaste feature listens to browser's paste event however our p is not a real paste. That's why Code's native formatOnPaste doesn't kick in.

A proper solution is

  • Check editor.formatOnPaste when running p
  • If it's true, run format selection on p's pasted content.
  • Set correct final selection.

It's like re-implementing formatOnPaste again in Vim. Since I did that in Code, I'd like to leave this to anyone who wants to contribute :)

All 6 comments

The formatOnPaste feature listens to browser's paste event however our p is not a real paste. That's why Code's native formatOnPaste doesn't kick in.

A proper solution is

  • Check editor.formatOnPaste when running p
  • If it's true, run format selection on p's pasted content.
  • Set correct final selection.

It's like re-implementing formatOnPaste again in Vim. Since I did that in Code, I'd like to leave this to anyone who wants to contribute :)

@rebornix can't you just copy your implementation into VSCodeVim :wink:

@johnfn yeah of course. The only thing I'm not sure about is whether users (majority) want to have this feature in Vim.

That's a very good point actually. It's good to focus on issues with the most thumbs up.

Is there a workaround for this?

A proper solution is
Check editor.formatOnPaste when running p
If it's true, run format selection on p's pasted content.
Set correct final selection.

I'll mention that I prototyped this at one point and it wasn't a great experience. What we really want is VSCode to expose its formatOnPaste implementation, since then from our side it would be atomic. Still, a sort of ugly solution is better than none.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WangRongda picture WangRongda  路  3Comments

spinningarrow picture spinningarrow  路  3Comments

jaredly picture jaredly  路  3Comments

ACollectionOfAtoms picture ACollectionOfAtoms  路  3Comments

rajinder-yadav picture rajinder-yadav  路  3Comments