Bash: delete word ahead of cursor Announcing the arrival of Valued Associate #679: Cesar...

Is there a service that would inform me whenever a new direct route is scheduled from a given airport?

What would be the ideal power source for a cybernetic eye?

How to motivate offshore teams and trust them to deliver?

What is the musical term for a note that continously plays through a melody?

Should gear shift center itself while in neutral?

How to recreate this effect in Photoshop?

Disable hyphenation for an entire paragraph

When to stop saving and start investing?

Storing hydrofluoric acid before the invention of plastics

Can Pao de Queijo, and similar foods, be kosher for Passover?

"Seemed to had" is it correct?

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How to bypass password on Windows XP account?

How much radiation do nuclear physics experiments expose researchers to nowadays?

The logistics of corpse disposal

What are the motives behind Cersei's orders given to Bronn?

I am not a queen, who am I?

How do I determine if the rules for a long jump or high jump are applicable for Monks?

Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?

Does surprise arrest existing movement?

How to assign captions for two tables in LaTeX?

How can I make names more distinctive without making them longer?

Can a non-EU citizen traveling with me come with me through the EU passport line?



Bash: delete word ahead of cursor



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Bash: delete from cursor till end of line with a keyboard shortcutDelete characters from cursor up to the beginningTerminal word navigation/deletionCursor positioning using mouse in bash possible?bash - wrong answer by word count commandBash: what is the meaning of ${parameter##word}Moving to a word in bash in Emacs modeDelete lines with a word using sedHow can I delete from cursor to start in terminal (delete, not cut)How to delete bash history for specific date range





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







67















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?










share|improve this question




















  • 2





    Ctrl u is an option for erasing from cursor location to beginning...

    – nutty about natty
    Apr 8 '13 at 15:23






  • 23





    Try alt + d, that might be useful, when emacs editing mode is set.

    – user76204
    Apr 8 '13 at 16:20













  • @Mik how do you enable emacs mode?

    – Adam Matan
    Apr 9 '13 at 9:00











  • @AdamMatan set -o emacs enables it, but it is usually the default; if not, you can put that line in .bashrc or .bash_aliases, then source the file or reload the terminal. However, then the shortcuts you may be used to in vi mode won't be available, although ones such as ctrl+c will because they are not Bash shortcuts.

    – user76204
    Apr 9 '13 at 9:25


















67















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?










share|improve this question




















  • 2





    Ctrl u is an option for erasing from cursor location to beginning...

    – nutty about natty
    Apr 8 '13 at 15:23






  • 23





    Try alt + d, that might be useful, when emacs editing mode is set.

    – user76204
    Apr 8 '13 at 16:20













  • @Mik how do you enable emacs mode?

    – Adam Matan
    Apr 9 '13 at 9:00











  • @AdamMatan set -o emacs enables it, but it is usually the default; if not, you can put that line in .bashrc or .bash_aliases, then source the file or reload the terminal. However, then the shortcuts you may be used to in vi mode won't be available, although ones such as ctrl+c will because they are not Bash shortcuts.

    – user76204
    Apr 9 '13 at 9:25














67












67








67


11






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?










share|improve this question
















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?







command-line bash shortcut-keys






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 8 '13 at 15:17







Adam Matan

















asked Apr 8 '13 at 15:12









Adam MatanAdam Matan

4,924195887




4,924195887








  • 2





    Ctrl u is an option for erasing from cursor location to beginning...

    – nutty about natty
    Apr 8 '13 at 15:23






  • 23





    Try alt + d, that might be useful, when emacs editing mode is set.

    – user76204
    Apr 8 '13 at 16:20













  • @Mik how do you enable emacs mode?

    – Adam Matan
    Apr 9 '13 at 9:00











  • @AdamMatan set -o emacs enables it, but it is usually the default; if not, you can put that line in .bashrc or .bash_aliases, then source the file or reload the terminal. However, then the shortcuts you may be used to in vi mode won't be available, although ones such as ctrl+c will because they are not Bash shortcuts.

    – user76204
    Apr 9 '13 at 9:25














  • 2





    Ctrl u is an option for erasing from cursor location to beginning...

    – nutty about natty
    Apr 8 '13 at 15:23






  • 23





    Try alt + d, that might be useful, when emacs editing mode is set.

    – user76204
    Apr 8 '13 at 16:20













  • @Mik how do you enable emacs mode?

    – Adam Matan
    Apr 9 '13 at 9:00











  • @AdamMatan set -o emacs enables it, but it is usually the default; if not, you can put that line in .bashrc or .bash_aliases, then source the file or reload the terminal. However, then the shortcuts you may be used to in vi mode won't be available, although ones such as ctrl+c will because they are not Bash shortcuts.

    – user76204
    Apr 9 '13 at 9:25








2




2





Ctrl u is an option for erasing from cursor location to beginning...

– nutty about natty
Apr 8 '13 at 15:23





Ctrl u is an option for erasing from cursor location to beginning...

– nutty about natty
Apr 8 '13 at 15:23




23




23





Try alt + d, that might be useful, when emacs editing mode is set.

– user76204
Apr 8 '13 at 16:20







Try alt + d, that might be useful, when emacs editing mode is set.

– user76204
Apr 8 '13 at 16:20















@Mik how do you enable emacs mode?

– Adam Matan
Apr 9 '13 at 9:00





@Mik how do you enable emacs mode?

– Adam Matan
Apr 9 '13 at 9:00













@AdamMatan set -o emacs enables it, but it is usually the default; if not, you can put that line in .bashrc or .bash_aliases, then source the file or reload the terminal. However, then the shortcuts you may be used to in vi mode won't be available, although ones such as ctrl+c will because they are not Bash shortcuts.

– user76204
Apr 9 '13 at 9:25





@AdamMatan set -o emacs enables it, but it is usually the default; if not, you can put that line in .bashrc or .bash_aliases, then source the file or reload the terminal. However, then the shortcuts you may be used to in vi mode won't be available, although ones such as ctrl+c will because they are not Bash shortcuts.

– user76204
Apr 9 '13 at 9:25










2 Answers
2






active

oldest

votes


















51














I answered similar question on unix.stackexchange.com:




Bash has readline commands that aren't bound by default. You can find
them at reference:
http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands



Command you are looking for is called "shell-backward-kill-word". You
have to select shortcut first. Let's use Crtl+p, since it's "previous
command" - same as up arrow.



bind '"C-p": shell-backward-kill-word'



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.






share|improve this answer





















  • 24





    Alt-d works for me

    – ricab
    Jan 20 '15 at 14:24






  • 8





    Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

    – Nate C-K
    Mar 20 '15 at 3:49













  • I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

    – tripleee
    Nov 30 '15 at 18:03






  • 1





    In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

    – user964970
    Jul 6 '17 at 10:17



















6














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






share|improve this answer





















  • 12





    Option + d gives me ∂ on OSX

    – Ivan Balashov
    Apr 16 '16 at 7:35






  • 3





    -1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

    – wjandrea
    Sep 24 '16 at 16:37











  • you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

    – nils petersohn
    Apr 23 '18 at 16:15











  • control + d on mac Sierra

    – mfink
    Aug 9 '18 at 17:42






  • 1





    @IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

    – tessie
    Nov 27 '18 at 13:09












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f279254%2fbash-delete-word-ahead-of-cursor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









51














I answered similar question on unix.stackexchange.com:




Bash has readline commands that aren't bound by default. You can find
them at reference:
http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands



Command you are looking for is called "shell-backward-kill-word". You
have to select shortcut first. Let's use Crtl+p, since it's "previous
command" - same as up arrow.



bind '"C-p": shell-backward-kill-word'



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.






share|improve this answer





















  • 24





    Alt-d works for me

    – ricab
    Jan 20 '15 at 14:24






  • 8





    Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

    – Nate C-K
    Mar 20 '15 at 3:49













  • I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

    – tripleee
    Nov 30 '15 at 18:03






  • 1





    In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

    – user964970
    Jul 6 '17 at 10:17
















51














I answered similar question on unix.stackexchange.com:




Bash has readline commands that aren't bound by default. You can find
them at reference:
http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands



Command you are looking for is called "shell-backward-kill-word". You
have to select shortcut first. Let's use Crtl+p, since it's "previous
command" - same as up arrow.



bind '"C-p": shell-backward-kill-word'



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.






share|improve this answer





















  • 24





    Alt-d works for me

    – ricab
    Jan 20 '15 at 14:24






  • 8





    Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

    – Nate C-K
    Mar 20 '15 at 3:49













  • I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

    – tripleee
    Nov 30 '15 at 18:03






  • 1





    In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

    – user964970
    Jul 6 '17 at 10:17














51












51








51







I answered similar question on unix.stackexchange.com:




Bash has readline commands that aren't bound by default. You can find
them at reference:
http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands



Command you are looking for is called "shell-backward-kill-word". You
have to select shortcut first. Let's use Crtl+p, since it's "previous
command" - same as up arrow.



bind '"C-p": shell-backward-kill-word'



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.






share|improve this answer















I answered similar question on unix.stackexchange.com:




Bash has readline commands that aren't bound by default. You can find
them at reference:
http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands



Command you are looking for is called "shell-backward-kill-word". You
have to select shortcut first. Let's use Crtl+p, since it's "previous
command" - same as up arrow.



bind '"C-p": shell-backward-kill-word'



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.







share|improve this answer














share|improve this answer



share|improve this answer








edited 9 mins ago









Pablo Bianchi

3,13521836




3,13521836










answered Apr 10 '13 at 16:04









NykakinNykakin

3,0151217




3,0151217








  • 24





    Alt-d works for me

    – ricab
    Jan 20 '15 at 14:24






  • 8





    Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

    – Nate C-K
    Mar 20 '15 at 3:49













  • I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

    – tripleee
    Nov 30 '15 at 18:03






  • 1





    In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

    – user964970
    Jul 6 '17 at 10:17














  • 24





    Alt-d works for me

    – ricab
    Jan 20 '15 at 14:24






  • 8





    Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

    – Nate C-K
    Mar 20 '15 at 3:49













  • I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

    – tripleee
    Nov 30 '15 at 18:03






  • 1





    In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

    – user964970
    Jul 6 '17 at 10:17








24




24





Alt-d works for me

– ricab
Jan 20 '15 at 14:24





Alt-d works for me

– ricab
Jan 20 '15 at 14:24




8




8





Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

– Nate C-K
Mar 20 '15 at 3:49







Generally, in the world of keyboards where Meta doesn't exist, Alt = Meta.

– Nate C-K
Mar 20 '15 at 3:49















I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

– tripleee
Nov 30 '15 at 18:03





I the world where you have many different keyboards, a convenient and fairly useful fact is that Esc as a prefix also acts as Meta.

– tripleee
Nov 30 '15 at 18:03




1




1





In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

– user964970
Jul 6 '17 at 10:17





In short, add e.g. this to your $HOME/.inputrc file:"ew": shell-kill-word , that will make Alt-w forward delete a word , much like CTRL-w backwards deletes a word (and unlike Alt-d which will forward delete but stop at e.g. a / or - and other characters)

– user964970
Jul 6 '17 at 10:17













6














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






share|improve this answer





















  • 12





    Option + d gives me ∂ on OSX

    – Ivan Balashov
    Apr 16 '16 at 7:35






  • 3





    -1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

    – wjandrea
    Sep 24 '16 at 16:37











  • you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

    – nils petersohn
    Apr 23 '18 at 16:15











  • control + d on mac Sierra

    – mfink
    Aug 9 '18 at 17:42






  • 1





    @IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

    – tessie
    Nov 27 '18 at 13:09
















6














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






share|improve this answer





















  • 12





    Option + d gives me ∂ on OSX

    – Ivan Balashov
    Apr 16 '16 at 7:35






  • 3





    -1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

    – wjandrea
    Sep 24 '16 at 16:37











  • you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

    – nils petersohn
    Apr 23 '18 at 16:15











  • control + d on mac Sierra

    – mfink
    Aug 9 '18 at 17:42






  • 1





    @IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

    – tessie
    Nov 27 '18 at 13:09














6












6








6







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 30 '15 at 19:39









Gayan Weerakutti

1,9441428




1,9441428










answered Nov 30 '15 at 16:24









visyoualvisyoual

7713




7713








  • 12





    Option + d gives me ∂ on OSX

    – Ivan Balashov
    Apr 16 '16 at 7:35






  • 3





    -1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

    – wjandrea
    Sep 24 '16 at 16:37











  • you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

    – nils petersohn
    Apr 23 '18 at 16:15











  • control + d on mac Sierra

    – mfink
    Aug 9 '18 at 17:42






  • 1





    @IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

    – tessie
    Nov 27 '18 at 13:09














  • 12





    Option + d gives me ∂ on OSX

    – Ivan Balashov
    Apr 16 '16 at 7:35






  • 3





    -1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

    – wjandrea
    Sep 24 '16 at 16:37











  • you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

    – nils petersohn
    Apr 23 '18 at 16:15











  • control + d on mac Sierra

    – mfink
    Aug 9 '18 at 17:42






  • 1





    @IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

    – tessie
    Nov 27 '18 at 13:09








12




12





Option + d gives me ∂ on OSX

– Ivan Balashov
Apr 16 '16 at 7:35





Option + d gives me ∂ on OSX

– Ivan Balashov
Apr 16 '16 at 7:35




3




3





-1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

– wjandrea
Sep 24 '16 at 16:37





-1 OSX is not Ubuntu. Feel free to add a comment, but this is not an answer.

– wjandrea
Sep 24 '16 at 16:37













you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

– nils petersohn
Apr 23 '18 at 16:15





you have to first enable the checkbox "use option as meta key" in the terminal preferences (profiles -> keyboard tab -> checkbox)

– nils petersohn
Apr 23 '18 at 16:15













control + d on mac Sierra

– mfink
Aug 9 '18 at 17:42





control + d on mac Sierra

– mfink
Aug 9 '18 at 17:42




1




1





@IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

– tessie
Nov 27 '18 at 13:09





@IvanBalashov if you are using iterm set your let opt key as esc+ . Under Profiles >keys

– tessie
Nov 27 '18 at 13:09


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f279254%2fbash-delete-word-ahead-of-cursor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Is there a lightweight tool to crop images quickly?Cropping Images using Command Line Tools OnlyHow to crop...

List of shipwrecks in 1808...

Unit packagekit.service is masked Announcing the arrival of Valued Associate #679: Cesar...