When inputing multiline script in fish shell, e.g. I have input these script
$ for file in *.txt
echo $file
end
Run Code Online (Sandbox Code Playgroud)
and my caret is after the word end
. Now I want to insert a line before it, make it like:
$ for file in *.txt
echo $file
echo "hello" // I want to insert this line
end
Run Code Online (Sandbox Code Playgroud)
But I found if I move my caret up and after echo $file
, and press enter
(or cmd/option/ctrl+enter
), it just run the entire script without inserting a new line. I have to copy them to another editor and copy back after editing.
Is there any way to do it?
Update:
I just uploaded a screen recording https://asciinema.org/a/i7pOWhpdXUu0RLVOAMjVJTXbn. In the recording, I moved my caret up to after echo
and pressed option + enter
, but it executed the script instead of inserting a new line
在默认绑定中,Alt-Enter 将始终插入新行:
> bind|fgrep \\n
bind \e\n commandline\ -i\ \\n
bind \e\r commandline\ -i\ \\n
...
Run Code Online (Sandbox Code Playgroud)
根据您的系统配置,Enter/Return 键可能会发送换行符 ( \n
) 或回车符 ( \r
),因此这就是有两个条目的原因。
fish 绑定转义 + 换行符以无条件插入换行符。在 Mac 上,您通常会按选项 + 返回。但是 Mac 终端模拟器默认不发送转义换行符。使用 iTerm2,您可以在 Preferences->Profiles->Keys 下请求该选项作为转义:
现在绑定将处于活动状态并且 option-return 将无条件地插入换行符。
(如果您愿意,您可以为这种情况添加一个键映射。)
您可以确认终端从fish_key_reader
安装在 fish 旁边的模拟器接收到什么。