简体   繁体   English

终端命令行快速导航

[英]Terminal command line quick navigation

I would like to move between the command line arguments in a fast way. 我想快速地在命令行参数之间移动。 For example, if I have the following command line: 例如,如果我有以下命令行:

> do_something_with /very_long_path/to_a_very_long_directory/ more_args
                    ^                                       ^    

I would like to skip the whole path (jump between the ^ symbols). 我想跳过整个路径(在^符号之间跳转)。 I'm already familiar with word mode (Alt+B and Alt+F) but in some scenarios it's not enough to navigate quickly between the arguments. 我已经很熟悉单词模式(Alt + B和Alt + F),但是在某些情况下,在参数之间快速导航是不够的。

In bash, you can set the cursor to the previous given character using the following features: 在bash中,可以使用以下功能将光标设置为上一个给定的字符:

character-search and character-search-backward features. character-searchcharacter-search-backward character-search character-search-backward功能。

ctrl + ] , (resp. alt + ctrl + ] ) + searched_character Ctrl + ] ,(分别是alt + Ctrl + ] )+ searched_character

In your example, you can search backward for a space. 在您的示例中,您可以向后搜索空格。

> do_something_with /very/long/path/\ with_spaces\ directory/ more_args
                 ^                                        ^

Unfortunately, this will not work so well with paths like: 不幸的是,这不适用于以下路径:

> do_something_with /very_\ long_path/to_a_\ very_long_directory/ more_args

As a sidenote, you can use ctrl + a and ctrl + e to go at the beginning / end of a line. 作为旁注,您可以使用ctrl + actrl + e在行的开头/结尾。

There are (quote from manual ) 有(引自手册

 shell-forward-word () 

Move forward to the end of the next word. 前进到下一个单词的末尾。 Words are delimited by non-quoted shell metacharacters. 单词由不带引号的外壳元字符定界。

and

 shell-backward-word () 

Move back to the start of the current or previous word. 移回当前或上一个单词的开头。 Words are delimited by non-quoted shell metacharacters. 单词由不带引号的外壳元字符定界。

I have bound them to Ctrl + Alt + F and Ctrl + Alt + B by adding this to my .inputrc : 通过将其添加到我的.inputrc ,我将它们绑定到Ctrl + Alt + FCtrl + Alt + B

"\e\C-f": shell-forward-word
"\e\C-b": shell-backward-word

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM