vim shortcut to open a file under cursor in an already opened window












9














In vim you can open a file under the cursor by using the gf command.



One can also easily open that file in a new split window by hitting <c-w> f. This is a really nice and time saving feature.



However, I can't figure out, how to open the file in an already opened split window (without creating a new one).










share|improve this question




















  • 1




    You may want to have a look at the preview feature (see :h preview).
    – Stéphane Chazelas
    May 3 '13 at 15:01










  • Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
    – psibar
    May 3 '13 at 15:04
















9














In vim you can open a file under the cursor by using the gf command.



One can also easily open that file in a new split window by hitting <c-w> f. This is a really nice and time saving feature.



However, I can't figure out, how to open the file in an already opened split window (without creating a new one).










share|improve this question




















  • 1




    You may want to have a look at the preview feature (see :h preview).
    – Stéphane Chazelas
    May 3 '13 at 15:01










  • Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
    – psibar
    May 3 '13 at 15:04














9












9








9


3





In vim you can open a file under the cursor by using the gf command.



One can also easily open that file in a new split window by hitting <c-w> f. This is a really nice and time saving feature.



However, I can't figure out, how to open the file in an already opened split window (without creating a new one).










share|improve this question















In vim you can open a file under the cursor by using the gf command.



One can also easily open that file in a new split window by hitting <c-w> f. This is a really nice and time saving feature.



However, I can't figure out, how to open the file in an already opened split window (without creating a new one).







vim vi editors key-mapping gvim






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 3 '13 at 14:37

























asked May 3 '13 at 13:08









psibar

21628




21628








  • 1




    You may want to have a look at the preview feature (see :h preview).
    – Stéphane Chazelas
    May 3 '13 at 15:01










  • Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
    – psibar
    May 3 '13 at 15:04














  • 1




    You may want to have a look at the preview feature (see :h preview).
    – Stéphane Chazelas
    May 3 '13 at 15:01










  • Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
    – psibar
    May 3 '13 at 15:04








1




1




You may want to have a look at the preview feature (see :h preview).
– Stéphane Chazelas
May 3 '13 at 15:01




You may want to have a look at the preview feature (see :h preview).
– Stéphane Chazelas
May 3 '13 at 15:01












Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04




Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04










3 Answers
3






active

oldest

votes


















7














I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:



 map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p


Explanation:





  • map <F8> maps on "F8" the commands that follow


  • let mycurf=expand("<cfile>") gets the filename under the cursor and saves it in mycurf


  • <c-w>w changes the focus to the next open split window


  • execute("e ".mycurf) opens the file saved in mycurf

  • finally <c-w>p changes the focus to the previous window (where we actually came from)






share|improve this answer































    0














    That can't be done easily. A [count] before <C-w>f specifies which file match on 'path' is opened, it does not select an existing window. Only for the <C-w>w command, [count] means "go to existing window number".



    To get that functionality, you need to write a custom mapping which either




    • grabs the file, goes to the [count] window and emulates the gf command, or

    • clones the current buffer to the [count] window, and executes gf there






    share|improve this answer





















    • Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
      – psibar
      May 3 '13 at 14:13



















    0














    I searched for the same VIm's function and found out this solution which works like charm:



    map <F8> :vertical wincmd f<CR>


    Source page.






    share|improve this answer





















      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%2f74571%2fvim-shortcut-to-open-a-file-under-cursor-in-an-already-opened-window%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:



       map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p


      Explanation:





      • map <F8> maps on "F8" the commands that follow


      • let mycurf=expand("<cfile>") gets the filename under the cursor and saves it in mycurf


      • <c-w>w changes the focus to the next open split window


      • execute("e ".mycurf) opens the file saved in mycurf

      • finally <c-w>p changes the focus to the previous window (where we actually came from)






      share|improve this answer




























        7














        I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:



         map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p


        Explanation:





        • map <F8> maps on "F8" the commands that follow


        • let mycurf=expand("<cfile>") gets the filename under the cursor and saves it in mycurf


        • <c-w>w changes the focus to the next open split window


        • execute("e ".mycurf) opens the file saved in mycurf

        • finally <c-w>p changes the focus to the previous window (where we actually came from)






        share|improve this answer


























          7












          7








          7






          I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:



           map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p


          Explanation:





          • map <F8> maps on "F8" the commands that follow


          • let mycurf=expand("<cfile>") gets the filename under the cursor and saves it in mycurf


          • <c-w>w changes the focus to the next open split window


          • execute("e ".mycurf) opens the file saved in mycurf

          • finally <c-w>p changes the focus to the previous window (where we actually came from)






          share|improve this answer














          I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:



           map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p


          Explanation:





          • map <F8> maps on "F8" the commands that follow


          • let mycurf=expand("<cfile>") gets the filename under the cursor and saves it in mycurf


          • <c-w>w changes the focus to the next open split window


          • execute("e ".mycurf) opens the file saved in mycurf

          • finally <c-w>p changes the focus to the previous window (where we actually came from)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 3 '13 at 16:07









          Damien

          498513




          498513










          answered May 3 '13 at 14:29









          psibar

          21628




          21628

























              0














              That can't be done easily. A [count] before <C-w>f specifies which file match on 'path' is opened, it does not select an existing window. Only for the <C-w>w command, [count] means "go to existing window number".



              To get that functionality, you need to write a custom mapping which either




              • grabs the file, goes to the [count] window and emulates the gf command, or

              • clones the current buffer to the [count] window, and executes gf there






              share|improve this answer





















              • Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
                – psibar
                May 3 '13 at 14:13
















              0














              That can't be done easily. A [count] before <C-w>f specifies which file match on 'path' is opened, it does not select an existing window. Only for the <C-w>w command, [count] means "go to existing window number".



              To get that functionality, you need to write a custom mapping which either




              • grabs the file, goes to the [count] window and emulates the gf command, or

              • clones the current buffer to the [count] window, and executes gf there






              share|improve this answer





















              • Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
                – psibar
                May 3 '13 at 14:13














              0












              0








              0






              That can't be done easily. A [count] before <C-w>f specifies which file match on 'path' is opened, it does not select an existing window. Only for the <C-w>w command, [count] means "go to existing window number".



              To get that functionality, you need to write a custom mapping which either




              • grabs the file, goes to the [count] window and emulates the gf command, or

              • clones the current buffer to the [count] window, and executes gf there






              share|improve this answer












              That can't be done easily. A [count] before <C-w>f specifies which file match on 'path' is opened, it does not select an existing window. Only for the <C-w>w command, [count] means "go to existing window number".



              To get that functionality, you need to write a custom mapping which either




              • grabs the file, goes to the [count] window and emulates the gf command, or

              • clones the current buffer to the [count] window, and executes gf there







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 3 '13 at 14:00









              Ingo Karkat

              8,53911832




              8,53911832












              • Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
                – psibar
                May 3 '13 at 14:13


















              • Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
                – psibar
                May 3 '13 at 14:13
















              Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
              – psibar
              May 3 '13 at 14:13




              Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
              – psibar
              May 3 '13 at 14:13











              0














              I searched for the same VIm's function and found out this solution which works like charm:



              map <F8> :vertical wincmd f<CR>


              Source page.






              share|improve this answer


























                0














                I searched for the same VIm's function and found out this solution which works like charm:



                map <F8> :vertical wincmd f<CR>


                Source page.






                share|improve this answer
























                  0












                  0








                  0






                  I searched for the same VIm's function and found out this solution which works like charm:



                  map <F8> :vertical wincmd f<CR>


                  Source page.






                  share|improve this answer












                  I searched for the same VIm's function and found out this solution which works like charm:



                  map <F8> :vertical wincmd f<CR>


                  Source page.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  waldauf

                  9018




                  9018






























                      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%2f74571%2fvim-shortcut-to-open-a-file-under-cursor-in-an-already-opened-window%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

                      Accessing regular linux commands in Huawei's Dopra Linux

                      Can't connect RFCOMM socket: Host is down

                      Kernel panic - not syncing: Fatal Exception in Interrupt