Paste preserving the indentation + Whitespace conversion issue.
-
Do you have any plugins that may auto-indent code?
What application do youcopy
from?
Did you consider that this app maycopy
un-indented text to the clipboard and NP++ justpastes
whatever in there? -
I don’t have plugins for autoindenting code aside from n++ automatic indent on new line behaviour.
I copy the code from discord and without spaces thats true, and paste into notepad++ but the text in notepad++ has the indents, and they get wiped.I cant just copy the whole block for this reason, Now, I copy things that have indents line by line, which of course has more steps than just being able to copy paste and keep the indents.
That’s all.
-
Pasting is not identical to typing the text “symbol by symbol”.
The auto-indent logic is triggered by the “enter” key press. This does not happen with paste and 99% of users will not want it to happen since pasting already indented text between source files, which is what code developers do, will become a mess.
Paste just inserts at the cursor a bulk of text: symbols, spaces, tabs and new-line symbols. Then NP++ redo syntax highlighting from the insertion place.The semi-easy solution is: copy all the lines, select them, and indent them as a block.
You may even be able to create a macro for that. -
How to do that?
-
I don’t see anything wrong with the way Notepad++ pasting works.
It is not often that pasted code is indented to the same level as the code being pasted into; I do this type of pasting A LOT. What would be best here would be if Scintilla kept the pasted text selected (if it is whole-line text that is either being inserted at the caret point, and–optionally-- is replacing a previous selection of whole lines). If it were kept selected, a quick TAB or Shift+TAB press(es) would adjust it to the right indent level quickly.
Otherwise, we have to be careful that we don’t talk about potential features that do too much mind-reading. Notepad++ isn’t an IDE that is really good at one language-it’s a general purpose tool that tries to do a lot of things acceptably well. It largely succeeds.
-
@SalviaSage said:
How to do that?
Select lines with shift-arrows.
Click tab to indent or shift-tab to unindent. -
One of the neat tricks about a stream selection that contains one or more line-endings is that you don’t have to have a selection covering an integral number of lines in order to tab-indent (or [shift-]tab-outdent) the lines touched. An example:
Note that in the beginning, only part of the first line and part of the last line are selected. A tab (or shift+tab) press affects the lines as if they were entirely selected, and in fact after the first tab keypress they are entirely selected.
-
That’s nice. I didn’t know you could do that. That effectively solves my problem. Although I may not be able to preserve the indents, I can then just select my lines and press tab.
This of course doesn’t work for those infidel space indenters, Which is why I need the convert spaces to tabs working correctly.
Look at my example above. If a space indenter indented with 4 spaces and I have my tab length set to 2 spaces, when I do the operation, I get 2 tabs when I should get 1. Can this be fixed with a script?
-
Hi, @salviasage, and All,
To my mind, it’s quite normal that N++ replace a
4-spaces
indented text with2-tabulations
of size2
, because, from your preferences, you decided :-
To use
tabulation
characters instead ofspaces
-
To define that each tabulation will take
2
positions
Indeed, if you expect a unique tabulation, taking
4
positions, it would, then, contradict your preferences !!Cheers,
guy038
-
-
that would be the case if it was you who was also indenting with 2 spaces, but you are not the only one who codes, you get a code from other people who may indent with 4 spaces, 6 spaces, 8 spaces or whatever it is that they decided to indent with.
Then, you want to convert that to your own style, and you cannot do this automatically, you still have to manually do it, by going into the preferences and changing your tab length to whatever the other coder formatted with, then you open another code formatted with a different set of spaces, then you do the same etc.
At least, it would be nice if we had like a tab length : 2 option in the status bar, where you can quickly set your tab length.
We can easily see what EOL the file is formatted with and convert the EOLs from the statusbar.
I really like that EOL option offered there on the status bar, and is perfect.
But, the same is simply not the case for the indents. That area, I think can be improved upon programmatically.If anyone knows a script to make these conversions more automatic, please let me know.
-