您的位置:首页 > 运维架构 > Linux

How to Navigate Linux Command Line Using Keybinding (Linux Ctrl Command Examples)

2015-02-10 21:54 477 查看


How to Navigate Linux Command Line Using Keybinding (Linux Ctrl Command Examples)

by AARON TABOR on MAY
12, 2014

Tweet

A keybinding is simply the mapping of a specific key combination to an action.

Keybindings that we are all familiar with outside of the command line environment are things like:
Control-c: copies selected text
Control-v: pastes copied text

In this tutorial, we’ll take a look at some of the default keybindings provided in the command line environment (and also where to look if you forget one).

There are many keybindings available by default when working in the Linux command line to make navigation and editing much easier. They are powered by a tool called Readline.

Here are few I often use (If you are familiar with the Emacs editor, you will likely see similarities):


Movement Keybindings

The following keybindings are used for movements:
KeybindingDescription
Control-aPosition cursor at the start of the line
Control-ePosition the cursor after the last character of the line
Control-fMove the cursor forward by one character (same behaviour as the arrow key)
Control-bMove the cursor backwards by one character (same behaviour as the arrow key)


Deletion Keybindings

The following keybindings are used for deletions:
KeybindingDescription
Control-kDelete all text after (and including) cursor
Control-uDelete all text before (not including) cursor
Control-wDelete immediate WORD before cursor (a WORD is a sequence of any consecutive non-whitespace characters)
Control-hDelete char before cursor (think backspace)
Control-dWhen text exist => delete char under cursor (think delete). When no text => exit shell


History Keybindings

The following keybindings are used for history:

KeybindingDescription
Control-pCycle to previous command
Control-nCycle to next command
Control-rReverse index search (allows you to type part of a command. searches in reverse order through command history for a matching command)


Misc Keybindings

The following are few misc keybindings:
KeybindingDescription
Control-lClear display (similar to ‘clear’ command)
Control-jExecute current command (same as Enter/Return)
Control-cCancel current command, return empty prompt
Control-/Redo the last undone edit
Control-?Undo the last edit
.

To see a full list currently bound and available keybindings and functions use the ‘bind’ command (this is a good quick reference when you forget one):
$ bind -p


You’ll see output that looks something like this:
"\C-g": abort
"\C-x\C-g": abort
"\e\C-g": abort
"\C-j": accept-line
…


The format here is:
key combination: binding


Please note that you’ll use the same format to define your own custom keybindings.

Remember that you can use grep to find the bindings you are interested in.

For example, to see only the binding that use the Control key:
$ bind -p | grep '\\C'


Note: In the above command, I’ve got to escape the backslash (\) character in the grep string.

Tweet

Add your comment


If you enjoyed this article, you might also like..

50 Linux Sysadmin Tutorials
50 Most Frequently Used Linux Commands (With Examples)
Top 25 Best Linux Performance Monitoring and Debugging Tools
Mommy, I found it! – 15 Practical Linux Find Command Examples
Linux 101 Hacks 2nd Edition eBook 


Awk Introduction – 7 Awk Print Examples
Advanced Sed Substitution Examples
8 Essential Vim Editor Navigation Fundamentals
25 Most Frequently Used Linux IPTables Rules Examples
Turbocharge PuTTY with 12 Powerful Add-Ons








Tags: Bind Command Examples

{ 11 comments… read them below or add
one }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  keybinding