Toggle Line Numbers


#1

Loving atom so far, quite a few improvements over sublime, but I’m missing the ability to quickly toggle line numbers with a keyboard shortcut. Any way to do this or add it simply?


#2

You have to add this code to your init.coffee:

atom.workspaceView.command 'line-numbers:toggle', ->
  atom.config.toggle('editor.showLineNumbers')

Then map the line-numbers:toggle command to a key, you can do this in the keymap.cson file:

'.editor':
  'f5': 'line-numbers:toggle'

I’m using F5 but you can use whatever you want.


#3

Awesome! Thank you, glad the editor is so flexible. May be my new main choice.


#4

Hi, It’s working like a charm. Thanks for sharing it.

But there are some deprecation messages on init.coffe file. This is the warning message:

Config::toggle is no longer supported. Please remove from your code.

and…

atom.workspaceView is no longer available. In most cases you will not need the view. See the Workspace docs for alternatives: https://atom.io/docs/api/latest/Workspace. If you do need the view, please use atom.views.getView(atom.workspace), which returns an HTMLElement.

What I should do for fixing these issues?

Thanks.


#5

You can do the same thing with:

atom.commands.add 'atom-text-editor:not([mini])', 'line-numbers:toggle', ->
  lineNumbersShowing = atom.config.get('editor.showLineNumbers')

  if lineNumbersShowing
    atom.config.set('editor.showLineNumbers', false)
  else if not lineNumbersShowing
    atom.config.set('editor.showLineNumbers', true)

[SOLVED] How to hide gutter when hiding line numbers?
#6

Thank you for your response. It’s solved the deprecation issues. :slight_smile: