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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















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?










share|improve this question

















  • 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











  • @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







  • 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, grep and - cool, will check the function of -. Cool!

    – roachsinai
    Jan 8 at 8:55















1















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?










share|improve this question

















  • 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











  • @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







  • 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, grep and - cool, will check the function of -. Cool!

    – roachsinai
    Jan 8 at 8:55













1












1








1


1






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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 8 at 8:20









roachsinairoachsinai

778




778







  • 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











  • @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







  • 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, grep and - cool, will check the function of -. Cool!

    – roachsinai
    Jan 8 at 8:55












  • 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











  • @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







  • 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, grep and - 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










1 Answer
1






active

oldest

votes


















2














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).






share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









2














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).






share|improve this answer























  • 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















2














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).






share|improve this answer























  • 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













2












2








2







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).






share|improve this answer













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).







share|improve this answer












share|improve this answer



share|improve this answer










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 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
















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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?