Opening most recently modified file in vim

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











up vote
1
down vote

favorite












The following commands work



$ ls -1t | head -1
git_sync_log20180924_00.txt

$ vi git_sync_log20180924_00.txt


But this does not



$ ls -1t | head -1 | vi
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.


How can I accomplish this (open most recently modified file in vi)?










share|improve this question



























    up vote
    1
    down vote

    favorite












    The following commands work



    $ ls -1t | head -1
    git_sync_log20180924_00.txt

    $ vi git_sync_log20180924_00.txt


    But this does not



    $ ls -1t | head -1 | vi
    Vim: Warning: Input is not from a terminal
    Vim: Error reading input, exiting...
    Vim: preserving files...
    Vim: Finished.


    How can I accomplish this (open most recently modified file in vi)?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      The following commands work



      $ ls -1t | head -1
      git_sync_log20180924_00.txt

      $ vi git_sync_log20180924_00.txt


      But this does not



      $ ls -1t | head -1 | vi
      Vim: Warning: Input is not from a terminal
      Vim: Error reading input, exiting...
      Vim: preserving files...
      Vim: Finished.


      How can I accomplish this (open most recently modified file in vi)?










      share|improve this question















      The following commands work



      $ ls -1t | head -1
      git_sync_log20180924_00.txt

      $ vi git_sync_log20180924_00.txt


      But this does not



      $ ls -1t | head -1 | vi
      Vim: Warning: Input is not from a terminal
      Vim: Error reading input, exiting...
      Vim: preserving files...
      Vim: Finished.


      How can I accomplish this (open most recently modified file in vi)?







      shell pipe vi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 mins ago

























      asked 16 mins ago









      Renu

      1114




      1114




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          vim -- "$(ls -t | head -n 1)"


          (that assumes file names don't contain newline characters).



          Or if using zsh:



          vim -- *(om[1])


          Or:



          vim -- *(.om[1])


          To only consider regular files.






          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f471080%2fopening-most-recently-modified-file-in-vim%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            vim -- "$(ls -t | head -n 1)"


            (that assumes file names don't contain newline characters).



            Or if using zsh:



            vim -- *(om[1])


            Or:



            vim -- *(.om[1])


            To only consider regular files.






            share|improve this answer
























              up vote
              3
              down vote













              vim -- "$(ls -t | head -n 1)"


              (that assumes file names don't contain newline characters).



              Or if using zsh:



              vim -- *(om[1])


              Or:



              vim -- *(.om[1])


              To only consider regular files.






              share|improve this answer






















                up vote
                3
                down vote










                up vote
                3
                down vote









                vim -- "$(ls -t | head -n 1)"


                (that assumes file names don't contain newline characters).



                Or if using zsh:



                vim -- *(om[1])


                Or:



                vim -- *(.om[1])


                To only consider regular files.






                share|improve this answer












                vim -- "$(ls -t | head -n 1)"


                (that assumes file names don't contain newline characters).



                Or if using zsh:



                vim -- *(om[1])


                Or:



                vim -- *(.om[1])


                To only consider regular files.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 12 mins ago









                Stéphane Chazelas

                285k53525865




                285k53525865



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471080%2fopening-most-recently-modified-file-in-vim%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery