Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-indent on paste #25260

Closed
pokliu opened this issue Apr 25, 2017 · 6 comments
Closed

Auto-indent on paste #25260

pokliu opened this issue Apr 25, 2017 · 6 comments
Assignees
Labels
editor-autoindent Editor auto indentation issues
Milestone

Comments

@pokliu
Copy link

pokliu commented Apr 25, 2017

  • VSCode Version: Code 1.11.2 (6eaebe3, 2017-04-13T08:03:11.395Z)
  • OS Version: Windows_NT ia32 6.1.7601
  • Extensions:
Extension Author Version
crane HvyIndustries 0.3.6
NodeAssertionSnippets jaymorrow 0.1.0
format-php Kasik96 1.1.2
php-docblocker neilbrayfield 0.4.2
laravel-blade onecentlin 1.8.1
laravel5-snippets onecentlin 1.3.4
upload wuwei 0.1.5

Steps to Reproduce:

1.Create a file named 'test.php', and type some code like this:
image

2.When I try to paste these selected multiline code to the first line of function 'test', it shows:
image


Why do not auto-indent except the first line of pasted codes?

@alexdima
Copy link
Member

fyi @rebornix

@alexdima alexdima added the feature-request Request for new features or functionality label Apr 25, 2017
@alexdima alexdima changed the title How to auto-indent for multiline code paste? Auto-indent on paste Apr 25, 2017
@alexdima alexdima added the editor-contrib Editor collection of extras label Apr 25, 2017
@alexdima alexdima added this to the Backlog milestone Apr 25, 2017
@CherryDT
Copy link

CherryDT commented Apr 26, 2017

@poklau123 About the "first line" question: You have copied the first line without the indention, but the second line with the indention, so of course the idention is unequal after pasting. To have it equal, you need to copy both lines with indention (e.g. by using the left border of the code window where the mouse cursor points right).

In general, though, I am also missing a way to auto-indent after paste. There have been various issues in GitHub about this before (see also #13945), and in January an option was added to do "Format on Paste" ("editor.formatOnPaste": true). However, I didn't want it to format on paste (including things other than just indenting), I wanted it only to indent, in a way similar to how Sublime Text does it on Ctrl+Shift+V.

My solution for now is the plugin Paste and Indent. I have changed the key bindings so that Ctrl+V does normal paste while Ctrl+Shift+V invokes pasteAndIndent.action. It does have a slightly different behavior from Sublime Text though (see rubymaniac/vscode-paste-and-indent#2): You have to set the cursor at the indention level which sould be the lowest indention you want for the pasted code, and then paste. It will not automatically determine the correct indention based on the surrounding code as Sublime Text did, and in the meantime I actually found this behavior not so bad because I have more control over how things get pasted.

@pokliu
Copy link
Author

pokliu commented Apr 27, 2017

@CherryDT Thanks for your advice! It's better for me to set option "editor.formatOnPaste": true , it is enough. TY!

update: I just found out the option "editor.formatOnPaste": true will intend the entire document, so I chose to use plugin Paste and Indent.

@pokliu pokliu closed this as completed Apr 27, 2017
@pokliu pokliu reopened this Apr 27, 2017
@druellan
Copy link

@poklau123 I was also experimenting with "editor.formatOnPaste": true. The thing is: if the extension you are using for formatting does not allow a "format-selection" command, it usually ends formatting all the file instead of the pasted code.

I'm also a bit confusing about the paste&format thing. When the discussion stared it was related to paste&indent, but then the paste&format discussion started and took over like a more advanced replacement, but I still believe paste&indent should be part of the editor for cases on where you don't want to format, but also, for languages that have no suitable formatter available, like SCSS.

@CherryDT
Copy link

@druellan I agree, that's what I meant in my comment above and that's why I ended up using the Paste and Ident extension.

@rebornix rebornix added editor-autoindent Editor auto indentation issues and removed editor-contrib Editor collection of extras labels May 1, 2017
@rebornix rebornix modified the milestones: June 2017, Backlog Jun 6, 2017
@rebornix rebornix self-assigned this Jun 6, 2017
@rebornix
Copy link
Member

Already added this feature in Insider build, thanks!

@roblourens roblourens removed the feature-request Request for new features or functionality label Jun 27, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-autoindent Editor auto indentation issues
Projects
None yet
Development

No branches or pull requests

6 participants