Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore anything-like behavior for TAB autocomplete in helm?

A related question was asked here. But the answer is to get used to the new way autocomplete works in helm. I cannot get used to it, here's why.

Say, I want to open a file /home/user/work/f.txt. I do C-x C-f, it takes me to current dir, say /current/dir/. I hit Backspace and notice that autocomplete won't let me delete /. Ok, turn off autocomplete with C-Backspace. Then kill the line C-a C-k and start typing. Notice that autocomplete doesn't work, turn it back on C-Backspace. Normally I would type the part that I know is probably unique, e.g. /hom and hit Tab.

Not here. As soon as I type /ho, autocomplete resolves it to /home/, but since I type fast, I end up with /home/m, and continue typing now meaningless characters until I notice it. Chances are, by that time I got autocompleted into directories that I had no intent of going.

So I have to constantly watch what autocomplete is doing, rather than rely on what I type and only checking suggested completions when I hit Tab.

I also find myself descending into wrong directories due to occasional typo, and then having difficulty going up a level -- evil autocomplete won't let you fix the situation with a couple of Backspaces.

This interaction of autocomplete behavior and the removal of Tab functionality completely upsets my work, so much that I decided to ask this question. I am looking to either:

  1. restore the old functionality
  2. learn how to use autocomplete in a meaningful way, or
  3. configure helm's C-x C-f to behave more like a linux command line

Please help.

like image 438
user443854 Avatar asked Oct 03 '22 20:10

user443854


1 Answers

Here are some ido tricks if you want to start using it. Let me know if helm is better, perhaps I'll switch over. I tried once shortly, but didn't like it.

Basic setup:

This will give you `ido-find-file on C-x C-f.

(ido-mode)
(setq ido-enable-flex-matching t)

Smex setup:

Install from https://github.com/nonsequitur/smex.

(require 'smex)
(global-set-key "\C-t" 'smex)

Switch buffers with ido:

(global-set-key
 "η"
 (lambda()(interactive)
   (when (buffer-file-name)
     (save-buffer))
   (ido-switch-buffer)))

(global-set-key
 (kbd "C-η")
 (lambda()(interactive)
   (let ((ido-default-buffer-method 'other-window))
     (ido-switch-buffer))))

Tricks:

;; 1
(add-hook 'dired-mode-hook
          (lambda()
            (define-key dired-mode-map "j" 'ido-find-file)))

(add-hook
 'ido-setup-hook
 (lambda()
   ;; 2
   (define-key ido-file-dir-completion-map "~"
     (lambda ()(interactive)
        (ido-set-current-directory "~/")
        (setq ido-exit 'refresh)
        (exit-minibuffer)))
   ;; 3
   (define-key ido-buffer-completion-map "η" 'ido-next-match)
   ;; 4
   (define-key ido-buffer-completion-map (kbd "C-p")
     'ido-fallback-command)
   ;; 5
   (define-key ido-completion-map (kbd "C-.") 'smex-find-function)
   (define-key ido-completion-map (kbd "C-,") 'smex-describe-function)))
  1. Quick open file from dired.
  2. Move to home directory one key faster (i.e. ~ instead of ~/).
  3. Cycle buffer candidates with the same key that shows the candidates (a la C-TAB in Firefox).
  4. Useful to have a fall back when you want to create a file-less buffer (ido will try select an existing buffer unless you fall back).
  5. Useful to jump to function definition/documentation.
like image 152
abo-abo Avatar answered Oct 29 '22 18:10

abo-abo