reddit / emacs
What do you bind TAB to? Indent, complete or fold?
Kaligule · 2022-03-02 06:45
In my opinion all 3 of those have a natural right to sit on the TAB key:
- Indentation: It is the tabulator key after all
- Completion: As in TAB-completion in the terminal
- folding: like in orgmode, but most code that has blocks can be folded
I don't have a good solution for all of them at once. ideally it would support different packages for Indentation/compilation/folding.
What do you use?
karthink · 2022-03-02 07:00
You can make tab do many things at once. Read the documentation for the variables `tab-always-indent` and `tab-first-completion`.
I use tab to do the following:
- Tab-completion in the shell/minibuffer
- `outline-cycle` (everywhere) and `org-cycle` (in org)
- Indent code
- Completion with `completion-at-point`, and cycling between candidates in `corfu`/`company-mode`
- Snippet expansion with YaSnippet
- Semantic cursor-jumps in `CDLaTeX-tab`
with the action to run chosen depending on the context. The heuristic for binding so many things to tab was built up over time and is complicated, but the built in support for multiple actions through the above variables works fine.
sewageseller · 2022-03-02 07:49
Could you share your configuration? (:
xtifr · 2022-03-02 07:53
I don't bind TAB. It comes with default bindings that work perfectly well for me.
karthink · 2022-03-02 07:58
Okay, but I don't recommend copying code from it. Customize `tab-always-indent` instead.
[Tab for outline-cycle with fallback](https://pastebin.com/bWWHsiBe)
[Tab for CDLaTex, YaSnippet and OrgTbl together](https://gist.github.com/karthink/7d89df35ee9b7ac0c93d0177b862dadb)
arthurno1 · 2022-03-02 13:37
It depends on the major mode.
xenodium · 2022-03-02 13:47
I got a DWIM-style function to indent (if necessary) otherwise toggle fold https://github.com/xenodium/dotsies/blob/a8451261e3a1621fb32601a74e696dc512e51a33/emacs/features/fe-navigation.el#L229
KaranasToll · 2022-03-02 14:30
Tab is for indent. M-/ is complete. C-tab is fold.
meain · 2022-03-02 18:06
I technically have them bound to all 3. I use evil mode, in normal mode tab does folds. In insert mode tab indents if no completion candidates available (not in the middle of text) or if tying something, it auto completes.
habershabery · 2022-03-02 23:12
I generally leave the TAB key alone and let it each mode change it as needed.
However, I do change the TAB and space keys when doing minibuffer completion, as hitting the TAB key then is too tedious (for me):
(define-key minibuffer-local-filename-completion-map "\^i"
'minibuffer-complete-word)
(define-key minibuffer-local-filename-completion-map " "
'minibuffer-complete)
(define-key minibuffer-local-completion-map "\^i"
'minibuffer-complete-word)
(define-key minibuffer-local-completion-map " "
'minibuffer-complete)
This make filename completion a lot easier -- once you get used to it, it's really hard to go back to TAB (in emacs -- you still have to use TAB in programs like bash, but I've never found that to be a problem). Note that this can make it harder to enter a space, but the completion will either skip over spaces, or I can just hit `C-q SPC`.
tman5400 · 2022-03-03 02:53
I have tab bound to `evil-quit`
seregaxvm · 2022-03-03 04:14
My TAB does completion, indentation, folding and inserts snippets.
Kaligule · 2022-03-03 06:17
How so?
seregaxvm · 2022-03-03 06:20
Here's the [config file](https://gitlab.com/matsievskiysv/emacs-configs/-/blob/master/elisp/init-indent-or-complete.el). I think I took it from <https://www.emacswiki.org/>