开发工具 OS X 下的 iTerm 2 如何让 cursor 跳字移动?

artone · 2012年10月17日 · 最后由 kbrx93 回复于 2018年03月16日 · 9507 次阅读

编辑器可以用 alt + 左右键,在单字之间移动,可是在 iTerm 中貌似会触发到快捷键,有其他方法吗?

# ~/.inputrc

## Key binding
# @see `bind -p`
# @format "key": command
$if mode=emacs # find the keyboard preference in mac terminal
    "\e[3~":              delete-char             # del
    "\e[1~":              beginning-of-line       # home
    "\e[4~":              end-of-line             # end
    "\x1B\x1B\x5B\x44":   backward-word           # opt + left
    "\x1B\x1B\x5B\x43":   forward-word            # opt + right
    "\e[B":               history-search-forward  # down
    "\e[A":               history-search-backward # up
    # no magic-space. not working in postgres console
    #Space:                magic-space
$endif

#1 楼 @chentianwen 看不明白,能不能说明一下?感谢。

在~/.inputrc 中加入:

"\e[1;9D": backward-word "\e[1;9C": forward-word

http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2

#3 楼 @yangyanhao 谢谢,我来研究一下。

我的方案主要是编辑 iTerm profile 里的快捷键

右移一个词:opt + 右 send escape sequence f 左移一个词:opt + 左 send escape sequence b 左删一个词:opt + del send escape sequence 007f (用 unicode 输入法,按住 opt 的同时输入 007f,字符不显示)

行首和行末复杂点,先要把原本 cmd + 左/右 的快捷键解绑,然后

行首:cmd + 左 send escape sequence OH 行末:cmd + 右 send escape sequence OF

如果用 bash, 修改 ~/.inputrc

"\e[1~": beginning-of-line
"\e[4~": end-of-line

如果用 zsh:

bindkey "^[OH" beginning-of-line
bindkey "^[OF" end-of-line

还有一种方案可以启用 CLI 的 vim 模式,如果熟 vim 的话会很爽。

@luikore 的建议很不错

alt+b, alt+f ?

最后我的方法是改成这样:

alt + 右则是改成 Esc + f,跟 @luikore 应该是同个方法。

@luikore 007f 那个始终不行,求教详细设置方法

#10 楼 @mike

要先切换到 Unicode 16 进位输入,没有这输入法的话要去 preference 勾选,然后切换过去。

开启 iTerm 如我上图,在 Esc + 那个栏位,压著 alt + 007f,要压著一起打,成功输进去的话 placeholder 应该要消失,这个时候在 iTerm 里试试,alt + delete 应该可行的。

esc + f ,esc + b

#2 楼 @artone That's the example file of inputrc, you don't need to change the iterm2 or terminal configuration.

#6 楼 @nightire 这个怎么开启?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号