Virtual space

Atom is just awesome editor, but in some editor, that I’ve used before, there was an “virtual space” feautre. What it is? It feels like whole editor filled with spaces. So, when I trying to move cursor with down key (if line exists) it moves down on the same column.
So, example:
In editor (| is cursor):

And after I press down key:

Or I click position with mouse, by the way.
Is there something similar in atom or is it possible to write such plugin?


I haven’t heard of a package that implement that feature, but it can definitely be implemented.

It’ll require some new commands that just fill the line above or below with spaces and then trigger the core:move-up and core:move-down commands as they already preserve the column when moving the cursor.

Then by binding these new commands to the same bindings originally used by core:move-up and core:move-down you’ll get what you describe.

1 Like

That’s certainly possible. I thought about creating a package for this, but I’m probably not going to use this, so I’m not sure I’m the right person to maintain that package. In case someone wants to, here’s what I did:

{Point, Range} = require 'atom'

moveCursorVirtualSpace = (direction, targetElement) ->
  lineDiff = if direction is 'up' then -1 else 1
  editor = atom.workspace.getActiveTextEditor()
  screenPos = editor.getCursorScreenPosition()
  newScreenPos = new Point screenPos.row + lineDiff, screenPos.column
  diff = screenPos.column - editor.lineTextForScreenRow(newScreenPos.row).length
  if diff > 0
    textToInsert = ''
    textToInsert += ' ' for i in [0...diff]
    bufferPos2 = editor.bufferPositionForScreenPosition newScreenPos
    bufferPos1 = new Point bufferPos2.row, bufferPos2.column - diff
    bufferRange = new Range bufferPos1, bufferPos2
    editor.setTextInBufferRange bufferRange, textToInsert
  atom.commands.dispatch targetElement, "core:move-#{direction}"

atom.commands.add 'atom-text-editor', 'text-editor:move-down-virtual-space', ({currentTarget}) ->
  moveCursorVirtualSpace 'down', currentTarget

atom.commands.add 'atom-text-editor', 'text-editor:move-up-virtual-space', ({currentTarget}) ->
  moveCursorVirtualSpace 'up', currentTarget
# keymap.cson
  'up': 'text-editor:move-up-virtual-space'
  'down': 'text-editor:move-down-virtual-space'

It should work already, but it doesn’t remove the spaces it adds to the editor. Not a big problem if you use the option to remove spaces at the end of lines in the whitespace package.


Hm, sounds great, I’ll try this, thanks!

Oh, something ugly comes here. I think we can’t partly control indentation guides visibility, can’t we?

Great snippet, does almost what is needed. One change I’d like to have is jump to the indentation level if moving onto an empty line, not to the same cursor position.

And some indexes go wrong… Needs debugging.

I’ve implemented a package that does what I needed – keeps the cursor at the current level of indentation, even on empty lines.

This package can be extended to support the past-end-of-line editing, but I see no use of this mode, so I’d like to have it optional, enabled by some setting. Feel free to contribute!

Looks good. Remove trailing spaces is good idea.

support the past-end-of-line editing, but I see no use of this mode

This is useful for me (comments, for example)

But anyway, this is just «generated spaces», not the True™ virtual space, when there is no extra characters until something typed. But this should be implemented deeper in atom, I think.

Is there really no way to move the cursor in the virtual space without changing the file?

Other editors have uncheckable options like ‘Constrain cursor to text’ (Textpad <- i am using this), or “Enable virtual space” (Visual Studio <-found this by google).
Once you’ve used that, you don’t want to give it up.