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

                                        Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

                                        Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form