Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

3 votes
1 answers
752 views
How to have gdb start in vi mode by default?
I know that I can use `CTRL+ALT+J` in `gdb` to get vim keybindings but how do I get `gdb` to start in vi mode by default ?
I know that I can use CTRL+ALT+J in gdb to get vim keybindings but how do I get gdb to start in vi mode by default ?
cassepipe (227 rep)
Sep 22, 2021, 01:13 PM • Last activity: Feb 6, 2025, 01:10 PM
0 votes
2 answers
65 views
remap '-' key in BASH vi normal mode to "cd .."
I just discovered vi mode in bash that I enable with `set -o vi` in my .bashrc. Now I was quite excited to remap the "normal mode" equivalents to some handy functionality. First and foremost I wanted to remap the dash-key to change directory one up from the current. I tried this: ```sh # Remap "-" k...
I just discovered vi mode in bash that I enable with set -o vi in my .bashrc. Now I was quite excited to remap the "normal mode" equivalents to some handy functionality. First and foremost I wanted to remap the dash-key to change directory one up from the current. I tried this:
# Remap "-" key to "cd .." in vi normal mode
bind -m vi-command '"-": "cd ..\n"'
but it doesn't seem to be working. Where did I go wrong and how to accomplish that?
glades (117 rep)
Sep 5, 2024, 05:45 AM • Last activity: Sep 24, 2024, 03:37 PM
3 votes
2 answers
9999 views
Vim Mode copy-paste not working on Tmux
I am new at using Tmux. I have seen that it is quite difficult to copy-paste inside Tmux. So I searched for an easier method. Some sites suggested that I should use vim mode as I am quite familiar with vim. But, vim mode copy-paste isn't working. I don't know what I am doing wrong. This is my ~/.tmu...
I am new at using Tmux. I have seen that it is quite difficult to copy-paste inside Tmux. So I searched for an easier method. Some sites suggested that I should use vim mode as I am quite familiar with vim. But, vim mode copy-paste isn't working. I don't know what I am doing wrong. This is my ~/.tmux.conf file.
# Improve colors
set -g default-terminal 'screen-256color'

# Set scrollback buffer to 10000
set -g history-limit 10000

# Customize the status line
set -g status-fg  green
set -g status-bg  black

set -g mouse on

bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'

# remap prefix to Control + a
set -g prefix M-a
# bind 'C-a C-a' to type 'C-a'
bind M-a send-prefix
unbind C-b



# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

set -g @plugin 'jimeh/tmux-themepack'

set -g @themepack 'powerline/block/blue'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
I am using Tmux 2.5. Thanks in advance for help.
Merajul Arefin Pial (133 rep)
Jul 5, 2020, 09:03 PM • Last activity: Jul 6, 2024, 08:05 AM
1 votes
1 answers
178 views
Anyway to bind keyboard to dash (Debian Almquist Shell)?
Specifically Up/Down for history navigation. # What I already know I understand [`dash`](https://en.wikipedia.org/wiki/Debian_Almquist_shell#Dash) is a minimalistic, no bloat, (somewhat) strict POSIX shell. I understand the philosophy behind it, and the reason features, that have become basic in oth...
Specifically Up/Down for history navigation. # What I already know I understand [dash](https://en.wikipedia.org/wiki/Debian_Almquist_shell#Dash) is a minimalistic, no bloat, (somewhat) strict POSIX shell. I understand the philosophy behind it, and the reason features, that have become basic in other interactive shells, are not present in dash. I've looked into the following resources: * [man](https://www.man7.org/linux/man-pages/man1/dash.1.html) page * [Arch Linux Wiki](https://wiki.archlinux.org/title/Dash) page As well as a bunch of other pages and answers specific about history in dash. From my reading, I gather _there is_ a history mechanism, as well as a vi mode. However I can't find how to map the ` key, or the [UP]/[DOWN]` arrow keys (or any key) to any meaningful action. No bind or bindkey builtin commands either. My goal - make dash minimally usable as an interactive shell for debugging purposes. # Questions * Is there a default mapping? * Is there a way to manipulate the keyboard mapping in dash? * Is there another source of information that can shed some light on interactive usability of dash?
Lockszmith (768 rep)
Jan 11, 2023, 10:58 PM • Last activity: Jan 11, 2024, 06:37 AM
83 votes
3 answers
35111 views
How do I perform a reverse history search in ZSH's vi-mode?
I use `vim` for essentially all my editing needs, so I decided to once again try vi-mode for my shell (currently ZSH w/ oh-my-zsh on OS X), but I find myself trying (and failing) to use `Ctrl-R` constantly. What's the equivalent key-binding? And for future reference, how would I figure this out myse...
I use vim for essentially all my editing needs, so I decided to once again try vi-mode for my shell (currently ZSH w/ oh-my-zsh on OS X), but I find myself trying (and failing) to use Ctrl-R constantly. What's the equivalent key-binding? And for future reference, how would I figure this out myself? I'm pretty sure I could use bind -P in bash.
Hank Gay (3639 rep)
Jul 27, 2012, 11:30 AM • Last activity: Dec 24, 2023, 01:18 AM
6 votes
3 answers
5932 views
Running external commands in vim
It seems that if I run the following inside the `vim`: `:w !wc -w` I get the word count of the file. But I don't understand the syntax. How does this work and how would I specify that I want the word count of a paragraph and not of the whole file?
It seems that if I run the following inside the vim: :w !wc -w I get the word count of the file. But I don't understand the syntax. How does this work and how would I specify that I want the word count of a paragraph and not of the whole file?
Cratylus (529 rep)
Jun 16, 2013, 10:36 AM • Last activity: Jun 2, 2023, 02:34 PM
3 votes
1 answers
366 views
Make one normal mode command while in insert mode in zsh's vi mode
Zsh vi mode doesn't have ctrl-o behavior set by default how do I get to work like in vim ?
Zsh vi mode doesn't have ctrl-o behavior set by default how do I get to work like in vim ?
Hazem Elmahy (33 rep)
Jan 10, 2021, 01:36 AM • Last activity: Apr 26, 2023, 11:08 AM
1 votes
1 answers
473 views
Colorful cursor to indicate vi mode in zsh, but fail to reset color
I am trying to have cursor color in zsh to indicate normal/insert mode, but once enter normal mode, the color of cursor don't reset to default color in insert mode. The source are: ``` # color cursor zle-keymap-select () { if [ $KEYMAP = vicmd ]; then echo -ne "\033]12;Cyan\e[2 q\033[m" else echo -n...
I am trying to have cursor color in zsh to indicate normal/insert mode, but once enter normal mode, the color of cursor don't reset to default color in insert mode.
The source are:
# color cursor
zle-keymap-select () {
    if [ $KEYMAP = vicmd ]; then
        echo -ne "\033]12;Cyan\e[2 q\033[m"
    else
        echo -ne "\e[2 q\033[m"
        zle -K viins
    fi
}
zle -N zle-keymap-select

zle-line-init () {
    zle -K viins
    echo -ne "\e[2 q\033[m"
}
zle -N zle-line-init
_fix_cursor() {
    echo -ne "\e[2 q\033[m"
}
precmd_functions+=(_fix_cursor)
The terminal emulator I am using is alacritty. --- If I am using zsh inside tmux, the color will change accordingly, but if outside tmux, cursor color don't change.
Solarisending (21 rep)
Apr 17, 2023, 04:10 AM • Last activity: Apr 21, 2023, 09:47 AM
0 votes
0 answers
46 views
vi command line edit mode - an odd observation
This is not a real problem, but something that I'm curious about - and maybe somebody knows the explanation. I work on several servers, mostly Ubuntu 20.04 and 22.04, plus a few Debian 11. I always work on the command line, and my editing mode is vi. I will often write ad-hoc scripts like: ``` root@...
This is not a real problem, but something that I'm curious about - and maybe somebody knows the explanation. I work on several servers, mostly Ubuntu 20.04 and 22.04, plus a few Debian 11. I always work on the command line, and my editing mode is vi. I will often write ad-hoc scripts like:
root@ceres:/etc/pam.d# for i in common*
> do
> echo $i
> grep -vE '^$|^#'  $i
> echo 
> done
And then, later, I search back to the same command (with Esc-k, of course) and pre v to see the command in vi. On some systems this happens:
root@ceres:/var/lib/icinga# for i in common*; do echo $i; grep -vE '^$|^#'  $i; echo ; done
... # press v 
for i in common*; do echo $i; grep -vE '^$|^#'  $i; echo ; done
~
~
~
but on others, this:
# for i in common*^Jdo^Jecho $i^Jgrep -vE '^$|^#' $i^Jecho^Jdone
... # press v 
for i in common*
do
echo $i
grep -vE '^$|^#' $i
echo
done
~
~
~
The question is, why? All my environments are set up the same, as far as I know.
j4nd3r53n (779 rep)
Apr 17, 2023, 02:43 PM
9 votes
1 answers
2257 views
How to enable bash completion in vi mode on Synology DSM6
When I turned on vi mode in bash by setting `set -o vi` suddenly the tab completion was broken, and a literal tab was inserted. How can this be fixed?
When I turned on vi mode in bash by setting set -o vi suddenly the tab completion was broken, and a literal tab was inserted. How can this be fixed?
Gerhard Burger (373 rep)
May 8, 2016, 03:17 PM • Last activity: Feb 9, 2023, 08:57 AM
1 votes
1 answers
25 views
Is it possible to make readline ignore compspec when expanding matches in VI mode?
I use VI mode when using bash and I sometimes find that some of the standard compspec definitions don't do what I want. For example, `java` doesn't appear to know that you have been able to do `java Source.java` since Java 9. Is there a way to get "dumb" expansion when in VI mode. In emacs mode, I u...
I use VI mode when using bash and I sometimes find that some of the standard compspec definitions don't do what I want. For example, java doesn't appear to know that you have been able to do java Source.java since Java 9. Is there a way to get "dumb" expansion when in VI mode. In emacs mode, I understand I can do ESC / and it will expand files without going through the compspec function. But that doesn't work in VI mode (the ESC just ends normal mode).
Mark W (145 rep)
Nov 29, 2022, 02:35 PM • Last activity: Dec 1, 2022, 05:50 PM
81 votes
5 answers
116561 views
Why does '\r' (and not '\n') work to replace with a newline in 'vim'?
In `vim` editor, I want to replace a newline character (`\n`) with two new line characters (`\n\n`) using `vim` command mode. Input file content: ```none This is my first line. This is second line. ``` * Command that I tried: ```vim :%s/\n/\n\n/g ``` But it replaces the string with unwanted characte...
In vim editor, I want to replace a newline character (\n) with two new line characters (\n\n) using vim command mode. Input file content:
This is my first line.
This is second line.
* Command that I tried:
:%s/\n/\n\n/g
But it replaces the string with unwanted characters as
This is my first line.^@^@This is second line.^@^@
* Then I tried the following command
:%s/\n/\r\r/g
It is working properly. Can you explain why it is working fine with second command?
Raghvendra (1092 rep)
Dec 4, 2015, 10:21 AM • Last activity: Nov 7, 2022, 10:51 AM
2 votes
1 answers
152 views
Zsh goes into command mode on unbound key
I like vi mode in Zsh, set with `bindkey -v`. Pressing escape triggers command mode as it should, but it irks me that unbound keychords trigger command mode, for example, Alt+1 and F1. Any way to stop that?
I like vi mode in Zsh, set with bindkey -v. Pressing escape triggers command mode as it should, but it irks me that unbound keychords trigger command mode, for example, Alt+1 and F1. Any way to stop that?
geb (83 rep)
Aug 15, 2022, 04:25 PM • Last activity: Aug 16, 2022, 04:10 PM
2 votes
0 answers
513 views
How to paste selection from vi-mode to clipboard
I want to access the content of what I copied in the buffer with the vi-mode of the clipboard via the command `ctrl` + `v` or `ctrl` + `shift` + `v` in the terminal. I copied in my .zshrc the following: (from this answer: https://unix.stackexchange.com/questions/25765/pasting-from-clipboard-to-vi-en...
I want to access the content of what I copied in the buffer with the vi-mode of the clipboard via the command ctrl + v or ctrl + shift + v in the terminal. I copied in my .zshrc the following: (from this answer: https://unix.stackexchange.com/questions/25765/pasting-from-clipboard-to-vi-enabled-zsh-or-bash-shell)
vi-append-x-selection () { RBUFFER=$(xsel -o -p 
When I highlight something in the terminal in vi-mode and yank it, I can successfully retrieve it by typing Ctrl + shift + y. However when I type Ctrl + shift + v, something else in being pasted. When I inspect the content of the clipboard with the following commands:
xclip -o sel p
xclip -o sel s
xclip -o sel c
xsel -o -p
xsel -o -s
xsel -o -b
it contains other string that I peviously copied with other means but NOT what I highlighted in vi-mode. Here is my **first question**: if I can retrieve it with the command Ctrl + shift + y and confirm that with xsel and xclip that it is not in one of the three buffer ("primary", "secondary" and "clipboard") where is stored then???) I also tried to replace the '^Y' by '^V' in the line
bindkey -a '^Y' vi-yank-x-selection
(as follows:)
bindkey -a '^V' vi-yank-x-selection
Without any success (it seems to print out an empty buffer) **my second question**: What am I doing wrong?
ecjb (475 rep)
May 26, 2022, 01:25 PM • Last activity: May 27, 2022, 10:16 PM
6 votes
2 answers
1332 views
How to use `Alt + .` in zsh with Vim bindings
I am using zsh with `bindkeys -v`. `Alt + .` does not work as expected. It seems to repeat what is currently typed in stdin, but not entered, on the next line. [This post](https://unix.stackexchange.com/questions/490801/alt-dot-shows-instead-of-a-previous-argument) seems to imply it does work as it...
I am using zsh with bindkeys -v. Alt + . does not work as expected. It seems to repeat what is currently typed in stdin, but not entered, on the next line. [This post](https://unix.stackexchange.com/questions/490801/alt-dot-shows-instead-of-a-previous-argument) seems to imply it does work as it does in bash, which is to grab the last argument to the last command entered. What is needed to make this work as intended?
mcp (827 rep)
Jan 4, 2022, 05:30 PM • Last activity: Mar 27, 2022, 07:35 AM
7 votes
2 answers
308 views
Insert the last argument in bash in vi mode without inserting a leading space
Using bash in the default (emacs) mode I get the following behavior when I hit Esc , **.** . ```bash $ echo hello hello $ hello # I hit ` .` to insert this ``` Note there is no space before the word `hello` that is inserted when I hit Esc , **.** . If I switch to vi mode and configure `.` I do get a...
Using bash in the default (emacs) mode I get the following behavior when I hit Esc, **.**.
$ echo hello
hello
$ hello  # I hit . to insert this
Note there is no space before the word hello that is inserted when I hit Esc, **.**. If I switch to vi mode and configure . I do get a leading space:
$ set -o vi
$ bind -m vi-command ".":yank-last-arg
$ echo hello
hello
$  hello  # I hit . to insert this. Note the leading space.
Is there any way to configure bash/readline to avoid this leading space?
mike (165 rep)
Aug 5, 2020, 03:50 AM • Last activity: Feb 16, 2022, 03:09 PM
3 votes
1 answers
508 views
Fish shell vi-mode is missing "repeat" command (dot/period/. key in Zsh)
I recently moved from Zsh to Fish, and I'm having a problem with vi-mode in Fish. There doesn't seem to be a "repeat" keybinding, like in Zsh's vi-mode (bound to the "dot" `.`). I think this is one of the most useful commands in vi-mode since it can prevent you from repeating commands. Is there a wa...
I recently moved from Zsh to Fish, and I'm having a problem with vi-mode in Fish. There doesn't seem to be a "repeat" keybinding, like in Zsh's vi-mode (bound to the "dot" .). I think this is one of the most useful commands in vi-mode since it can prevent you from repeating commands. Is there a way to add this command to vi-mode in the Fish shell. Any idea how am I supposed to do this? Thanks.
Reynald Lamury (131 rep)
Sep 23, 2021, 06:22 AM • Last activity: Nov 2, 2021, 03:11 AM
0 votes
1 answers
175 views
assign letters to jump forward and backward in bash
My default shell is `tcsh`. In my `.cshrc` file. I have `bindkey -v`, so that at the command line, the letters `b` and `w` jump backwards and forwards a word, respectively. I'd like to set up bash so that when I switch to that shell, it does the same thing. I've tried putting `bindkey -v` into `.bas...
My default shell is tcsh. In my .cshrc file. I have bindkey -v, so that at the command line, the letters b and w jump backwards and forwards a word, respectively. I'd like to set up bash so that when I switch to that shell, it does the same thing. I've tried putting bindkey -v into .bashrc but bindkey is not recognized. Could somebody please explain how to mimic these tcsh key bindings in bash. Thanks!
Leo Simon (453 rep)
Apr 4, 2021, 05:42 PM • Last activity: Apr 4, 2021, 06:31 PM
2 votes
1 answers
116 views
how to detect state of bash readline using bash script?
for example; if [ 'readline is vi-command' ]; then echo 'normal mode' else echo 'insert mode' fi I really don't have any idea how to do this and I can't seem to find anything on the man pages either, or is it possible at all?
for example; if [ 'readline is vi-command' ]; then echo 'normal mode' else echo 'insert mode' fi I really don't have any idea how to do this and I can't seem to find anything on the man pages either, or is it possible at all?
cevhyruz (477 rep)
Apr 26, 2019, 12:55 PM • Last activity: Feb 27, 2021, 12:01 PM
1 votes
0 answers
539 views
Seeking alternative to KeyNav(drive mouse with keyboard, for X)
as described in the title, I am seeking user-friendly alternatives to KeyNav. I am a fan of CLI&TUI applications and stay on the terminal emulator most of the time, where I can use the keyboard to get most of the job done. However, I have to use the browser from time to time, which means I have to u...
as described in the title, I am seeking user-friendly alternatives to KeyNav. I am a fan of CLI&TUI applications and stay on the terminal emulator most of the time, where I can use the keyboard to get most of the job done. However, I have to use the browser from time to time, which means I have to use the mouse(hmm, on a laptop, I only have the trackpad/touchpad) even I have the vimnium extesion. I found it really hard to navigate my pointer to some small elements (e.g. the radio tag in a form). So I'm wondering if there exists a fast&accurate way to simulate mouse movement/dragging/click. ### links - [github repository of keynav](https://github.com/jordansissel/keynav) - [homepage of KeyNav (on the developer's blog)](https://www.semicomplete.com/projects/keynav/)
hehelego (11 rep)
Dec 29, 2020, 01:19 AM
Showing page 1 of 20 total questions