Retention of indentation when copying from one file and pasting to another file.

Sadly, none of the links I have found answer my questions regarding the retention of indentation on a paste , or I can’t interpret how the questions are answered. I am relatively new to modern software development and newer still to IntelliJ (v2017). I love the product BTW.

I have been attempting to work on an Express/Pug project, a major task if which was to break up a rather large index template into smaller, bitesize chunks. I started by cutting and pasting modular sections from the large file in to smaller modular file. The large file was already pug-formatted with indentation. When I pasted the indented code from the large file into the smaller files, in each case I lost all of the indentation. Each line in the smaller files started at position 0.

To make a long story short when I attempted to redo the indentation in the smaller files (manually), I didn't get it right. As I am sure you are aware that is a catastrophic problem with pug. Surely, there must be a way to set a parameter in IntelliJ to retain the indentation when performing cut/paste operations like that. It is such a robust product. I just have found the answer yet.

0
10 comments

Hi there,

>Sadly, none of the links I have found answer my questions regarding the retention of indentation on a paste , or I can’t interpret how the questions are answered.

It would be great to see those links -- otherwise I might be repeating the same here.

In any case -- that the option that I'm aware that affects indentation on paste.

Plus, you can always try "Edit | Paste Simple" instead of usual "Paste"

 

1
Avatar
Permanently deleted user

Andriy Bazanov Thank you. This was NOT a link I found. I never guessed it would have anything to do with Smart Keys so I never looked at this.

Let me make sure I understand what you are telling me. The Reformat on paste: should be set to None. (Mine is set to Indent Each Line).

0
Avatar
Permanently deleted user

I just created a login to thank the question form Doug and the beautiful answer from Andriy, it not only just fixed my indentation problem on pasting the code in IDE but also made my day and brought sanity to my work. Thanks once again for the excellent community support.

0

I have a similar problem but with a slight variant.  I use IdeaVim to edit pug files in PHPStorm (with same behavior in WebStorm).  In the screenshot below, I start with lines 15-17.  I then position my cursor on line 15 and type “2yyP”.  What happens is the indentation gets really weird, as seen in second image.  This is counterproductive as I am constantly copy/pasting in these files.

I tried the Smart Key adjustment recommended above, and no change in operation.  Do either of you know of a solution?  I could create another story but thought it might be a small adjustment to the recommendation above.  Thank you.

0

As an update,

I was able to get indentation with IdeaVim and pug to work properly, though at the cost of ignoring *.pug files, which has side effects such as not seeing the files in the project file browser (!)  Code coloring seems to be maintained.  I'm open to alternative options though that doesn't entirely disable editing features.

0

Ryan McKeel 

Sadly I neither work with *.pug files or use IdeaVim. Therefore I cannot say what effect IdeaVim may have on Copy+Paste operations. 

My best idea is to check if using “Paste | Paste as plain text” would do any better than just "Paste".

As far as I know in Pug files indentation plays a big role (just like in Python), therefore I do not think that "Code | Auto Indent Lines" would help here…

 

Other than that – might be WEB-43958 ticket on WebStorm Issue Tracker (will post the link in a separate comment, since all posts with links need to be moderated/approved, which takes time)

0

Andriy Bazanov Thank you for your quick reply!

I just figured out that disabling this plugin: https://plugins.jetbrains.com/plugin/7094-pug-ex-jade- eliminates this odd indent effect, so perhaps when I get some time I'll file a bug there.  I'll also check out the other resource you linked to, thank you.

0

Well … that first WEB-43958 ticket – looks like it was you who created it in the first place 😂

0

Andriy Bazanov Thanks for your thoughtful responses.  Yes, you're right, I did create WEB-43958 three years ago!  Had to rediscover the bandaid solution of disabling the pug plugin, as I had forgotten I created a formal issue.  Anyway I'm still subscribed to those issues and will see when or if they are fixed.  Thanks

0

Please sign in to leave a comment.