Normalize indent on paste doesn't work as expected


#1

With the default “Normalize Indent on Paste” option, indent-on-paste doesn’t work as expected for me.

If I have a file with some indented lines like:

  foo
  bar
  baz

And then I select the entire line “bar”, then copy, then paste, I get:

  foo
bar
  baz

I would expect it to keep the indentation, but it goes back to the beginning of the line.

If I turn off “Normalize Indent on Paste”, this works as expected.


Copy/paste loses indentation?
normalizeIndentOnPaste disables autoIndentOnPaste
Is Paste Broken or am I dumb?
#2

Hi Jason,

I got hit by this one too.
Is ‘normalizeIndentOnPaste’ enabled in your editor’s config?
When both ‘normalizeIndentOnPaste’ and ‘autoIndentOnPaste’ are switched on I noticed that ‘autoIndentOnPaste’ does not work anymore.

My choice is ‘autoIndentOnPaste’:
so here is what my Config looks like:

'editor':
  'autoIndentOnPaste': true
  'normalizeIndentOnPaste': false

Here is the bug report: normalizeIndentOnPaste disables autoIndentOnPaste

I hope this helps,
Hugues


#3

Huh. In the settings view, I see an “Auto indent” option, but not “Auto indent on paste”. I didn’t even try turning off auto-indent since it seemed too obviously useful.

In fact, audoIndentOnPaste seems to only be relevant to an older version of Atom—it’s not in the latest docs: https://atom.io/docs/latest/customizing-atom


#4

Hey good point I was staring at an older doc. I am up to date with 0.73.
So I removed the line with the obsolete ‘autoIndentOnPaste’ that makes no difference.

If ‘normalizeIndentOnPaste’ is on then I get the behaviour you describe.
When it is false then the pasted line keeps its spaces and tabs at the beginning.

Not as much as I was hoping for with the ‘autoIndentOnPaste’ but my favorite setting for now.

Hugues


#5

Wow. Turning off normalizeIndentOnPaste actually makes me want to use Atom again! Excellent?

All this time I was slowly being driven mad by all the extra manual indenting I was having to perform post-paste.

So, what’s the use case for this setting? When is it useful to turn on? Why is it on by default?


CoffeeScript auto-indent broken?
#6

For anyone wondering where the setting is, it’s here…


OK, I have had it
#7

the option should be: Remove Indent On Paste


#8

thanks, added that to config.cson works like a charm

'editor':
  'normalizeIndentOnPaste': false

#10

This is unbelievable. Why is this not built-in? How do we fix this issue??


#11

This is still an issue, and nothing here fixes it. Every time I copy/paste code to and from any file, the indentation is always messed up.

As a sidenote: look how many views this post has. This is ridiculous and needs to be fixed.


#12

Unable to find a workaround for this issue, a good example would the “Paste and Indent” feature from Sublime. With a shortcut you are able to paste and indent the copy as expected.


#13

Still awaiting a fix.


#14

I think the feature was working previously (around Atom 1.4).
Now (1.4.3), when I cut a function declaration (for example), then paste it elsewhere at the same level, I get my snippet indented by two levels!

Ah, I guess it blindly adds the current indentation level to all the pasted lines, without checking if these lines are already indented!
I will stick to set the setting to false. Too bad, as this can be useful in some cases.

Note: indenting with 4 spaces, auto indenting detection (tab type: auto), auto-indenting on typing.


#15

Still doesn’t work for simple JS files.


#16

hey, just switched to Atom from Sublime. Is this still an issue? Cause it looks like there is no way to paste with normalised indentation so far :confused:


#17

If you have “Auto Indent on Paste” selected, your pasted text will be indented at the level of the line before it.


#18

Can’t say I understand why, but if I use this custom snippet keeping autoIndentOnPaste: true the situation gets actually better, even if it should change nothing:

init.coffee

atom.commands.add 'atom-text-editor',
  'user:paste-and-indent': (event) ->
    editor = atom.workspace.getActiveTextEditor()
    editor.pasteText({ 
      select: true # This selects just-pasted text, just an additional feature, you can disable safely
    })

keymap.cson

'atom-text-editor:not(.mini)':
  'cmd-v': 'user:paste-and-indent'

config.cson

'editor':
  'normalizeIndentOnPaste': false

PS: the normalizeIndentOnPaste config option is no longer existent.