Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
22
votes
6
answers
19148
views
zsh kill Ctrl + Backspace, Ctrl + Delete
How to configure zsh such that Ctrl + Backspace kills the word before point? How to achieve that Ctrl + Delete kills the word after point? I use urxvt as terminal emulator.
How to configure zsh such that Ctrl+Backspace kills the word before point? How to achieve that Ctrl+Delete kills the word after point?
I use urxvt as terminal emulator.
student
(18865 rep)
May 7, 2011, 09:08 AM
• Last activity: Jul 25, 2025, 06:36 PM
1
votes
1
answers
1796
views
How to prevent zsh path completion magic until I press TAB?
I have a hobby server with a significant numbr of USB hard drives. I have aggressive power management enabled, and a short spin-down timeout, as these drives are basically meant to be cold storage with quick accessibility when needed. So most of them spend 99.9% of their time in APM standby until I...
I have a hobby server with a significant numbr of USB hard drives. I have aggressive power management enabled, and a short spin-down timeout, as these drives are basically meant to be cold storage with quick accessibility when needed. So most of them spend 99.9% of their time in APM standby until I need to access them, at which point they spin up, and for single drives I have access within ten seconds, for drives in RAID, up to 30 seconds.
The ZSH completion system is giving me headaches in this regard, since the arguably fantastic auto-completion magic it offers has some sort of automatic path validation going on as well, even when I don't press TAB, and even if I use my arrow keys to traverse the shell command history.
For instance, I can type
rsync
, then press the up key to start traversing the history for my previous rsync
commands, and immediately the completion magic starts to access filesystem paths in those commands to validate and do magic stuff on them. This not only causes huge pauses where zsh blocks and becomes unresponsive, it also spins up sleeping drives which increases wear on those spinners. Any paths to network mounts also cause delays due to their network nature.
It also kicks in while writing a path, with me just typing letters, slashes and wildcards.
I have found a lot of questions about similar gripes, [like this one](https://unix.stackexchange.com/questions/162078/stop-zsh-from-completing-parent-directories) , but I've yet to find something that addresses this precisely.
On the mentioned post above, there's a link to the zsh Completion System docs, and while reading them I find myself still confused. From the docs I'm not even sure what the syntax for zstyle
is, and I'm confused about a lot of the terminology.
Basically I'm just looking for a way to say to zsh, "listen mate, I love what you're doing, but could you wait with all you wonderful magic until I press TAB?"
FlamingKitties
(5029 rep)
Aug 26, 2022, 08:16 AM
• Last activity: May 9, 2025, 10:53 AM
1
votes
5
answers
862
views
How to transpose command line arguments with emacs keybindings?
Using Bash, with emacs keybindings set, the transpose-words keybinding (`M-t`) doesn't transpose arguments, but "words" (by its own definition of words). So if I have this: vimdiff project-number-One/Vagrantfile project-number-Two/Vagrantfile.old and my cursor is between the first and second argumen...
Using Bash, with emacs keybindings set, the transpose-words keybinding (
M-t
) doesn't transpose arguments, but "words" (by its own definition of words).
So if I have this:
vimdiff project-number-One/Vagrantfile project-number-Two/Vagrantfile.old
and my cursor is between the first and second argument when I enter optiont, I instead end up with
vimdiff project-number-One/project Vagrantfile-number-Two/Vagrantfile.old
which is obviously not what I want. How can I transpose arguments?
iconoclast
(9402 rep)
Oct 16, 2014, 06:29 PM
• Last activity: Dec 10, 2024, 08:46 AM
1
votes
1
answers
555
views
paste clipboard text plus string with .inputrc
I've got in my .inputrc something like "\C-v": "script.sh " I use a link from my clipboard as a parameter for the script, so I type ctrl-v and then paste the link, and then hit enter. So I've seen that you can use "paste-from-clipboard" to actually paste something. Is there a way to get this done al...
I've got in my .inputrc something like
"\C-v": "script.sh "
I use a link from my clipboard as a parameter for the script, so I type ctrl-v and then paste the link, and then hit enter.
So I've seen that you can use "paste-from-clipboard" to actually paste something.
Is there a way to get this done alltogether by .inputrc? Something like
"\C-v": "script.sh ", paste-from-clipboard, "\n"
strudelkopf
(145 rep)
Oct 3, 2015, 03:51 PM
• Last activity: Sep 20, 2024, 03:37 PM
27
votes
1
answers
14584
views
SQLite3 command line: how do you cancel a command?
I made a mistake writing a command at the SQLite command prompt, which I now want to abort, this is how my command line looks sqlite> select * from todos' ...> ' ...> ;^C In this case, likely because I have opened a quote, I can't even hit `ENTER` to run the command. I just get a line continuation,...
I made a mistake writing a command at the SQLite command prompt, which I now want to abort, this is how my command line looks
sqlite> select * from todos'
...> '
...> ;^C
In this case, likely because I have opened a quote, I can't even hit
ENTER
to run the command. I just get a line continuation, that would still be less than ideal because I would be having to run bad code and cause and error, just to regain control of the prompt.
How can I cancel the line/command and get returned back to a prompt?
the_velour_fog
(12760 rep)
Jun 21, 2016, 08:33 AM
• Last activity: Jul 11, 2024, 07:38 AM
6
votes
3
answers
5672
views
tcsh shortcut to move the cursor back to previous space
I'm looking for a keyboard shortcut in `tcsh` to move the cursor back to the previous blank: not ESC + B which takes me back one word (for instance, in a path argument, to the previous path component) - I want to get to previous space or start of current path.
I'm looking for a keyboard shortcut in
tcsh
to move the cursor back to the previous blank: not ESC+B which takes me back one word (for instance, in a path argument, to the previous path component) - I want to get to previous space or start of current path.
haimon
(63 rep)
May 7, 2013, 02:41 PM
• Last activity: May 10, 2024, 07:42 PM
25
votes
6
answers
3323
views
Bash command to copy before cursor and paste after?
I am not sure how to word this, but I often I find myself typing commands like this: cp /etc/prog/dir1/myconfig.yml /etc/prog/dir1/myconfig.yml.bak I usually just type out the path twice (with tab completion) or I'll copy and paste the path with the cursor. Is there some bashfoo that makes this easi...
I am not sure how to word this, but I often I find myself typing commands like this:
cp /etc/prog/dir1/myconfig.yml /etc/prog/dir1/myconfig.yml.bak
I usually just type out the path twice (with tab completion) or I'll copy and paste the path with the cursor. Is there some bashfoo that makes this easier to type?
user1028270
(1104 rep)
Oct 12, 2016, 03:17 PM
• Last activity: Apr 16, 2024, 11:48 PM
10
votes
7
answers
21782
views
How to add text to end of line when pattern is matched?
inputs: line1 with the PATTERN that contains ( ) line2 with the PATTERN that contains ( ) lineN with the PATTERN that contains ( ) outputs: line1 with the PATTERN that contains ( ) ; line2 with the PATTERN that contains ( ) ; ... lineN with the PATTERN that contains ( ) ; I tried this: find . -name...
inputs:
line1 with the PATTERN that contains ( )
line2 with the PATTERN that contains ( )
lineN with the PATTERN that contains ( )
outputs:
line1 with the PATTERN that contains ( ) ;
line2 with the PATTERN that contains ( ) ;
...
lineN with the PATTERN that contains ( ) ;
I tried this:
find . -name "test.txt" -print | xargs sed -i "/PATTERN/ s/$)/); /g"
but it didn't work.
user3342338
(335 rep)
Feb 28, 2014, 10:03 PM
• Last activity: Apr 13, 2024, 01:01 PM
1
votes
1
answers
1638
views
What is the difference between `set -o emacs` vs `bindkey -e`?
From what I have seen, both `set -o emacs` and `bindkey -e` are used to modify the behavior of your terminal line editor to emulate `emacs` whereas `set -o vi` and `bindkey -v` are used to emulate `vi` keybindings. Since both `set -o` and `bindkey` seem to do the same thing, I was wondering what the...
From what I have seen, both
set -o emacs
and bindkey -e
are used to modify the behavior of your terminal line editor to emulate emacs
whereas set -o vi
and bindkey -v
are used to emulate vi
keybindings. Since both set -o
and bindkey
seem to do the same thing, I was wondering what the differences between the two were and if there were any differences at all.
It seems like set -o
works for most shells whereas bindkey
is a zle
specific command. Is this the only difference? Also, do they bind the same keys or are there some keys where set -o
and bindkey
bind to different operations?
grenmester
(195 rep)
Apr 9, 2020, 07:23 AM
• Last activity: Sep 16, 2023, 08:11 AM
1
votes
2
answers
943
views
bindkey commands run in .zshrc seem ignored when in tmux
- I have some `bindkey` commands in my `.zshrc` file which behave as desired. - I start `tmux`; the same `.zshrc` is run, including the `bindkey`s but they don't function. - But then if I manually type them on the command prompt inside tmux, they *do* work again. I've tried with an empty tmux.conf (...
- I have some
bindkey
commands in my .zshrc
file which behave as desired.
- I start tmux
; the same .zshrc
is run, including the bindkey
s but they don't function.
- But then if I manually type them on the command prompt inside tmux, they *do* work again.
I've tried with an empty tmux.conf (tmux -L test -f /dev/null
) so I know it's not my tmux conf.
- zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
- tmux 3.2a
- Gnome shell (has default TERM=xterm-256color)
It's like tmux is somehow resetting the bind keys *after* running my .zshrc?
After some testing, I found out that if I remove this line from my .zshrc
, the problem goes away:
export EDITOR=which vim
Why?
artfulrobot
(3059 rep)
May 22, 2023, 08:34 AM
• Last activity: May 22, 2023, 12:13 PM
34
votes
9
answers
8463
views
How to repeat currently typed in parameter on Bash console?
I was just typing something along the lines of: mv foo/bar/poit/zoid/narf.txt Suddenly I realized, damn, I have to type large parts of that parameter again: mv foo/bar/poit/zoid/narf.txt foo/bar/poit/zoid/troz.txt Even with tab completion, that's quite a pain. I know I can copy-paste the parameter b...
I was just typing something along the lines of:
mv foo/bar/poit/zoid/narf.txt
Suddenly I realized, damn, I have to type large parts of that parameter again:
mv foo/bar/poit/zoid/narf.txt foo/bar/poit/zoid/troz.txt
Even with tab completion, that's quite a pain. I know I can copy-paste the parameter by mouse-selecting the text and middleclicking but that is not good enough. I want to keep my hands on the keyboard.
Is there a way to copy-paste the current parameter of the line using the keyboard?
k0pernikus
(16501 rep)
Jun 6, 2012, 09:47 AM
• Last activity: Apr 12, 2023, 10:29 AM
18
votes
2
answers
3695
views
Copy and set-mark in Bash as in Emacs?
I would like to be able to copy and paste text in the command line in Bash using the same keyboard bindings that Emacs uses by default (i.e. using `C-space` for `set-mark`, `M-w` to copy text, `C-y`, `M-y` to paste it, etc.). The [GNU Bash documentation][1] says that Bash comes with some of these ke...
I would like to be able to copy and paste text in the command line in Bash using the same keyboard bindings that Emacs uses by default (i.e. using
C-space
for set-mark
, M-w
to copy text, C-y
, M-y
to paste it, etc.).
The GNU Bash documentation says that Bash comes with some of these key bindings set up by default.
For example, yanking (C-y
) works by default on my terminal. However, I can't get the set-mark
and copy
commands to work, and they don't seem to be bound to any keys by default.
Usually, the way a user can define her own key bindings is to add them to .inputrc
. So I looked and found the following bash functions in the documentation that I presume can help me define the Emacs-like behavior that I want (i.e. set-mark
with C-space
and copy
with M-w
).
copy-region-as-kill ()
> Copy the text in the region to the
> kill buffer, so it can be yanked right
> away. By default, this command is
> unbound.
and
set-mark (C-@)
> Set the mark to the point. If a
> numeric argument is supplied, the mark
> is set to that position.
If I understand correctly, the above means that copy-region-as-kill
is not bound to any keyboard sequence by default, while set-mark
is bound to C-@
by default.
I tried C-@
on my terminal, but I don't think it runs set-mark
because I don't see any text highlighted when I move my cursor. In any case, I tried adding keyboard bindings (M-w
and C-
) to the functions copy-region-as-kill
and set-mark
above in my .inputrc
and then reloading it with C-x C-r
, but this didn't work. I know that my other entries in .inputrc
work because I have other user-defined keybindings defined in it.
Is there anything I am doing wrong? Am I missing anything?
Amelio Vazquez-Reina
(42851 rep)
Apr 24, 2011, 07:34 PM
• Last activity: Feb 19, 2023, 11:12 PM
43
votes
2
answers
23146
views
Where is the bash feature to open a command in $EDITOR documented?
I have recently discovered that if we press Ctrl + X Ctrl + E , bash opens the current command in an editor (set in `$VISUAL` or `$EDITOR`) and executes it when the editor is closed. But it doesn't seem to be documented in the `man` pages. Is it documented, and if so where?
I have recently discovered that if we press Ctrl+X Ctrl+E, bash opens the current command in an editor (set in
$VISUAL
or $EDITOR
) and executes it when the editor is closed.
But it doesn't seem to be documented in the man
pages. Is it documented, and if so where?
Kartik
(2024 rep)
Aug 3, 2013, 07:39 AM
• Last activity: Dec 8, 2022, 04:22 PM
7
votes
2
answers
1464
views
zsh line editor: Can I navigate and edit by argument?
I have a common situation in the shell when a command is attempted `command "/some/complex/and terrible/path" -vf --various --flags --and -- things --config-file="/some other/annoyingly/large/path/to/somewhere"` and it turns out that I'm mostly there but need to move some stuff around. Suppose I hav...
I have a common situation in the shell when a command is attempted
command "/some/complex/and terrible/path" -vf --various --flags --and -- things --config-file="/some other/annoyingly/large/path/to/somewhere"
and it turns out that I'm mostly there but need to move some stuff around. Suppose I have to move the last argument all the way to the front to attempt this next.
command --config-file="/some other/annoyingly/large/path/to/somewhere" "/some/complex/and terrible/path" -vf --various --flags --and -- things
Trying to take a keystroke golf look at this, it's a dire situation. This is actually a nightmare shell command entry scenario where you kind of have to re-type (or copy&paste) almost half the command. The best hope of sanity might be to use an external editor [[like this]](http://nuclearsquid.com/writings/edit-long-commands/) .
Even still, Vim isn't smart enough to do arg parsing (so there is no quick way to slurp out the last arg there using e.g. daW
, though it should be possible to complete the job within 8 keystrokes or so given the power of vim).
I think that this can be a decent workaround, because I do bring a lot of software to bear on editing text in vim since I use it to do all of my coding.
But what I want is if Zsh (or even Bash!) line editor could be programmed somehow to let me shove an arg around. Kind of like this: https://github.com/AndrewRadev/sideways.vim But of course, this plugin won't work on space delimited shell arguments either. And it requires vim.
I'd be happy with either a directional hop (so that I can put my cursor somewhere on the --config-file
arg and then mash HopLeft to hop the arg to the left) or a yank & paste (so i can put my cursor somewhere on the --config-file
arg, yank it out, hit home to go to the front and paste it after it).
This way we can rapidly recompose shell arguments by navigating the args as a unit rather than navigating individual characters as a unit. It would speed up general command editing a lot. I care about this a lot because I do an unusually large amount of coding directly in the shell.
If we are to take the idea further this would be implemented as an editor *mode*, let's call it Argument Edit Mode, where the cursor moves across args instead of characters and a more developed set of actions can be performed on args as a unit.
Let's come back down to earth now. The question is this: can I programmatically cause zsh to delete the shell arg that i'm currently on? And then paste it back in? Can I bind a key to let me hop based on actual args instead of just hopping words?
There doesn't seem to be ready-to-use binds for use with bindkey
, but it feels like there might be a way to do it if i can programmatically control the position of the cursor. I do use a plugin that can live syntax highlight my command after all. https://github.com/zsh-users/zsh-syntax-highlighting
Steven Lu
(2422 rep)
Jan 16, 2018, 08:03 PM
• Last activity: May 29, 2022, 05:23 PM
0
votes
2
answers
1867
views
How to switch from input mode into command mode in ed?
As far as I know, `ed` starts in command mode. Once I input `i`, `a` or `c`, `ed` changes into input mode. So far it worked. Now I read that in order to switch from input mode into command mode one has to input `,` and Enter . I tried so, but it did not work, I stayed in input mode and had to quit t...
As far as I know,
ed
starts in command mode. Once I input i
, a
or c
, ed
changes into input mode. So far it worked. Now I read that in order to switch from input mode into command mode one has to input ,
and Enter. I tried so, but it did not work, I stayed in input mode and had to quit the program with Ctrl+Z without the opportunity to write the text in the buffer onto hard disk.
I am using Linux Mint and the Xfce terminal, how can I switch into command mode?
Abdul Al Hazred
(27600 rep)
Mar 5, 2015, 10:34 PM
• Last activity: Nov 15, 2021, 08:56 AM
1
votes
1
answers
626
views
Physical buffer in terminal is getting misaligned with display in oh-my-zsh configuration
I have been experiencing an unusual problem in the oh-my-zsh configuration in which the cursor gets out of sync with the text. (I normally work using `screen` in `konsole`. For instance on a new terminal line where nothing has been typed on the prompt, the cursor just shifts forward after a few seco...
I have been experiencing an unusual problem in the oh-my-zsh configuration in which the cursor gets out of sync with the text. (I normally work using
screen
in konsole
.
For instance on a new terminal line where nothing has been typed on the prompt, the cursor just shifts forward after a few seconds for no reason. It as though the starting position for the prompt gets shifted forward, like some ghost did it.
The other feature is that it is impossible to backspace to the first cursor position and the character at that position cannot be backspaced over.
The way I see is that the visual position of the cursor and text displayed gets misaligned with its actual position within the physical buffer of the text being edited.
eg. say I enter help
at the terminal and after that I use the up arrow key to get the previous command which should be help
. Something seems to happen with the result that when I backspace over the help
I can only backspace as far the e
leaving the h
still showing, but physically the whole word help
in the physical buffer would have been cleared. So if I want to type help
again the screen will display hhelp
, but on pressing the enter key the command help
will be executed. It wont be hhelp
.
It only happens on the root account although I am sure that I am using identical settings for both root and end users.
The end result is that if abcde
is showing on the screen and backspace over c
I more likely to have backspaced of b
, leaving me with acde
rather than abde
.
Any ideas?
UPDATE:
This is additional information related to the comments.
My prompt is %{%f%b%k%}$(build_prompt)
. It is the same on both regular accounts and root
's account. But the problem only occurs in the root
account.
vfclists
(7909 rep)
Dec 27, 2019, 01:08 AM
• Last activity: Oct 8, 2021, 07:22 AM
30
votes
4
answers
34115
views
Ctrl-Backspace and Ctrl-Delete in bash
Putting on Debian 8.3 stty werase '^H' or on Arch Linux 2/2016 stty werase '^?' in `.bashrc` (for example) makes Ctrl - Backspace delete the last word in the terminal. Still it's not the same behavior as in modern GUI applications (e.g. Firefox): It deletes the last ***whitespace***-separated word,...
Putting on Debian 8.3
stty werase '^H'
or on Arch Linux 2/2016
stty werase '^?'
in
.bashrc
(for example) makes Ctrl-Backspace delete the last word in the terminal. Still it's not the same behavior as in modern GUI applications (e.g. Firefox): It deletes the last ***whitespace***-separated word, and not the last word separated by whitespace ***or*** characters like . : , ; " ' & / ( )
.
Is it possible to make Ctrl-Backspace behave in the terminal similar to modern GUI applications? Also, is there any way to make Ctrl-Delete delete the word immediately before the cursor?
viuser
(2724 rep)
Feb 21, 2016, 04:20 PM
• Last activity: Sep 16, 2021, 12:41 PM
3
votes
1
answers
1564
views
Tcsh: Searching history using Ctrl-P and Ctrl-N
What are the equivalent functions in `tcsh` for the following `zsh` functions? up-line-or-history history-beginning-search-backward down-line-or-history history-beginning-search-forward I have the following code in my **,zsh** that I am hoping to translate **in full** to my ".tcsh". The code below i...
What are the equivalent functions in
tcsh
for the following zsh
functions?
up-line-or-history
history-beginning-search-backward
down-line-or-history
history-beginning-search-forward
I have the following code in my **,zsh** that I am hoping to translate **in full** to my ".tcsh". The code below is supposed to bind Ctrl-P
and Ctrl-N
to such history search functions:
up-line-or-history-beginning-search () {
if [[ -n $PREBUFFER ]]; then
zle up-line-or-history
else
zle history-beginning-search-backward
fi
}
down-line-or-history-beginning-search () {
if [[ -n $PREBUFFER ]]; then
zle down-line-or-history
else
zle history-beginning-search-forward
fi
}
zle -N up-line-or-history-beginning-search
zle -N down-line-or-history-beginning-search
bindkey '^P' up-line-or-history-beginning-search
bindkey '^N' down-line-or-history-beginning-search
Any ideas about what the equivalent tcsh
code would look like?
Amelio Vazquez-Reina
(42851 rep)
Sep 5, 2012, 08:22 PM
• Last activity: Mar 23, 2021, 06:05 PM
2
votes
4
answers
2109
views
Use substitution to delete everything up to a point on a line
I want to use a global substitution in Vim to delete everything *up to* `https`. # Before The website is https://website.com The website is https://website.com The website is https://website.com # After https://website.com https://website.com https://website.com
I want to use a global substitution in Vim to delete everything *up to*
https
.
# Before
The website is https://website.com
The website is https://website.com
The website is https://website.com
# After
https://website.com
https://website.com
https://website.com
5am
(333 rep)
Apr 29, 2020, 11:13 AM
• Last activity: Mar 17, 2021, 05:45 PM
31
votes
4
answers
21607
views
First characters of the command repeated in the display when completing
The first two chars were repeated while I use Tab to do completion. In the screenshot below, `cd` is repeated. ![enter image description here][1] I have tried rxvt-unicdoe, xterm, terminator. All these terminal emulators have this issue. Zsh version 5.0.2, config file [on-my-zsh][2] [1]: https://i.s...
The first two chars were repeated while I use Tab to do completion. In the screenshot below,
I have tried rxvt-unicdoe, xterm, terminator. All these terminal emulators have this issue.
Zsh version 5.0.2, config file on-my-zsh
cd
is repeated.

jilen
(787 rep)
Sep 15, 2013, 03:48 PM
• Last activity: Feb 2, 2021, 05:14 PM
Showing page 1 of 20 total questions