[Announce] Force Tab -- Just Insert a tab character, darn it!


#1

I don’t know about y’all, but sometimes I just want to insert a tab character and I don’t want Atom to argue with me about it! :angry:

Sometimes I’ll try to insert a tab and get snippets inserting a bunch of stuff I don’t want, or autocomplete will try to autocomplete something I don’t want, or softTabs is enabled and I literally can’t insert an actual tab character without temporarily disabling the setting – which is super annoying!

Enter :anger_right: force-tab! :anger_right:

By default Atom outdents code when you press shift-tab, but I absolutely never use that! I always use cmd-[, with cmd-] for indenting. If you’re like me, and sometimes you just want to insert a damn tab character, I’ve made shift-tab map to a new command that forcibly inserts a tab or an appropriate number of spaces if editor.softTabs is enabled.

Settings for the package include an option to totally disable honoring editor.softTabs.


#2

Hrm, well, personally I’ve never found myself in this situation… I always have hard tabs enabled, and use spaces to align anything after a non-whitespace character, so… :smiley:

I’m guessing Atom’s language-specific editor settings don’t help for you?


#3

I use spaces in some languages and tabs in others, but I usually use the tab key for aligning things after a non-whitespace character. And sometimes I’ve wanted to insert a literal tab character and been unable to because of softTabs being enabled.

Probably this won’t be a super useful package to most people, but maybe some! :slight_smile:


#4

Quick solution.

Open Textedit.app / Notepad and press tab. Then copy and paste that to Atom.

I use this in the rare occasion that I need a REAL TAB in Atom. For me this is only when I am editing tabular data (TSV) and using multi-select to do a quick edit. And that’s usually when I’m scraping HTML and doing some hack processing to get it to fit into a spreadsheet.


#5

Can confirm that @fulldecent’s solution works just fine too. I used to do the copy/paste trick myself before writing the package.


#6

I was unwilling to lose shift-tab to adjust indentation, my solution was to add this to my snippets file:

'.source':
  'tab':
    'prefix': 'tab'
    'body': '\t'

#7

That’s clever. I’ve just added to ~/.atom/snippets.cson:

atom.commands.add 'atom-text-editor',
'user:insert-tab': (event) ->
    editor = @getModel()
    editor.insertText('\t')

And to ~/.atom/keymap.cson:

'atom-text-editor':
    'ctrl-i': 'user:insert-tab'

#8

Funny, I really need shift-tab to outdent the selected lines but for me shift-tab moves the focus to some parts in the status bar, which is very annoying since tabbing does not seem to bring back the focus to the editor.

I can’t seem to remove all shift-tab shortcuts. This is in the keybindings:

shift-tab	editor:outdent-selected-rows	Core		atom-text-editor:not([mini])
shift-tab	core:focus-previous			Core		body .native-key-bindings

Any ideas?


#9

I’ve seen that issue before too and was able to re-create it just now. What’s your current keymap.cson file? You can get to it from:

  • Atom > Keymap... on MacOS (I’m not sure on other OSes)

Or you can use the Keybinding tab in the Settings View (Cmd+, on macOS and Ctrl+, on Linux/Windows); click on the link for your keymap file.

I was able to get things working adding something like this to my keymap.cson:

"body .native-key-bindings":
  "shift-tab": "unset!"

And if you have force-tab installed you’ll probably want to uninstall it, disable it, or go into it settings and disable its keymap.


#10

My keymap.cson was empty. I tried unsetting the value by assigning it an empty string, but your unset! (didn’t find that when I was looking to unset a key) works! I had to unset Tab as well:

'body .native-key-bindings':
    'shift-tab': 'unset!'
    'tab': 'unset!'

'atom-text-editor:not([mini])':
    'shift-tab': 'editor:outdent-selected-rows'

This works, so thanks!