atom / revert-buffer

Revert a buffer to its saved state
MIT License
9 stars 11 forks source link

How to use revert-buffer within atom after install? #3

Open saundershayes opened 9 years ago

saundershayes commented 9 years ago

What is the recommended way to use revert-buffer after installing it using apm? I still cannot seem to force a reload from disk within the editor.

skylize commented 7 years ago

Since dev is not responding and did not bother with documentation, I'll answer you.

Once installed, there is a new command Revert Buffer: Revert which you can find easily the fuzzy searching Command Palette by typing Ctrl-Shift-P (or ⌘-Shift-P for Mac) then type revert and press Enter. (Use arrows to select the correct command before pressing Enter if it was not the first match).


But you probably want a single hotkey, so let's go one step further.

You can use the same technique as above to access your keymap: [Ctrl-Shift-P] keymap [Enter]

In your keymap add atom-text-editor if it doesn't exist, and add your desired shortcut as a property of atom-text-editor.

'atom-text-editor':
  'ctrl-alt-r': 'revert-buffer:revert'

You can check your existing keybindings in Settings View: Keybindings to make sure you don't clobber something you need.


You can use this technique to make hotkeys for any command you find from the Command Pallete. Just use lowercase and dashes instead of spaces to get the code version of the command name.

So as an example, let's type [Ctrl-Shift-P ] select beginning. You should see a command Editor: Select to Beginning of Line. which doesn't have a keybinding. (This command makes a selection from your cursor to the very beginning of the current line, including leading spaces and ignoring soft wrap.)

We can add a hotkey of Ctrl-Alt-LeftArrow by adding it to the keymap.cson beneath our previously created Revert hotkey like this:

'atom-text-editor':
  'ctrl-alt-r': 'revert-buffer:revert'
  'ctrl-alt-left': 'editor:select-to-beginning-of-line'