I wonder if its possible to automatically expand completions menu, which arrives if you hit <tab>? To basically check for autocompletion under cursor every time you enter character, and not only when you hit tab? Thx.
Internaly fish tab completions are done by a fish binding:
bind -k btab complete-and-search
The wildcard binding is bound to self-insert:
bind '' self-insert
self insert adds the captured char passed from bind '' to the current command,
so when a is pressed it inserts a.
The bind command accepts more than one command, so to do this you would need
to wrap __fish_complete_command (Or whatever internal completion fucntion)
and bind it something like this bind '' self-insert command_complete_wrapper
Because in reality, youd would not want to bind to every input, only
a sane subset.
Good luck.
Related
I am unable to remove the default binding in Fish shell for CTRL + p.
I want to activate separate "background" app outside of the terminal using the CTRL+P shortcut.
I have tried:
bind --erase \cp up-or-search
However the binding remains. How can I remove the preset bindings? The documentation does not mention it.
I want this shortcut to propagate up to the parent process rather than Fish swallowing it and reacting to it.
That's not how it works.
If by "parent process" you mean the terminal, that gets first dibs on every key. It gets to decide what is passed on and what isn't.
If by "parent process" you mean an in-terminal process that started fish: That typically stays in the background and doesn't read any keys at all.
And fish will (and has to) read all input it receives, even if it then decides to do nothing. Reading it is how it finds out what it has to do, and it cannot stuff the input back.
And the terminal has no idea what the processes running inside it have bound or not, so it also can't decide to send keys that it knows the shell will do something with and keep others for itself.
Your mental model is incorrect.
How can I remove the preset bindings?
To erase a preset binding, you could run
bind --erase --preset \cp
However, you would have to arrange for that to be run after the binding has actually been set up. You might want to store it in a function called fish_user_key_bindings. Fish runs that after it sets up the bindings, whenever it does it (e.g. if you switch to vi-mode it'll rerun it).
Typically to disable a binding you would rather make your own that does nothing, like
bind \cp true
Not that this would help what you want to do, see above.
In order to configure a user binding (version 2.2.0), it must be in the fish_user_key_bindings function:
function fish_user_key_bindings
bind \n 'commandline -f accept-autosuggestion execute'
end
This works fine.
I wanted to expand this binding to Ctrl+Enter, by using the appropriate modifier:
function fish_user_key_bindings
bind \c\n 'commandline -f accept-autosuggestion execute'
end
This does not work: Enter uses the current (up to the cursor) suggestion (which is the default) but Ctrl+Enter as well (as if the action with the modifier was not taken into account)
Binding \c\n doesn't make any sense because \n is already a control character. Applying the control modifier a second time to a control character has no effect. Since \n is just an alias for \cJ what you're trying to do is the equivalent of binding to \c\cJ. The only way to bind [Ctrl][Enter] is to configure your terminal to send a unique sequence for that key combination.
P.S., If you grab the current git head source you can make fish_key_reader to build a handy program which will show you a lot of information about what different keys send (although you'll need to wait a few minutes from the time I type this because I need to merge https://github.com/fish-shell/fish-shell/pull/3012).
P.P.S., As of fish 2.3.0 (currently in beta testing) the tty driver no longer automatically converts the \r (aka \cM) that the enter key sends to \n (aka \cJ).
I think you want the following:
bind \cf accept-autosuggestion execute
or the following if you have vi mode installed
bind -M insert \cf accept-autosuggestion execute
I wish to create a custom command which has it's first argument as a regex & pressing TAB after typing regex will open a auto-complete menu with all the files matching the pattern.
if I name my command vimf (meaning vim find) and write the auto-complete function like:
#compdef vimf
_arguments "1: :_files -g \"**/*.conf\""\
In the above auto-complete function, typing $vimf , lists all the files ending with .conf in the auto-completion menu. Now, I want this part .conf to be taken from the first argument of the command. So, if I type something like: vimf *.pp, I want it to search only files ending with *.pp.
How do I make that possible? How can I use the arguments of a command while writing auto-complete functions?
To do this you need to use the words array which is set to the content of the command line.
From this, you retrieve the file type by accessing the good index, and troncate the prefix. (this is done by #compdef vimf)
Here is the result:
#compdef vimf
_arguments "1: :_files -g \"**/*.${words[2]##*.}\""\
&& return 0
I tried it on my terminal, it works, but of course can take long time to perform if your do this by the root. Enjoy :)
While trying to autocomplete a file (e.g. to open a file with C-x C-f) Emacs-helm shows a list of possible candidates.
If I then press Tab (which I would hope it would help me choose the first/closest match), I get the following in the minibuffer:
It looks like the minibuffer gets confused with escape characters, and it does not choose the file that I actually want to open (the top choice).
Helm requires this conceptual jump from the default Emacs completion, which is not so obvious:
You don't need to press a key to complete. The completion buffer refreshes
with new results after every input.
This is called "incremental" completion.
The normal tab functionality is not needed in "incremental"
completion. So tab was rebound to helm-select-action, which allows you to
choose an alternative action with the selection. But there is only one action
in read-file-name.
The error you're seeing could be clearer though, I've filed this issue on github.
Additionally, note Helm treats each space separated term as a filtering
regular expression. So, pressing space foo will filter
the current list down to those that contain foo in the name.
Let's say I'm editing a line...
obj.fooBar(x, y, z);
I want to change the method name to fooSomethingElse, but keep most of the arguments. If I delete all or part of the name, and then use content assist, it completes the method name, but starts a new arg list...
obj.fooSomethingElse(arg1, arg2)(x, y, z)
^---- this arg is highlighted for editing
I often have to delete "(arg1, arg2)". I can turn off "fill method arguments" in preferences and then I only have to delete "()", but it's still annoying. Is there another command to complete only the method name. Ideally it would just be a separate command and key combo from the general purpose content-assist, so I can invoke either one as needed.
Essentially you are looking for a way to toggle between inserting and replacing via content assist. The default behavior is to insert. You can toggle this behavior while inside the content assist selection dialog by pressing and holding the Ctrl key while selecting the completion.
More inforation - http://blog.deepakazad.com/2012/06/jdt-tip-toggle-between-inserting-and.html
I think you just need to press tab instead of enter to autocomplete it. Then it will keep your existing parameters.