Answers:
用大炮杀死苍蝇:
然后,您可以使用向后移动一个字Option ⌥+ ←和使用单词向前Option ⌥+ →,移动到使用线路的起点fn+ ←,并与行的末尾fn+ →。您也可以删除向后用字Option ⌥+ ⌫,使用删除整行Command ⌘+ ⌫。
如果没有出现预设,请重新安装iTerm2。如果使用Homebrew + Cask安装它:
brew cask reinstall iterm2
我喜欢以下设置。
向前移动一个字
option+right
send escape sequence
f
后退一个字
option+left
send escape sequence
b
删除到单词的开头(信用)
option+delete
send hex code
0x1B 0x08
删除到字尾
fn+option+delete
send escape sequence
d
(我不确定是否记得,但是我想我从下面的jherran答案中复制了此答案并添加了更多内容。我应该在该答案的注释或建议的编辑中添加额外的信息。我不知道如何改进情况,但现在知道了。)
您可以将终端设置为vi模式,set -o vi
以便能够使用通常的vi运动命令(在其中添加行.bash_profile
以永久存储设置。)
因此,就像在vi中一样,您可以按Esc
,然后b
向后移动一个单词(w
表示向前),使用转到行的开头0
,或者使用F
+ 字符向后搜索一个字符。
点击i
返回普通模式并插入。
那些熟悉vi的人可以做更多的事情。备忘单可以在这里找到。
Esc
然后点击I
一次仅行至行首比Ctrl-a
这要方便一些-这种用例通常在您只想修改命令名称时发生。所以我在vi模式下使用iTerm2中的一些键绑定更改来映射Ctrl-A
并类似于转义序列Esc+0
。这样,在编辑模式下结束时,这些情况甚至更快。
打开首选项
配置向左(和/或)向右选项键发送Esc +
如果您弄乱了预设,则可能需要加载默认预设(请注意,这可能会擦掉您的自定义按键绑定!)
如果执行此操作后看到奇怪的字符,则可能需要配置〜/ .inputrc或/ etc / inputrc
将此添加到您的〜/ .inputrc中:
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
完整的示例inputrc:
# /etc/inputrc - global inputrc for libreadline
# See readline(3readline) and `info rluserman' for more information.
# Be 8 bit clean.
set input-meta on
set output-meta on
# To allow the use of 8bit-characters like the german umlauts, uncomment
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.
# set convert-meta off
# try to enable the application keypad when it is called. Some systems
# need this to enable the arrow keys.
# set enable-keypad on
# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys
# do not bell on tab-completion
# set bell-style none
# set bell-style visible
# some defaults / modifications for the emacs mode
$if mode=emacs
# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert
# mappings for "page up" and "page down" to step to the beginning/end
# of the history
# "\e[5~": beginning-of-history
# "\e[6~": end-of-history
# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward
# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
$if term=rxvt
"\e[7~": beginning-of-line
"\e[8~": end-of-line
"\eOc": forward-word
"\eOd": backward-word
$endif
# for non RH/Debian xterm, can't hurt for RH/Debian xterm
# "\eOH": beginning-of-line
# "\eOF": end-of-line
# for freebsd console
# "\e[H": beginning-of-line
# "\e[F": end-of-line
$endif
使用iTerm2 3.1.4,我可以设置以下内容而无需添加单独的键映射。
通过新的终端会话,您现在可以使用:
Option ⌥+ f前进
Option ⌥+ b前进
Option ⌥+ Delete ⌫删除单词