How to get clipboard as input file name to Vim on bash?

Clash Royale CLAN TAG#URR8PPP
I install xclip to access system clipboard, my setting and some operations as below:
➜ ~ cat .zshrc | grep xclip
alias c="xclip -selection c"
alias v="xclip -selection c -o"
➜ ~ which dict | c
➜ ~ v
/usr/bin/dict
➜ ~ sudo vim ??
/usr/bin/dict is a python script. And what I want to know is what can substitute ?? on my last command can use vim open file /usr/bin/dict?
bash vim clipboard xclip xsel
add a comment |
I install xclip to access system clipboard, my setting and some operations as below:
➜ ~ cat .zshrc | grep xclip
alias c="xclip -selection c"
alias v="xclip -selection c -o"
➜ ~ which dict | c
➜ ~ v
/usr/bin/dict
➜ ~ sudo vim ??
/usr/bin/dict is a python script. And what I want to know is what can substitute ?? on my last command can use vim open file /usr/bin/dict?
bash vim clipboard xclip xsel
1
Do you wantvimto open the file named in the clipboard, or do you wantvimto open with the contents of the clipboard in the editing buffer?
– wurtel
Jan 8 at 8:31
@wurtel the first, I wantvimto open the file named in the clipboard! But the second is also a thing I don't know I will search it, if I don't find out it will be a new question to be asked.
– roachsinai
Jan 8 at 8:43
@wurtel Is there a way to directly open with the contents of the clipboard in the editing buffer? In my mind, I have to run vim and then use"+pto paste it to vim. If there is a method, I could ask a new question atVim Stack Exchange.
– roachsinai
Jan 8 at 8:50
1
You can runsome-command | vim -and vim will read its input and place that in the buffer.
– wurtel
Jan 8 at 8:52
@wurtel thanks a lot,grepand-cool, will check the function of-. Cool!
– roachsinai
Jan 8 at 8:55
add a comment |
I install xclip to access system clipboard, my setting and some operations as below:
➜ ~ cat .zshrc | grep xclip
alias c="xclip -selection c"
alias v="xclip -selection c -o"
➜ ~ which dict | c
➜ ~ v
/usr/bin/dict
➜ ~ sudo vim ??
/usr/bin/dict is a python script. And what I want to know is what can substitute ?? on my last command can use vim open file /usr/bin/dict?
bash vim clipboard xclip xsel
I install xclip to access system clipboard, my setting and some operations as below:
➜ ~ cat .zshrc | grep xclip
alias c="xclip -selection c"
alias v="xclip -selection c -o"
➜ ~ which dict | c
➜ ~ v
/usr/bin/dict
➜ ~ sudo vim ??
/usr/bin/dict is a python script. And what I want to know is what can substitute ?? on my last command can use vim open file /usr/bin/dict?
bash vim clipboard xclip xsel
bash vim clipboard xclip xsel
asked Jan 8 at 8:20
roachsinairoachsinai
778
778
1
Do you wantvimto open the file named in the clipboard, or do you wantvimto open with the contents of the clipboard in the editing buffer?
– wurtel
Jan 8 at 8:31
@wurtel the first, I wantvimto open the file named in the clipboard! But the second is also a thing I don't know I will search it, if I don't find out it will be a new question to be asked.
– roachsinai
Jan 8 at 8:43
@wurtel Is there a way to directly open with the contents of the clipboard in the editing buffer? In my mind, I have to run vim and then use"+pto paste it to vim. If there is a method, I could ask a new question atVim Stack Exchange.
– roachsinai
Jan 8 at 8:50
1
You can runsome-command | vim -and vim will read its input and place that in the buffer.
– wurtel
Jan 8 at 8:52
@wurtel thanks a lot,grepand-cool, will check the function of-. Cool!
– roachsinai
Jan 8 at 8:55
add a comment |
1
Do you wantvimto open the file named in the clipboard, or do you wantvimto open with the contents of the clipboard in the editing buffer?
– wurtel
Jan 8 at 8:31
@wurtel the first, I wantvimto open the file named in the clipboard! But the second is also a thing I don't know I will search it, if I don't find out it will be a new question to be asked.
– roachsinai
Jan 8 at 8:43
@wurtel Is there a way to directly open with the contents of the clipboard in the editing buffer? In my mind, I have to run vim and then use"+pto paste it to vim. If there is a method, I could ask a new question atVim Stack Exchange.
– roachsinai
Jan 8 at 8:50
1
You can runsome-command | vim -and vim will read its input and place that in the buffer.
– wurtel
Jan 8 at 8:52
@wurtel thanks a lot,grepand-cool, will check the function of-. Cool!
– roachsinai
Jan 8 at 8:55
1
1
Do you want
vim to open the file named in the clipboard, or do you want vim to open with the contents of the clipboard in the editing buffer?– wurtel
Jan 8 at 8:31
Do you want
vim to open the file named in the clipboard, or do you want vim to open with the contents of the clipboard in the editing buffer?– wurtel
Jan 8 at 8:31
@wurtel the first, I want
vim to open the file named in the clipboard! But the second is also a thing I don't know I will search it, if I don't find out it will be a new question to be asked.– roachsinai
Jan 8 at 8:43
@wurtel the first, I want
vim to open the file named in the clipboard! But the second is also a thing I don't know I will search it, if I don't find out it will be a new question to be asked.– roachsinai
Jan 8 at 8:43
@wurtel Is there a way to directly open with the contents of the clipboard in the editing buffer? In my mind, I have to run vim and then use
"+p to paste it to vim. If there is a method, I could ask a new question at Vim Stack Exchange.– roachsinai
Jan 8 at 8:50
@wurtel Is there a way to directly open with the contents of the clipboard in the editing buffer? In my mind, I have to run vim and then use
"+p to paste it to vim. If there is a method, I could ask a new question at Vim Stack Exchange.– roachsinai
Jan 8 at 8:50
1
1
You can run
some-command | vim - and vim will read its input and place that in the buffer.– wurtel
Jan 8 at 8:52
You can run
some-command | vim - and vim will read its input and place that in the buffer.– wurtel
Jan 8 at 8:52
@wurtel thanks a lot,
grep and - cool, will check the function of -. Cool!– roachsinai
Jan 8 at 8:55
@wurtel thanks a lot,
grep and - cool, will check the function of -. Cool!– roachsinai
Jan 8 at 8:55
add a comment |
1 Answer
1
active
oldest
votes
Given your current setup
sudo vim "$(v)"
will use command substitution to run your alias v and insert its output into the command line to be run before executing it, so it would run sudo vim /usr/bin/dict in the end. The quotes make sure it comes out as a single argument, and $(...) handles running the command and capturing its output.
This will only work from your interactive shell, since aliases aren't used elsewhere. If you want to access it from a script, you could make a small script somewhere in your PATH variable with the same command inside it.
You've tagged this bash but then shown an extract from .zshrc, so note also that zsh has "global aliases" that expand anywhere:
alias -g v='"$(xclip -selection c -o)"'
and then just run sudo vim v and have that happen for free. Global aliases are almost always more trouble than they're worth, so I don't recommend that, but depending on your usage patterns some global alias might be convenient (I'd recommend a longer and more unusual name if you do: putting some odd punctuation in can help avoid running it by mistake, so alias -g v# ... or @v or ^v or something).
Wow, thanks, global seems very convenient for me. And the reason I usezshbut taggedbashis I think what works in zsh should be worked in bash, so I want a more general method.
– roachsinai
Jan 8 at 8:46
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493171%2fhow-to-get-clipboard-as-input-file-name-to-vim-on-bash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Given your current setup
sudo vim "$(v)"
will use command substitution to run your alias v and insert its output into the command line to be run before executing it, so it would run sudo vim /usr/bin/dict in the end. The quotes make sure it comes out as a single argument, and $(...) handles running the command and capturing its output.
This will only work from your interactive shell, since aliases aren't used elsewhere. If you want to access it from a script, you could make a small script somewhere in your PATH variable with the same command inside it.
You've tagged this bash but then shown an extract from .zshrc, so note also that zsh has "global aliases" that expand anywhere:
alias -g v='"$(xclip -selection c -o)"'
and then just run sudo vim v and have that happen for free. Global aliases are almost always more trouble than they're worth, so I don't recommend that, but depending on your usage patterns some global alias might be convenient (I'd recommend a longer and more unusual name if you do: putting some odd punctuation in can help avoid running it by mistake, so alias -g v# ... or @v or ^v or something).
Wow, thanks, global seems very convenient for me. And the reason I usezshbut taggedbashis I think what works in zsh should be worked in bash, so I want a more general method.
– roachsinai
Jan 8 at 8:46
add a comment |
Given your current setup
sudo vim "$(v)"
will use command substitution to run your alias v and insert its output into the command line to be run before executing it, so it would run sudo vim /usr/bin/dict in the end. The quotes make sure it comes out as a single argument, and $(...) handles running the command and capturing its output.
This will only work from your interactive shell, since aliases aren't used elsewhere. If you want to access it from a script, you could make a small script somewhere in your PATH variable with the same command inside it.
You've tagged this bash but then shown an extract from .zshrc, so note also that zsh has "global aliases" that expand anywhere:
alias -g v='"$(xclip -selection c -o)"'
and then just run sudo vim v and have that happen for free. Global aliases are almost always more trouble than they're worth, so I don't recommend that, but depending on your usage patterns some global alias might be convenient (I'd recommend a longer and more unusual name if you do: putting some odd punctuation in can help avoid running it by mistake, so alias -g v# ... or @v or ^v or something).
Wow, thanks, global seems very convenient for me. And the reason I usezshbut taggedbashis I think what works in zsh should be worked in bash, so I want a more general method.
– roachsinai
Jan 8 at 8:46
add a comment |
Given your current setup
sudo vim "$(v)"
will use command substitution to run your alias v and insert its output into the command line to be run before executing it, so it would run sudo vim /usr/bin/dict in the end. The quotes make sure it comes out as a single argument, and $(...) handles running the command and capturing its output.
This will only work from your interactive shell, since aliases aren't used elsewhere. If you want to access it from a script, you could make a small script somewhere in your PATH variable with the same command inside it.
You've tagged this bash but then shown an extract from .zshrc, so note also that zsh has "global aliases" that expand anywhere:
alias -g v='"$(xclip -selection c -o)"'
and then just run sudo vim v and have that happen for free. Global aliases are almost always more trouble than they're worth, so I don't recommend that, but depending on your usage patterns some global alias might be convenient (I'd recommend a longer and more unusual name if you do: putting some odd punctuation in can help avoid running it by mistake, so alias -g v# ... or @v or ^v or something).
Given your current setup
sudo vim "$(v)"
will use command substitution to run your alias v and insert its output into the command line to be run before executing it, so it would run sudo vim /usr/bin/dict in the end. The quotes make sure it comes out as a single argument, and $(...) handles running the command and capturing its output.
This will only work from your interactive shell, since aliases aren't used elsewhere. If you want to access it from a script, you could make a small script somewhere in your PATH variable with the same command inside it.
You've tagged this bash but then shown an extract from .zshrc, so note also that zsh has "global aliases" that expand anywhere:
alias -g v='"$(xclip -selection c -o)"'
and then just run sudo vim v and have that happen for free. Global aliases are almost always more trouble than they're worth, so I don't recommend that, but depending on your usage patterns some global alias might be convenient (I'd recommend a longer and more unusual name if you do: putting some odd punctuation in can help avoid running it by mistake, so alias -g v# ... or @v or ^v or something).
answered Jan 8 at 8:33
Michael HomerMichael Homer
47.1k8124162
47.1k8124162
Wow, thanks, global seems very convenient for me. And the reason I usezshbut taggedbashis I think what works in zsh should be worked in bash, so I want a more general method.
– roachsinai
Jan 8 at 8:46
add a comment |
Wow, thanks, global seems very convenient for me. And the reason I usezshbut taggedbashis I think what works in zsh should be worked in bash, so I want a more general method.
– roachsinai
Jan 8 at 8:46
Wow, thanks, global seems very convenient for me. And the reason I use
zsh but tagged bash is I think what works in zsh should be worked in bash, so I want a more general method.– roachsinai
Jan 8 at 8:46
Wow, thanks, global seems very convenient for me. And the reason I use
zsh but tagged bash is I think what works in zsh should be worked in bash, so I want a more general method.– roachsinai
Jan 8 at 8:46
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493171%2fhow-to-get-clipboard-as-input-file-name-to-vim-on-bash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Do you want
vimto open the file named in the clipboard, or do you wantvimto open with the contents of the clipboard in the editing buffer?– wurtel
Jan 8 at 8:31
@wurtel the first, I want
vimto open the file named in the clipboard! But the second is also a thing I don't know I will search it, if I don't find out it will be a new question to be asked.– roachsinai
Jan 8 at 8:43
@wurtel Is there a way to directly open with the contents of the clipboard in the editing buffer? In my mind, I have to run vim and then use
"+pto paste it to vim. If there is a method, I could ask a new question atVim Stack Exchange.– roachsinai
Jan 8 at 8:50
1
You can run
some-command | vim -and vim will read its input and place that in the buffer.– wurtel
Jan 8 at 8:52
@wurtel thanks a lot,
grepand-cool, will check the function of-. Cool!– roachsinai
Jan 8 at 8:55