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;
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
add a comment |
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
add a comment |
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
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
search mark jump
asked Jul 17 at 19:04
LuxGiammiLuxGiammi
1283 bronze badges
1283 bronze badges
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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
.
add a comment |
Two options I can think of off the top of my head:
:[v]split
, then search in only one window:nnoremap / mz/
; then`z
should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)
add a comment |
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.
add a comment |
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.)
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 storegetpos()
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered Jul 17 at 20:20
kaankaan
1115 bronze badges
1115 bronze badges
add a comment |
add a comment |
Two options I can think of off the top of my head:
:[v]split
, then search in only one window:nnoremap / mz/
; then`z
should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)
add a comment |
Two options I can think of off the top of my head:
:[v]split
, then search in only one window:nnoremap / mz/
; then`z
should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)
add a comment |
Two options I can think of off the top of my head:
:[v]split
, then search in only one window:nnoremap / mz/
; then`z
should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)
Two options I can think of off the top of my head:
:[v]split
, then search in only one window:nnoremap / mz/
; then`z
should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)
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
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jul 18 at 5:10
MattMatt
3063 bronze badges
3063 bronze badges
add a comment |
add a comment |
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.)
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 storegetpos()
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
add a comment |
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.)
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 storegetpos()
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
add a comment |
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.)
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.)
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 storegetpos()
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
add a comment |
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 storegetpos()
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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