Skip to content

Instantly share code, notes, and snippets.

@srcrip
Created November 26, 2017 19:38
Show Gist options
  • Save srcrip/47b3e9b7b0b1a10c1429c824fbf79d87 to your computer and use it in GitHub Desktop.
Save srcrip/47b3e9b7b0b1a10c1429c824fbf79d87 to your computer and use it in GitHub Desktop.
Edit command line in Fish
# thanks to github.com/oh-my-fish/theme-budspencer
# Set the tmp file
set -g tmpcmdline '/tmp/'(echo %self)'_cmdline.fish'
function edit_commandline -d 'Open current command line with your editor'
commandline > $tmpcmdline
eval $EDITOR $tmpcmdline
set -l IFS ''
if [ -s $tmpcmdline ]
commandline (sed 's|^\s*||' $tmpcmdline)
else
commandline ''
end
rm $tmpcmdline
end
# Your fish_user_key_bindings function will look different. Make sure to ADD the line:
# bind \ci 'edit_commandline'
# and replace it with the binding of your choice. You can't have multiple fish_user_key_bindings
# functions because they will overwrite.
# I made examples for vi_mode and non vi_mode use.
# Use without vi_mode
function fish_user_key_bindings
bind \ci 'edit_commandline' # Uses C-i, but it could be whatever you want.
end
# Use with vi_mode
function fish_user_key_bindings
set fish_key_bindings fish_vi_key_bindings
bind . 'edit_commandline' # Pressing . while in normal/command mode will enter $EDITOR. Insert mode is unaffected.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment