Bash: delete word ahead of cursor



" data-medium-file="" data-large-file="" src="" srcset=" 500w, 300w" sizes="(max-width: 350px) 100vw, 350px" data-recalc-dims="1">It may or may not surprise you to know that the bash shell has a very rich array of convenient shortcuts that can make your life, working with the command line, a whole lot easier. This ability to edit the command line using shortcuts is provided by the GNU Readline library. This library is used by many other *nix application besides bash, so learning some of these shortcuts will not only allow you to...
0 0

Consider the following bash prompt, where ^ denotes the prompt location:

svn commit -m very/long/path/to/some/file "[bug 123456] Fix the pixel issue" ^

I'd like to commit a different file with the same message. How can I delete the current word, from cursor location to the next space? Is there also a shortcut for backward deletion, form the cursor to the first space backwards?

Update: ctrl+w erases backwards, but which shortcut erases one word forward?

I answered similar question here:

The only difference is you have to use "shell-kill-word" command instead, since you want to delete forward.

There is also a "kill-word" command with Meta+d shortcut (try Esc+d if you don't have Meta key). It will delete only one part of path at once.

Tested both the esc+d and alt/opt+d on OSX Mavericks and they work there as...

0 0

If you spend a lot of time at the command line, you undoubtedly find yourself adjusting and editing text and commands, and you likely often need to move the cursor to a further position in the Terminal from where it’s actively located. Sure you can use the arrow keys to move left and right on a per-character basis, or you can use the handy put cursor at mouse position trick, but another option is to move the cursor position word by word in Terminal, skipping back or forward by entire word blocks rather than individual text characters.

There are a few ways to achieve this, but the easiest which requires no modifications to the Terminal uses a longstanding series of two different keyboard shortcuts:

Move Cursor Forward by Word in Terminal: Escape + F

Escape F moves the cursor forward a word at the command line.

Move Cursor Backward by Word in Terminal: Escape + B

Escape B moves the cursor backward by a word at the command...

0 0

So, you hate using a terminal? That might be, because you use the arrow keys to navigate character by character through a long command just to change a paramater at the other end of the line, right? Here's a list of my most-used bash & zsh shortcuts, that will definitely boost your productivity and will help you to improve your command line experience.

History Search

Press CTRL + R to search through the history. Continue pressing CTRL + R until you find the entry you're looking for. Press [ENTER] to execute the current expression. Press [Right Arrow] to modify the current expression. Press CTRL + G to escape from search mode.

Special setup for Mac OS X

Go to Terminal -> Preferences -> Settings -> Keyboard

To enable the use of the ALT or OPTION key, select use option as meta key To enable the CTRL + [left arrow] and CTRL + [right arrow] shortcuts, select control cursor left and set it to \033b and control cursor right and set it...
0 0

ANSI escape sequences allow you to move the cursor around the screen at will. This is more useful for full screen user interfaces generated by shell scripts, but can also be used in prompts. The movement escape sequences are as follows:

The latter two codes are NOT honoured by many terminal emulators. The only ones that I'm aware of that do are xterm and nxterm - even though the majority of terminal emulators are based on xterm code. As far as I can tell, rxvt, kvt, xiterm, and Eterm do not support them. They are supported on the console.

Try putting in the following line of code at the prompt (it's a little clearer what it does if the prompt is several lines down the terminal when you put this in): This should move the cursor seven lines up screen, print the word " BASH ", and then return to where it started to produce a normal prompt. This isn't a prompt: it's just a demonstration of moving the cursor on screen, using colour to emphasize what has been...

0 0
0 0

The bash and zsh shells are very similar, with zsh being more of a "power-house" shell than bash. Key commands for both shells are similar and knowing these time-saving shortcuts can be a great boon for those using the shell often. Most of these commands are used for quick navigation or editing of the current command line.

To move to the beginning of the current line, use [Ctrl][A]. To move to the end of the current line, use [Ctrl[E]. To move the cursor forward one word on the current line, use [Alt][F]; to move the cursor backwards one word on the current line, use [Alt][B].

You can also use key commands to do more than move around on the current line. They can be used to manipulate text on the current line as well. For instance, use [Ctrl][U] to clear the characters on the line before the current cursor position and [Ctrl][K] to clear the characters on the line after the current cursor position. Bash and zsh work slightly different here. In zsh, [Ctrl][U] clears...

0 0

Comments. Lines beginning with a (with the exception of ) are comments and will not be executed.

Comments may also occur following the end of a command.

Comments may also follow whitespace at the beginning of a line.

Comments may even be embedded within a pipe.

The standard quoting and escape characters (" ' \) escape the #.

Certain pattern matching operations also use the .

Command separator [semicolon]. Permits putting two or more commands on the same line.

Note that the "" sometimes needs to be escaped.

Terminator in a case option [double semicolon].


"dot", as a component of a filename. When working with filenames, a leading dot is the prefix of a "hidden" file, a file that an ls will not normally show.

When considering directory names, a single dot represents the current working directory, and two dots denote the parent directory.

The dot often appears as the ...

0 0
0 0