Single hotkey for toggling code folding?


#1

How can I configure Atom to use a single hotkey for toggling code folding, rather than having to press two hotkeys?


#2

See the section in the documentation on Overloading Key Bindings:

https://atom.io/docs/latest/behind-atom-keymaps-in-depth#overloading-key-bindings


#3

Add to your init.coffee file:

atom.commands.add 'atom-text-editor',
  'custom:toggle-current-row-folding': (event) ->
    editor = @getModel()
    cursorScreenPosition = editor.getCursorScreenPosition()
    bufferRow = editor.bufferPositionForScreenPosition(cursorScreenPosition).row
    if editor.isFoldedAtBufferRow(bufferRow)
      editor.unfoldBufferRow(bufferRow)
    else
      editor.foldBufferRow(bufferRow)

Taken from: