5

I'm using terminator along with fish and I want to use Alt-Left etc for navigating terminator and Ctrl-Left and Ctrl-right to move the cursor by word. The problem is when I do

bind \cleft backward-word

it doesn't change the behavior of of Ctrl-left or right. This seems to follow what the documentation and I pulled the key and the command from the -K and -f flags and

bind -a

shows that the bindings exists.

I've used the same command for other sequences, but I can't get this one to work. Am I missing something?

0

5 Answers 5

5

I fixed it on my end. This goes in the config:

bind \e\[1\;5C forward-word
bind \e\[1\;5D backward-word

"source" it by executing:

. .config/fish/config.fish

("." is source in fish)

Hope that helps you!

4
  • 1
    Great! But I'm having a problem getting this to run automatically every time I open a terminal. I don't want to source it manually every time. Is there a way to do it automatically?
    – Seb
    Sep 6, 2012 at 15:24
  • @Seb Same here. I don't use fish frequently enough (due to these kinds of issues) for this to have been an issue, so I am still sourcing manually. I would very much like to know, though. You could open a question I guess?
    – eggonlegs
    Sep 9, 2012 at 18:57
  • the "~/.bash_profile" for fish is in ~/.config/fish/config.fish (if it doesn't exist create it). To have it run on login do this: if status --is-login bind \e[1\;5C forward-word bind \e[1\;5D backward-word end
    – Steve Ross
    Apr 23, 2013 at 20:57
  • Hi, @eggonlegs , is the escape sequence you typed stand for escape + [ + 1 + ; 5 C", this is quite a long sequence. Why use such a long key sequence, isn't it hard to press them all?
    – richard.g
    Aug 22, 2015 at 1:20
3

type bind \cleft backward-word in the fish command line should do the job. If you want it to be executed at each startup put:

function fish_user_key_bindings
    bind \cleft backward-word
end

in .config/fish/config.fish

From fish bind documentation

Key bindings are not saved between sessions by default. Bare bind statements in config.fish won't have any effect because it is sourced before the default keybindings are setup. To save custom keybindings, put the bind statements into a function called fish_user_key_bindings, which will be autoloaded.

2

First thing to note is that ctrl+left-arrow doesn't make any sense and can't be done in any shell. That's because the ctrl key doesn't actually send any characters by itself (unless you've done something very unusual to your terminal configuration). What that key does is modify the next letter that is press. For example, ctrl+a causes the terminal to send the single byte hex value 0x01. Since keys such as left-arrow normally send a sequence of characters that begin with the esc character, and escape is already a control character, applying the control modifier to it doesn't do anything.

As you found the usual way to do this is use the alt. If you've configured your terminal to treat that as a "meta" key that prefixes whatever follows with the escape character you can then press alt+page-up to have the terminal send \e\e[5~. If you build fish from git sources you'll get a handy program named fish_key_reader that makes learning what different keys send much easier. That will be in the fish 2.3.1 release which should be available in a couple of weeks.

Lastly, custom key bindings should go in your personal config file, not the global /usr/share/fish/functions/fish_default_key_bindings.fish script. You should create a file named $HOME/.config/fish/functions/fish_user_key_bindings.fish with the following content:

function fish_user_key_bindings
    bind \e\[1\;5C forward-word
    bind \e\[1\;5D backward-word
end
0

The "~/.bash_profile" for fish is in ~/.config/fish/config.fish (if it doesn't exist create it). To have it run on login put this in the config.fish file:

if status --is-login
 bind \e\[1\;5C forward-word
 bind \e\[1\;5D backward-word
end
0

The accepted answer is almost worked, but I found I can't make it auto bind the keys through config.fish file. I endup modify the fish_vi_key_bindings.fish (which under /usr/share/fish/functions) directly.

Also, just adding ctrl-left and ctrl-right to normal mode under vi keybind is not enough, have to add insert and visual mode also.

bind \e\[1\;5C forward-word
bind \e\[1\;5D backward-word
bind -M insert \e\[1\;5C forward-word
bind -M insert \e\[1\;5D backward-word
bind -M visual \e\[1\;5C forward-word
bind -M visual \e\[1\;5D backward-word

Sorry for this should be a comment to the accepted answer, not an independent answer, but due to I don't have sufficient reputation to add comment (personally, I don't think this reputation system is reasonable), and I felt that I should share this to someone who is facing the same issue, or for someone who has experience on how to fix the issue.

2
  • Worked for me, though I added it to /usr/share/fish/functions/fish_default_key_bindings.fish.
    – metal
    May 23, 2016 at 13:36
  • Please reread my answer. You can only put the bindings in config.fish if you are running fish 3.0. Otherwise the bind commands should go in your personal * $HOME/.config/fish/functions/fish_user_key_bindings.fish* autoloaded function. You should never modify the system files. Feb 14, 2019 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.