macos Mac OS X 终端:将选项+删除映射到“向后删除单词”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/327664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac OS X Terminal: Map option+delete to "backward delete word"
提问by ibz
Tried to map it from Preferences -> Settings -> Keyboard, but the "key" combo box has only "forward delete" but no "delete". My keyboard on the other hand has only "delete" and no "forward delete"!
试图从首选项 -> 设置 -> 键盘映射它,但“键”组合框只有“向前删除”而没有“删除”。另一方面,我的键盘只有“删除”而没有“向前删除”!
Is there some other way to do it except from the preferences?
除了偏好之外,还有其他方法可以做到吗?
回答by Andru Luvisi
Enable option key as meta key
启用选项键作为元键
- Go to
Terminal
>Preferences
>Profiles
>Keyboard
- Check
Use option key as meta key
.
- 前往
Terminal
>Preferences
>Profiles
>Keyboard
- 检查
Use option key as meta key
。
Image
图片
On macOS High Sierra 10.13.6, captured on October 23, 2018.
在 macOS High Sierra 10.13.6 上,拍摄于 2018 年 10 月 23 日。
Notes
笔记
Many applications (including bash and tcsh) treat Meta-Delete as "backward delete word."
许多应用程序(包括 bash 和 tcsh)将 Meta-Delete 视为“向后删除字”。
回答by nadafigment
OS X's terminal runs bash, which includes readline support. Follow Glomek's advice and tell terminal to use option as meta key (or else use Esc) and then you've got a bunch of handy options: Ctrl+wdeletes prev word (as does Meta+delete as mentioned), but you can also use Meta+f and Meta+b to walk forward and backwards thru words, Ctrl+aand Ctrl+eto beginning and end of line, Ctrl+kdelete (kill) from cursor to end of line, and a bunch more.
OS X 的终端运行 bash,其中包括 readline 支持。遵循 Glomek 的建议并告诉终端使用 option 作为元键(或者使用Esc),然后你有一堆方便的选项:Ctrl+w删除上一个词(正如前面提到的 Meta+delete),但你也可以使用 Meta+ f 和 Meta+b 向前和向后遍历单词,Ctrl+a和Ctrl+e到行首和行尾,Ctrl+k从光标到行尾删除(杀死),等等。
See http://www.bigsmoke.us/readline/shortcutsfor a nice little reference table.
请参阅http://www.bigsmoke.us/readline/shortcuts以获得一个不错的小参考表。
回答by Shai
Delete a word going back:
删除一个词回去:
Ctr-w.
Ctrl-W。
回答by Dustin
By default meta backspace does a backwards word yank in most shells. If you press escape and then press backspace, that pretty much works everywhere.
默认情况下,元退格键在大多数 shell 中执行向后单词 yank。如果您按 Esc 键然后按退格键,这几乎可以在任何地方使用。
回答by Stephane Gasparini
?W
(control+W) is not the same thing than meta + delete (ESC+delete if you don't have checked use option as meta key)
meta+delete will treat / _
as word delimiter where ^W
will consider space as delimiter.
?W
(control+W) 与 meta + delete 不同(ESC+delete 如果您没有选中 use 选项作为元键) meta+delete 将/ _
视为单词分隔符,其中^W
将空格视为分隔符。
e.g. using ESC+Bakcspace on (cursor at the end)
例如使用 ESC+Bakcspace on(最后的光标)
rm /dira/dirb/file1
gives
给
rm /dira/dirb/
while ^W on the same will give
而 ^W 同样会给
rm
So it is better to use \033\177 rather than ^W when defining the modifying the terminal profile. That way you are really mapping ?? to what esc? is doing and you keep having ^W to erase word based on space delimiter.
所以在定义修改终端配置文件时最好使用\033\177而不是^W。这样你真的在映射??什么esc?正在做,并且您一直在使用 ^W 来根据空格分隔符擦除单词。
I would love to be able to post an image on how do this but as a newbies I can't.
我希望能够发布有关如何执行此操作的图像,但作为新手我不能。
refer to bouke comment to see how to modify terminal profile.
请参阅 bouke 评论以了解如何修改终端配置文件。
回答by Bouke
In your Terminal's profile, you can bind ?? (option+delete) to ?W (control+W), so it works similar to other apps.
在您的终端配置文件中,您可以绑定 ?? (option+delete) 到 ?W (control+W),所以它的工作方式类似于其他应用程序。
回答by Curtis M
Command Editing Shortcuts
命令编辑快捷键
Ctrl + a – go to the start of the command line
Ctrl + a – 转到命令行的开头
Ctrl + e – go to the end of the command line
Ctrl + e – 转到命令行末尾
Ctrl + k – delete from cursor to the end of the command line
Ctrl + k – 从光标处删除到命令行末尾
Ctrl + u – delete from cursor to the start of the command line
Ctrl + u – 从光标处删除到命令行的开头
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + w – 从光标到词首删除(即向后删除一个词)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + y – 在光标后粘贴使用其中一种删除快捷方式(例如上面的一种)剪切的单词或文本
Ctrl + xx – move between start of command line and current cursor position (and back again)
Ctrl + xx – 在命令行开头和当前光标位置之间移动(然后再返回)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + b – 向后移动一个单词(或转到光标当前所在单词的开头)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + f – 向前移动一个词(或移动到光标当前所在的词尾)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + d – 从光标处删除到词尾(如果光标位于词首,则为整个词)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – 从光标处开始大写到单词的结尾(如果光标位于单词的开头,则为整个单词)
Alt + u – make uppercase from cursor to end of word
Alt + u – 从光标到词尾大写
Alt + l – make lowercase from cursor to end of word
Alt + l – 从光标到词尾小写
Alt + t – swap current word with previous
Alt + t – 将当前单词与上一个单词交换
Ctrl + f – move forward one character
Ctrl + f – 向前移动一个字符
Ctrl + b – move backward one character
Ctrl + b – 向后移动一个字符
Ctrl + d – delete character under the cursor
Ctrl + d – 删除光标下的字符
Ctrl + h – delete character before the cursor
Ctrl + h – 删除光标前的字符
Ctrl + t – swap character under cursor with the previous one
Ctrl + t – 将光标下的字符与前一个字符交换
Command Recall Shortcuts
命令调用快捷方式
Ctrl + r – search the history backwards
Ctrl + r – 向后搜索历史
Ctrl + g – escape from history searching mode
Ctrl + g – 退出历史搜索模式
Ctrl + p – previous command in history (i.e. walk back through the command history)
Ctrl + p – 历史中的上一个命令(即返回命令历史)
Ctrl + n – next command in history (i.e. walk forward through the command history) Alt + . – use the last word of the previous command
Ctrl + n – 历史中的下一个命令(即向前浏览命令历史) Alt + . – 使用上一个命令的最后一个字
Command Control Shortcuts
命令控制快捷键
Ctrl + l – clear the screen
Ctrl + l – 清屏
Ctrl + s – stops the output to the screen (for long running verbose command)
Ctrl + s – 停止输出到屏幕(对于长时间运行的详细命令)
Ctrl + q – allow output to the screen (if previously stopped using command above)
Ctrl + q – 允许输出到屏幕(如果之前停止使用上面的命令)
Ctrl + c – terminate the command
Ctrl + c – 终止命令
Ctrl + z – suspend/stop the command
Ctrl + z – 暂停/停止命令
Bash Bang (!) Commands Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
Bash Bang (!) 命令 Bash 还有一些使用 ! (bang) 允许你用 bash 命令做一些时髦的事情。
!! – run last command !blah – run the most recent command that starts with ‘blah' (e.g. !ls)
!! – 运行最后一个命令!blah – 运行以“blah”开头的最新命令(例如!ls)
!blah:p – print out the command that !blah would run (also adds it as the latest command in the command history)
!blah:p – 打印出 !blah 将运行的命令(还将其添加为命令历史记录中的最新命令)
!$ – the last word of the previous command (same as Alt + .)
!$ – 上一个命令的最后一个单词(与 Alt + . 相同)
!$:p – print out the word that !$ would substitute
!$:p – 打印出 !$ 将替代的单词
!* – the previous command except for the last word (e.g. if you type ‘_find somefile.txt /', then !* would give you ‘_find somefile.txt')
!* – 除了最后一个单词之外的前一个命令(例如,如果你输入“_find somefile.txt /”,那么 !* 会给你“_find somefile.txt”)
!:p – print out what !would substitute
!:p – 打印出什么!会替代
回答by Anthony Artemiev
With Natural Text Editing
preset enabled in Profile -> Keys.
You can simply remove the word
随着Natural Text Editing
>键-预设的配置文件中启用。你可以简单地删除这个词
- Backward with
alt + delete
- Forward with
fn + alt + delete
- 落后与
alt + delete
- 转发与
fn + alt + delete