Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I force fish to save new key bindings persistently after closing a terminal window?

At the moment i have the problem:

  • I open a terminal window, the default shell is fish.
  • I add a key binding with: bind \eg functionname
  • It works in the terminal window
  • Now I close terminal window
  • Open a new terminal window, again fish is default shell
  • The binding doesn't work any longer and doesn't show up in output of fish -a
share|improve this question

You can add the bindings in the initialization files:


For example you can add the following function:

function __fish_less
       commandline -i -- "|less"

bind \ey __fish_less

An example:


From the fish shell documentation:

Initialization files On startup, fish evaluates the files /usr/share/fish/ (Or /usr/local/fish... if you installed fish in /usr/local), /etc/fish/ (Or ~/etc/fish/... if you installed fish in your home directory) and ~/.config/fish/ (Or any other directory specified by the $XDG_CONFIG_HOME variable), in that order. The first file should not be directly edited, the second one is meant for systemwide configuration and the last one is meant for user configuration. If you want to run a command only on starting an interactive shell, use the exit status of the command 'status --is-interactive' to determine if the shell is interactive. If you want to run a command only when using a login shell, use 'status --is-login' instead.


If you want to add the directory ~/linux/bin to your PATH variable when using a login shell, add the following to your ~/.config/fish/ file:

if status --is-login set PATH $PATH ~/linux/bin end

If you want to run a set of commands when fish exits, use an event handler that is triggered by the exit of the shell:

function on_exit --on-process %self echo fish is now exiting end

Universal variables are stored in the file .config/fish/fishd.HOSTNAME, where HOSTNAME is the name of your computer. Do not edit this file directly, edit them through fish scripts or by using fish interactively instead.

So, you should edit the ~/.config/fish/, logout (or re-source the and finally you should have your "custom bindings".

I kindly advice you to read the whole documentation and play a bit whit the shell, nothing that I wrote here doesn't come from the doc.

Then, if it doesn't work, come back here with logs (whenever available), config files, debug output and so forth.

share|improve this answer
at first i put just bind \eg appendgrep to and it didn't work. second try was to put also the function in the file like this function appendgrep commandline -i -- "| grep \"" end but this also make no difference and doesn't work. – NES Jan 4 '11 at 23:13
however, the defined functions via the functions directory seems to be persistent and are still available after closing terminal window and opening it. although they doesn't appear in the bind -f output. perhaps are there any differences that function need to be global or so? – NES Jan 4 '11 at 23:21
Update: There shouldn't be no problem to use the bind commandline in the file as you also suggested, because it works in shell. However, will try to find the solution and put the answer in here, when i find out. i guess it can be also related to this question – NES Jan 5 '11 at 13:23
I've a couple of doubts... 1. Use readline to be sure you are correctly mapping the Alt-keys combinations. 2. Maybe fish is not reading the fish.config, so try to edit the system ones /etc/fish/ and /usr/share/fish/ . Look for strange conf parameters and add your function if needed. – tmow Jan 5 '11 at 13:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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