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
Related
In most command line interface "cli" programs the Option-arrow key combinations allows one to move forwards/backwards a word at a time. But in psql both Option-arrow and Control-Arrow actually insert non printable control characters that corrupt the command. In addition in most CLI programs hitting CTL-A goes to the beginning of the command and CTL-E goes to the end of the command. But in psql those combinations do not have any effect.
Navigating a single character at a time is simply too slow: I can not imagine this were an unsolved problem. What is the configuration needed to get one of those key combinations to skip forward/backward by words not characters?
This is an answer containing the response in the comment by by #Marth. The ~/.inputrc does cause the issue.
# want vi to be the default editor for readline
set editing-mode vi
$if mode=vi
# normal mode
set keymap vi-command
set keymap vi-insert
"\C-n": backward-kill-word
"\C-p": history-search-backward
$endif
I have completely removed the ~/.inputrc now.
I am a windows user. I am trying Ubuntu via WSL-2. I am struggling to select text with arrow keys in fish shell. I tried so many places to get answer for this question, but no one gave me proper solution. In documentation they wrote about binding for begin-selection. But what is the default way to do this?
begin-selection is a key binding, but it's not enabled in the standard key bindings by default.
You'll need to set some key bindings to begin and end selecting text. For example:
bind \e, begin-selection
bind \e. end-selection
will set Alt-< and Alt-> to be begin and end select mode, respectively. These can be used with the default Ctrl-X clipboard copy function.
Fish does not support your intended style of selecting text. The begin-selection and end-selection commands are intended for VI-style selection in VI mode.
See this feature request, this question on superuser and daleeidd/natural-selection for an attempt to implement shift-select.
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.
In Emacs, I want to bind a particular key combination to a command. However, because I am using Emacs in terminal mode within iTerm2 on OS X, I need to translate the key combo to character escape sequence and register that sequence with iTerm2 so that it will recognize the key combination.
But how do I find out the corresponding sequence given a key combination? For example, I found that something like ^[[1;8A corresponds to Ctrl+Alt+up (where I have configured Alt to function as +Esc in iTerm2), but I have no idea how that key combination translates into this particular sequence.
Is there a way to look up or work out the escape sequence for any given key combo? For example, what is the sequence for Ctrl+Alt+r?
A related question, can someone explain to me the relationship between setting up a key combo with its corresponding sequence in iTerm2 and making Emacs translate a sequence into its internal key representation using input-decode-map inside .emacs (e.g. (define-key input-decode-map "[escape_sequencehere]" [internal_key_representation_here])? It seems to me that setting it up in iTerm2 alone is sufficient to make the binding work in Emacs, so when and why do we need to set up the latter in .emacs? (and perhaps when do we need both to make something work?)
Some of the key combinations are sent directly to the application running in iTerm2. You can get it
by using ctrl+v approach (see In bash, how do I bind a function key to a command?) or
bash-3.2$ ^[[1;10A (in this case I hit ctrl + v before shift+alt+up)
sed -n l (note it's lowercase L). For instance, you can see what the application receives if you send (shift+alt+up):
bash-3.2$ sed -n l
^[[1;10A
\033[1;10A$
If some key combination does not get through, you can instruct iTerm2 to let it pass and map it to a key combination that you can detect as described above. For instance, you can send through and map ctrl+alt+cmd+R to ESC+sdf and your terminal will receive ^[sdf which you can assign to a command in Emacs.
In your terminal type showkey -a and let the key-strokes fly.
I'm using psql 8.2.3 on FreeBSD. Every time I press Insert, Home, Delete, End, Page Up or Page Down, a tilde (~) character is inserted instead of performing the expected function of the key. Why does this happen and how can I fix it?
As mentioned in Endlessdeath's answer, this turned out to be a key mapping problem with the operating system (FreeBSD), not psql. You can make these keys work as expected by creating or adding to a configuration file for inputrc.
You can create a file named .inputrc in your home directory with the following:
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
Alternatively, you can create a global file for all users. A common practice for this is to create or add to the file at /usr/local/etc/inputrc the same lines as above and then export the variable in /etc/profile:
export INPUTRC=/usr/local/etc/inputrc
Ensure that /etc/profile is sourced by your shell (most do by default) and you're good to go. Note that the file won't be sourced until you log out and in again.
Here are some other resources for this problem:
http://bsdpants.blogspot.com/2007/08/make-home-and-end-keys-work.html
http://www.cyberciti.biz/tips/freebsd-how-to-customized-home-del-insert-keys-for-bash-shell.html
http://www.ibb.net/~anne/keyboard.html
That shouldn't be a psql problem - it's os specific.
A quick search on google could help.