Jump back to the position I started a searchHow can I make the “gn” motion wrap to the beginning of the file?How to show search results for all open buffersHow to setup AG (the silver searcher) in vim?How can I make a search in vimscript let n and N look for more?How do I jump back to the next-to-last insert position?Find first occurrence of string or return end of fileIs it possible to use the :put Ex command using column numbers?How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?Vim can't search for dotSearch for line, move to end of search string, then search+replace

May a man marry the women with whom he committed adultery?

The best place for swimming in Arctic Ocean

Old French song lyrics with the word "baiser."

How did the Axis intend to hold the Caucasus?

Is there an antonym for "spicy" or "hot" regarding food (NOT "seasoned" but "spicy")?

How can I rectify up to 85 kV

Where to find an interactive PDF or HTML version of the tex.web documentation?

Pointwise convergence of uniformly continuous functions to zero, but not uniformly

Did the IBM PC use the 8088's NMI line?

Is a topological space considered to be a class in set theory?

How do I stop my characters falling in love?

Unethical behavior : should I report it?

Why does Canada require mandatory bilingualism in all government posts?

Are there any examples of technologies have been lost over time?

Commercial jet accompanied by small plane near Seattle

Converting 8V AC to 8V DC - bridge rectifier gets very hot while idling

What is this spacecraft tethered to another spacecraft in LEO (vintage)

How to apply the changes to my `.zshrc` file after edit?

Suggestions for protecting jeans from saddle clamp bolt

Vertical tennis ball into fancy new enumerate

What are the different qualities of the intervals?

(2 of 11: Moon-or-Sun) What is Pyramid Cult's Favorite Camera?

Why/when is AC-DC-AC conversion superior to direct AC-AC conversion?

Request for a Latin phrase as motto "God is highest/supreme"



Jump back to the position I started a search


How can I make the “gn” motion wrap to the beginning of the file?How to show search results for all open buffersHow to setup AG (the silver searcher) in vim?How can I make a search in vimscript let n and N look for more?How do I jump back to the next-to-last insert position?Find first occurrence of string or return end of fileIs it possible to use the :put Ex command using column numbers?How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?Vim can't search for dotSearch for line, move to end of search string, then search+replace






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have a small question: let's suppose I'm at the beginning of line 10 and I search a term with the command /term_to_search and then I press <Enter> to start navigating search results with n or N. Then I want to go back to the location I were before starting the search (the beginning of line 10). How can I do? I know that the commands CTRL+O and CTRL+I jump back and forth the list of jumps, but how can I do it in just one keypress? Do I need to define a new special mark to do that (if so, how)?



Thanks in advance.










share|improve this question




























    2















    I have a small question: let's suppose I'm at the beginning of line 10 and I search a term with the command /term_to_search and then I press <Enter> to start navigating search results with n or N. Then I want to go back to the location I were before starting the search (the beginning of line 10). How can I do? I know that the commands CTRL+O and CTRL+I jump back and forth the list of jumps, but how can I do it in just one keypress? Do I need to define a new special mark to do that (if so, how)?



    Thanks in advance.










    share|improve this question
























      2












      2








      2








      I have a small question: let's suppose I'm at the beginning of line 10 and I search a term with the command /term_to_search and then I press <Enter> to start navigating search results with n or N. Then I want to go back to the location I were before starting the search (the beginning of line 10). How can I do? I know that the commands CTRL+O and CTRL+I jump back and forth the list of jumps, but how can I do it in just one keypress? Do I need to define a new special mark to do that (if so, how)?



      Thanks in advance.










      share|improve this question














      I have a small question: let's suppose I'm at the beginning of line 10 and I search a term with the command /term_to_search and then I press <Enter> to start navigating search results with n or N. Then I want to go back to the location I were before starting the search (the beginning of line 10). How can I do? I know that the commands CTRL+O and CTRL+I jump back and forth the list of jumps, but how can I do it in just one keypress? Do I need to define a new special mark to do that (if so, how)?



      Thanks in advance.







      search mark jump






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 17 at 19:04









      LuxGiammiLuxGiammi

      1283 bronze badges




      1283 bronze badges




















          4 Answers
          4






          active

          oldest

          votes


















          5














          I do this by first creating a mark - for example, create a mark named "a" with ma in command mode – then search or move around the file however you want. Then go back to your mark with 'a.






          share|improve this answer






























            3














            Two options I can think of off the top of my head:




            1. :[v]split, then search in only one window


            2. :nnoremap / mz/; then `z should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)





            share|improve this answer






























              2















              let's suppose I'm at the beginning of line 10




              Then the easiest way back is 10G or :10. It's not that useless if you have line numbers on and your memory is not bad either.



              Also, sometimes the command g; (go back one position in the change list) proves to be be useful.






              share|improve this answer






























                0














                If, contrary to my initial thinking, OP just wants a way to do what they describe manually (and the voting so far suggests that's most people are reading it that way) then this is overkill. But if one wants a transparent, automated method that allows return to search start any time w/o having to think about it ahead of time....this should help...



                If we want to get a little fancier (though still down and dirty) we can create an autocommand and a mapping like so...



                augroup searchorigin
                autocmd!
                au CmdLineLeave * let b:cmdtype = expand('<afile>') | if (b:cmdtype == '/' || b:cmdtype == '?') | let b:searchorigin = getpos(".") | endif
                augroup END

                nnoremap <leader>/ :exec 'call setpos(".", b:searchorigin)'<CR>


                The autocommand will record the starting point of your current search in a buffer-local variable, allowing this to work simultaneously on different searches occurring in different buffers. The mapping will move the cursor back to that point using that variable.



                So just start a search as you always do and then hit / and you'll be back to the start point. (Replace <leader>/ in the mapping with whatever free key(s) you desire.)






                share|improve this answer

























                • Registers != marks, and marks are buffer local for the lowercase.

                  – D. Ben Knoble
                  Jul 18 at 12:39











                • @D.BenKnoble Umm. Okay. Who said otherwise?

                  – B Layer
                  Jul 19 at 11:39











                • read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                  – D. Ben Knoble
                  Jul 19 at 12:41











                • My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                  – B Layer
                  Jul 19 at 18:24













                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "599"
                ;
                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%2fvi.stackexchange.com%2fquestions%2f20650%2fjump-back-to-the-position-i-started-a-search%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









                5














                I do this by first creating a mark - for example, create a mark named "a" with ma in command mode – then search or move around the file however you want. Then go back to your mark with 'a.






                share|improve this answer



























                  5














                  I do this by first creating a mark - for example, create a mark named "a" with ma in command mode – then search or move around the file however you want. Then go back to your mark with 'a.






                  share|improve this answer

























                    5












                    5








                    5







                    I do this by first creating a mark - for example, create a mark named "a" with ma in command mode – then search or move around the file however you want. Then go back to your mark with 'a.






                    share|improve this answer













                    I do this by first creating a mark - for example, create a mark named "a" with ma in command mode – then search or move around the file however you want. Then go back to your mark with 'a.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 17 at 20:20









                    kaankaan

                    1115 bronze badges




                    1115 bronze badges























                        3














                        Two options I can think of off the top of my head:




                        1. :[v]split, then search in only one window


                        2. :nnoremap / mz/; then `z should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)





                        share|improve this answer



























                          3














                          Two options I can think of off the top of my head:




                          1. :[v]split, then search in only one window


                          2. :nnoremap / mz/; then `z should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)





                          share|improve this answer

























                            3












                            3








                            3







                            Two options I can think of off the top of my head:




                            1. :[v]split, then search in only one window


                            2. :nnoremap / mz/; then `z should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)





                            share|improve this answer













                            Two options I can think of off the top of my head:




                            1. :[v]split, then search in only one window


                            2. :nnoremap / mz/; then `z should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jul 17 at 20:08









                            D. Ben KnobleD. Ben Knoble

                            4,0311 gold badge6 silver badges24 bronze badges




                            4,0311 gold badge6 silver badges24 bronze badges





















                                2















                                let's suppose I'm at the beginning of line 10




                                Then the easiest way back is 10G or :10. It's not that useless if you have line numbers on and your memory is not bad either.



                                Also, sometimes the command g; (go back one position in the change list) proves to be be useful.






                                share|improve this answer



























                                  2















                                  let's suppose I'm at the beginning of line 10




                                  Then the easiest way back is 10G or :10. It's not that useless if you have line numbers on and your memory is not bad either.



                                  Also, sometimes the command g; (go back one position in the change list) proves to be be useful.






                                  share|improve this answer

























                                    2












                                    2








                                    2








                                    let's suppose I'm at the beginning of line 10




                                    Then the easiest way back is 10G or :10. It's not that useless if you have line numbers on and your memory is not bad either.



                                    Also, sometimes the command g; (go back one position in the change list) proves to be be useful.






                                    share|improve this answer














                                    let's suppose I'm at the beginning of line 10




                                    Then the easiest way back is 10G or :10. It's not that useless if you have line numbers on and your memory is not bad either.



                                    Also, sometimes the command g; (go back one position in the change list) proves to be be useful.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jul 18 at 5:10









                                    MattMatt

                                    3063 bronze badges




                                    3063 bronze badges





















                                        0














                                        If, contrary to my initial thinking, OP just wants a way to do what they describe manually (and the voting so far suggests that's most people are reading it that way) then this is overkill. But if one wants a transparent, automated method that allows return to search start any time w/o having to think about it ahead of time....this should help...



                                        If we want to get a little fancier (though still down and dirty) we can create an autocommand and a mapping like so...



                                        augroup searchorigin
                                        autocmd!
                                        au CmdLineLeave * let b:cmdtype = expand('<afile>') | if (b:cmdtype == '/' || b:cmdtype == '?') | let b:searchorigin = getpos(".") | endif
                                        augroup END

                                        nnoremap <leader>/ :exec 'call setpos(".", b:searchorigin)'<CR>


                                        The autocommand will record the starting point of your current search in a buffer-local variable, allowing this to work simultaneously on different searches occurring in different buffers. The mapping will move the cursor back to that point using that variable.



                                        So just start a search as you always do and then hit / and you'll be back to the start point. (Replace <leader>/ in the mapping with whatever free key(s) you desire.)






                                        share|improve this answer

























                                        • Registers != marks, and marks are buffer local for the lowercase.

                                          – D. Ben Knoble
                                          Jul 18 at 12:39











                                        • @D.BenKnoble Umm. Okay. Who said otherwise?

                                          – B Layer
                                          Jul 19 at 11:39











                                        • read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                                          – D. Ben Knoble
                                          Jul 19 at 12:41











                                        • My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                                          – B Layer
                                          Jul 19 at 18:24















                                        0














                                        If, contrary to my initial thinking, OP just wants a way to do what they describe manually (and the voting so far suggests that's most people are reading it that way) then this is overkill. But if one wants a transparent, automated method that allows return to search start any time w/o having to think about it ahead of time....this should help...



                                        If we want to get a little fancier (though still down and dirty) we can create an autocommand and a mapping like so...



                                        augroup searchorigin
                                        autocmd!
                                        au CmdLineLeave * let b:cmdtype = expand('<afile>') | if (b:cmdtype == '/' || b:cmdtype == '?') | let b:searchorigin = getpos(".") | endif
                                        augroup END

                                        nnoremap <leader>/ :exec 'call setpos(".", b:searchorigin)'<CR>


                                        The autocommand will record the starting point of your current search in a buffer-local variable, allowing this to work simultaneously on different searches occurring in different buffers. The mapping will move the cursor back to that point using that variable.



                                        So just start a search as you always do and then hit / and you'll be back to the start point. (Replace <leader>/ in the mapping with whatever free key(s) you desire.)






                                        share|improve this answer

























                                        • Registers != marks, and marks are buffer local for the lowercase.

                                          – D. Ben Knoble
                                          Jul 18 at 12:39











                                        • @D.BenKnoble Umm. Okay. Who said otherwise?

                                          – B Layer
                                          Jul 19 at 11:39











                                        • read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                                          – D. Ben Knoble
                                          Jul 19 at 12:41











                                        • My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                                          – B Layer
                                          Jul 19 at 18:24













                                        0












                                        0








                                        0







                                        If, contrary to my initial thinking, OP just wants a way to do what they describe manually (and the voting so far suggests that's most people are reading it that way) then this is overkill. But if one wants a transparent, automated method that allows return to search start any time w/o having to think about it ahead of time....this should help...



                                        If we want to get a little fancier (though still down and dirty) we can create an autocommand and a mapping like so...



                                        augroup searchorigin
                                        autocmd!
                                        au CmdLineLeave * let b:cmdtype = expand('<afile>') | if (b:cmdtype == '/' || b:cmdtype == '?') | let b:searchorigin = getpos(".") | endif
                                        augroup END

                                        nnoremap <leader>/ :exec 'call setpos(".", b:searchorigin)'<CR>


                                        The autocommand will record the starting point of your current search in a buffer-local variable, allowing this to work simultaneously on different searches occurring in different buffers. The mapping will move the cursor back to that point using that variable.



                                        So just start a search as you always do and then hit / and you'll be back to the start point. (Replace <leader>/ in the mapping with whatever free key(s) you desire.)






                                        share|improve this answer















                                        If, contrary to my initial thinking, OP just wants a way to do what they describe manually (and the voting so far suggests that's most people are reading it that way) then this is overkill. But if one wants a transparent, automated method that allows return to search start any time w/o having to think about it ahead of time....this should help...



                                        If we want to get a little fancier (though still down and dirty) we can create an autocommand and a mapping like so...



                                        augroup searchorigin
                                        autocmd!
                                        au CmdLineLeave * let b:cmdtype = expand('<afile>') | if (b:cmdtype == '/' || b:cmdtype == '?') | let b:searchorigin = getpos(".") | endif
                                        augroup END

                                        nnoremap <leader>/ :exec 'call setpos(".", b:searchorigin)'<CR>


                                        The autocommand will record the starting point of your current search in a buffer-local variable, allowing this to work simultaneously on different searches occurring in different buffers. The mapping will move the cursor back to that point using that variable.



                                        So just start a search as you always do and then hit / and you'll be back to the start point. (Replace <leader>/ in the mapping with whatever free key(s) you desire.)







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jul 19 at 18:46

























                                        answered Jul 18 at 10:34









                                        B LayerB Layer

                                        6,8971 gold badge6 silver badges24 bronze badges




                                        6,8971 gold badge6 silver badges24 bronze badges












                                        • Registers != marks, and marks are buffer local for the lowercase.

                                          – D. Ben Knoble
                                          Jul 18 at 12:39











                                        • @D.BenKnoble Umm. Okay. Who said otherwise?

                                          – B Layer
                                          Jul 19 at 11:39











                                        • read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                                          – D. Ben Knoble
                                          Jul 19 at 12:41











                                        • My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                                          – B Layer
                                          Jul 19 at 18:24

















                                        • Registers != marks, and marks are buffer local for the lowercase.

                                          – D. Ben Knoble
                                          Jul 18 at 12:39











                                        • @D.BenKnoble Umm. Okay. Who said otherwise?

                                          – B Layer
                                          Jul 19 at 11:39











                                        • read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                                          – D. Ben Knoble
                                          Jul 19 at 12:41











                                        • My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                                          – B Layer
                                          Jul 19 at 18:24
















                                        Registers != marks, and marks are buffer local for the lowercase.

                                        – D. Ben Knoble
                                        Jul 18 at 12:39





                                        Registers != marks, and marks are buffer local for the lowercase.

                                        – D. Ben Knoble
                                        Jul 18 at 12:39













                                        @D.BenKnoble Umm. Okay. Who said otherwise?

                                        – B Layer
                                        Jul 19 at 11:39





                                        @D.BenKnoble Umm. Okay. Who said otherwise?

                                        – B Layer
                                        Jul 19 at 11:39













                                        read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                                        – D. Ben Knoble
                                        Jul 19 at 12:41





                                        read your last points as counterarguments to the mark answer. I guess you know what they say when you assume 😅

                                        – D. Ben Knoble
                                        Jul 19 at 12:41













                                        My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                                        – B Layer
                                        Jul 19 at 18:24





                                        My first (ill advised) inclination was to store getpos() result in a register...that's the origin of that bullet point (which is kind of superfluous in retrospect).

                                        – B Layer
                                        Jul 19 at 18:24

















                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Vi and Vim 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%2fvi.stackexchange.com%2fquestions%2f20650%2fjump-back-to-the-position-i-started-a-search%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

                                        Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                        Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                                        Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?