vim - open file and goto line number using ::











up vote
20
down vote

favorite
8












Several tools such as grep, py.test, etc ... use the pattern <FileName>:<line number>: to point to errors. For example:



; grep -Hn Common setup.cfg
setup.cfg:11: Common


How can I modify vim and gvim so that I can invoke them like so:



gvim setup.cfg:11:


instead of



gvim setup.cfg +11


I know that I can write a small shell script that would parse things but I wonder if there is an easier way.










share|improve this question


















  • 2




    This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See :help quickfix for more info.
    – Random832
    Oct 5 '12 at 12:48















up vote
20
down vote

favorite
8












Several tools such as grep, py.test, etc ... use the pattern <FileName>:<line number>: to point to errors. For example:



; grep -Hn Common setup.cfg
setup.cfg:11: Common


How can I modify vim and gvim so that I can invoke them like so:



gvim setup.cfg:11:


instead of



gvim setup.cfg +11


I know that I can write a small shell script that would parse things but I wonder if there is an easier way.










share|improve this question


















  • 2




    This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See :help quickfix for more info.
    – Random832
    Oct 5 '12 at 12:48













up vote
20
down vote

favorite
8









up vote
20
down vote

favorite
8






8





Several tools such as grep, py.test, etc ... use the pattern <FileName>:<line number>: to point to errors. For example:



; grep -Hn Common setup.cfg
setup.cfg:11: Common


How can I modify vim and gvim so that I can invoke them like so:



gvim setup.cfg:11:


instead of



gvim setup.cfg +11


I know that I can write a small shell script that would parse things but I wonder if there is an easier way.










share|improve this question













Several tools such as grep, py.test, etc ... use the pattern <FileName>:<line number>: to point to errors. For example:



; grep -Hn Common setup.cfg
setup.cfg:11: Common


How can I modify vim and gvim so that I can invoke them like so:



gvim setup.cfg:11:


instead of



gvim setup.cfg +11


I know that I can write a small shell script that would parse things but I wonder if there is an easier way.







vim gvim






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 5 '12 at 7:14









Sardathrion

2,43542249




2,43542249








  • 2




    This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See :help quickfix for more info.
    – Random832
    Oct 5 '12 at 12:48














  • 2




    This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See :help quickfix for more info.
    – Random832
    Oct 5 '12 at 12:48








2




2




This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See :help quickfix for more info.
– Random832
Oct 5 '12 at 12:48




This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See :help quickfix for more info.
– Random832
Oct 5 '12 at 12:48










4 Answers
4






active

oldest

votes

















up vote
14
down vote



accepted










You can use the file:line plugin available here, which does exactly what you want...






share|improve this answer

















  • 1




    It sure does and with the added bonus that you can use vundle to install it.
    – Sardathrion
    Jun 25 '15 at 6:53










  • The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
    – Lekensteyn
    Jul 16 '15 at 9:06


















up vote
9
down vote













There isn't a way, and I think a script is the only way.
The reason being, what if you had a file called setup.cfg:11 and wanted to edit it?



Here is a quick script that does what you want as a oneliner...



editline() { vim ${1%%:*} +${1##*:}; }





share|improve this answer























  • Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
    – Sardathrion
    Oct 5 '12 at 7:44






  • 2




    You can edit a +11 file by saying vim ./+11
    – Julian
    Oct 5 '12 at 7:47


















up vote
2
down vote













With Vundle.vim, add this to your .vimrc:



Plugin 'bogado/file-line'





share|improve this answer























  • @Sardathrion: Which issues do you have?
    – Dorian
    Oct 14 '16 at 0:13










  • I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
    – Sardathrion
    Oct 14 '16 at 6:50


















up vote
0
down vote













You can also use such alias:



alias gd 'set number=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/3/"`; set file=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/2/"`; eval "if ($number == $file) then \
gvim $file \
else \
gvim $file +$number \
endif"'





share|improve this answer








New contributor




user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















    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',
    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%2f49996%2fvim-open-file-and-goto-line-number-using-filenameline-nbr%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    14
    down vote



    accepted










    You can use the file:line plugin available here, which does exactly what you want...






    share|improve this answer

















    • 1




      It sure does and with the added bonus that you can use vundle to install it.
      – Sardathrion
      Jun 25 '15 at 6:53










    • The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
      – Lekensteyn
      Jul 16 '15 at 9:06















    up vote
    14
    down vote



    accepted










    You can use the file:line plugin available here, which does exactly what you want...






    share|improve this answer

















    • 1




      It sure does and with the added bonus that you can use vundle to install it.
      – Sardathrion
      Jun 25 '15 at 6:53










    • The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
      – Lekensteyn
      Jul 16 '15 at 9:06













    up vote
    14
    down vote



    accepted







    up vote
    14
    down vote



    accepted






    You can use the file:line plugin available here, which does exactly what you want...






    share|improve this answer












    You can use the file:line plugin available here, which does exactly what you want...







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 6 '14 at 16:59









    mmigdol

    25623




    25623








    • 1




      It sure does and with the added bonus that you can use vundle to install it.
      – Sardathrion
      Jun 25 '15 at 6:53










    • The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
      – Lekensteyn
      Jul 16 '15 at 9:06














    • 1




      It sure does and with the added bonus that you can use vundle to install it.
      – Sardathrion
      Jun 25 '15 at 6:53










    • The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
      – Lekensteyn
      Jul 16 '15 at 9:06








    1




    1




    It sure does and with the added bonus that you can use vundle to install it.
    – Sardathrion
    Jun 25 '15 at 6:53




    It sure does and with the added bonus that you can use vundle to install it.
    – Sardathrion
    Jun 25 '15 at 6:53












    The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
    – Lekensteyn
    Jul 16 '15 at 9:06




    The references file-line plugin has some issues, including brokeness when tab pages are in use. vim-fetch does what file-line does, but better.
    – Lekensteyn
    Jul 16 '15 at 9:06












    up vote
    9
    down vote













    There isn't a way, and I think a script is the only way.
    The reason being, what if you had a file called setup.cfg:11 and wanted to edit it?



    Here is a quick script that does what you want as a oneliner...



    editline() { vim ${1%%:*} +${1##*:}; }





    share|improve this answer























    • Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
      – Sardathrion
      Oct 5 '12 at 7:44






    • 2




      You can edit a +11 file by saying vim ./+11
      – Julian
      Oct 5 '12 at 7:47















    up vote
    9
    down vote













    There isn't a way, and I think a script is the only way.
    The reason being, what if you had a file called setup.cfg:11 and wanted to edit it?



    Here is a quick script that does what you want as a oneliner...



    editline() { vim ${1%%:*} +${1##*:}; }





    share|improve this answer























    • Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
      – Sardathrion
      Oct 5 '12 at 7:44






    • 2




      You can edit a +11 file by saying vim ./+11
      – Julian
      Oct 5 '12 at 7:47













    up vote
    9
    down vote










    up vote
    9
    down vote









    There isn't a way, and I think a script is the only way.
    The reason being, what if you had a file called setup.cfg:11 and wanted to edit it?



    Here is a quick script that does what you want as a oneliner...



    editline() { vim ${1%%:*} +${1##*:}; }





    share|improve this answer














    There isn't a way, and I think a script is the only way.
    The reason being, what if you had a file called setup.cfg:11 and wanted to edit it?



    Here is a quick script that does what you want as a oneliner...



    editline() { vim ${1%%:*} +${1##*:}; }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 5 '12 at 7:48

























    answered Oct 5 '12 at 7:38









    Julian

    66944




    66944












    • Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
      – Sardathrion
      Oct 5 '12 at 7:44






    • 2




      You can edit a +11 file by saying vim ./+11
      – Julian
      Oct 5 '12 at 7:47


















    • Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
      – Sardathrion
      Oct 5 '12 at 7:44






    • 2




      You can edit a +11 file by saying vim ./+11
      – Julian
      Oct 5 '12 at 7:47
















    Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
    – Sardathrion
    Oct 5 '12 at 7:44




    Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that.
    – Sardathrion
    Oct 5 '12 at 7:44




    2




    2




    You can edit a +11 file by saying vim ./+11
    – Julian
    Oct 5 '12 at 7:47




    You can edit a +11 file by saying vim ./+11
    – Julian
    Oct 5 '12 at 7:47










    up vote
    2
    down vote













    With Vundle.vim, add this to your .vimrc:



    Plugin 'bogado/file-line'





    share|improve this answer























    • @Sardathrion: Which issues do you have?
      – Dorian
      Oct 14 '16 at 0:13










    • I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
      – Sardathrion
      Oct 14 '16 at 6:50















    up vote
    2
    down vote













    With Vundle.vim, add this to your .vimrc:



    Plugin 'bogado/file-line'





    share|improve this answer























    • @Sardathrion: Which issues do you have?
      – Dorian
      Oct 14 '16 at 0:13










    • I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
      – Sardathrion
      Oct 14 '16 at 6:50













    up vote
    2
    down vote










    up vote
    2
    down vote









    With Vundle.vim, add this to your .vimrc:



    Plugin 'bogado/file-line'





    share|improve this answer














    With Vundle.vim, add this to your .vimrc:



    Plugin 'bogado/file-line'






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 17 at 10:17

























    answered Oct 12 '16 at 15:56









    Dorian

    1214




    1214












    • @Sardathrion: Which issues do you have?
      – Dorian
      Oct 14 '16 at 0:13










    • I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
      – Sardathrion
      Oct 14 '16 at 6:50


















    • @Sardathrion: Which issues do you have?
      – Dorian
      Oct 14 '16 at 0:13










    • I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
      – Sardathrion
      Oct 14 '16 at 6:50
















    @Sardathrion: Which issues do you have?
    – Dorian
    Oct 14 '16 at 0:13




    @Sardathrion: Which issues do you have?
    – Dorian
    Oct 14 '16 at 0:13












    I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
    – Sardathrion
    Oct 14 '16 at 6:50




    I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible.
    – Sardathrion
    Oct 14 '16 at 6:50










    up vote
    0
    down vote













    You can also use such alias:



    alias gd 'set number=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/3/"`; set file=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/2/"`; eval "if ($number == $file) then \
    gvim $file \
    else \
    gvim $file +$number \
    endif"'





    share|improve this answer








    New contributor




    user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote













      You can also use such alias:



      alias gd 'set number=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/3/"`; set file=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/2/"`; eval "if ($number == $file) then \
      gvim $file \
      else \
      gvim $file +$number \
      endif"'





      share|improve this answer








      New contributor




      user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        0
        down vote










        up vote
        0
        down vote









        You can also use such alias:



        alias gd 'set number=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/3/"`; set file=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/2/"`; eval "if ($number == $file) then \
        gvim $file \
        else \
        gvim $file +$number \
        endif"'





        share|improve this answer








        New contributor




        user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        You can also use such alias:



        alias gd 'set number=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/3/"`; set file=`echo !:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/2/"`; eval "if ($number == $file) then \
        gvim $file \
        else \
        gvim $file +$number \
        endif"'






        share|improve this answer








        New contributor




        user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Dec 3 at 8:05









        user2683458

        1




        1




        New contributor




        user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        user2683458 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f49996%2fvim-open-file-and-goto-line-number-using-filenameline-nbr%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

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux