Sample Header Ad - 728x90

Yanking to the global clip board from the command line in Vi editing-mode

0 votes
1 answer
48 views
I am using Arch, bash and gnome terminal. All are up to date with the very latest software versions. I wish to bind ctrl+c to yank the current line on the command line to the global clipboard, which may not yet be in the history file. So far I have had no success. Parsing the history file is problematic becasue the line on the command line may be yanked before the command has been run, in which case it won't be in the history file, so parsing this is not a viable option. .bashrc has vi bindings enabled as follows # set editing-mode vi set -o vi I am being careful to re-source each time as necessary with source ~/.bashrc. I have tried adding the below various options to .inputrc, re-initialising each time with bind -f ~/.inputrc, none have worked. **.inputrc tests:** $if mode=vi "\C-y": " \C-e\C-u\C-k\C-y\C-l\C-y\C-e\C-y\n" $endif and this $if mode=vi "\C-c": "\e0\C-k\C-u\C-y\n" $endif and these "\"+y": yank-to-clipboard "\Cc": copy-line # ctrl+c "\^C": copy-line # ctrl+c "\006": copy-line # ctrl+c **.bashrc tests:** I have also tried adding the following to .bashrc bind -m vi-command '"\C-y": "fc -ln -0 | tr -d \"\\n\" | xclip -selection clipboard\n"' then copy_current_command() { local cmd cmd=$(fc -ln -0) echo -n "$cmd" | xclip -selection clipboard } bind -m vi-command '"\C-c": "copy_current_command\n"' The below does not work either This is .inputrc "\e[1;6C": yank-to-clipboard # ctrl+shift+c "\^C": yank-to-clipboard # ctrl+c and this in .bashrc yank-to-clipboard() { local line=$(readline) # get the current line echo "$line" | xclip -in -selection clipboard }
Asked by Kes (909 rep)
Feb 2, 2025, 01:47 PM
Last activity: Feb 3, 2025, 12:29 AM