Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I traverse functions with jump list? #479

Closed
goodpaperman opened this issue Feb 6, 2023 · 16 comments
Closed

How can I traverse functions with jump list? #479

goodpaperman opened this issue Feb 6, 2023 · 16 comments
Labels
educational Issues that contain useful content enhancement New feature or request

Comments

@goodpaperman
Copy link

goodpaperman commented Feb 6, 2023

Feature description

commonly I use g + d/D/h jump between functions, from calling point to definition, and vice versa.
I go back and forth by Ctrl + I/O with jump stacks, but when I do some searches between function jumps, it becomes a real mess !

so, I want to know if there any standalone jump stack for functions (and shortcuts, too), it will be useful if one just want to read code, after reading currrent function, he can go back the calling place by a simple command, no matter how many searches there are in this file.

can nvim support this feature? or tell me how if it has been supported.
thanks a lot~

Additional information

jump stacks in vim (:ls)
图片

@goodpaperman goodpaperman added the enhancement New feature or request label Feb 6, 2023
@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

You want a new keymap to back and forth for the jumps which are just caused by gD?

@goodpaperman
Copy link
Author

goodpaperman commented Feb 6, 2023

g + D/d/h,all jumps about function, and live_grep jumps if possible

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

Maybe a stand alone plugin is needed to solve it.

@CharlesChiuGit
Copy link
Collaborator

Perhaps this one:
https:/cbochs/portal.nvim

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Feb 6, 2023

@goodpaperman P.S. The official term in nvim of jump stack is "jump list".

@Jint-lzxy
Copy link
Collaborator

@goodpaperman I would like to provide a vim-builtin solution. If you need a location that you can jump to that is independent of what you do later, you can use a global mark (m[A-Z] to mark and `(or ')[A-Z] to goto a mark). This is extremely useful if your requirement is to "go back to the calling place". You may have your own marking rules so that you can mark in that order and return to the place you want. After a period of adaptation, you will find out that this feature can actually take you to anywhere you want.

:h mark

AFAIK Bram doesn't have a plan to implement features like "jump list modification". (Sorry I can't find that issue for the time being)

@goodpaperman
Copy link
Author

@goodpaperman P.S. The official term in nvim of jump stack is "jump list".

that's right

@goodpaperman
Copy link
Author

@goodpaperman I would like to provide a vim-builtin solution. If you need a location that you can jump to that is independent of what you do later, you can use a global mark (m[A-Z] to mark and `(or ')[A-Z] to goto a mark). This is extremely useful if your requirement is to "go back to the calling place". You may have your own marking rules so that you can mark in that order and return to the place you want. After a period of adaptation, you will find out that this feature can actually take you to anywhere you want.

:h mark

AFAIK Bram doesn't have a plan to implement features like "jump list modification". (Sorry I can't find that issue for the time being)

do you meaning make the function jump list by global mark? some comstomization is needed, I think.
Using marks directly is inconvenient in my situation.

@goodpaperman
Copy link
Author

goodpaperman commented Feb 7, 2023

Perhaps this one: https:/cbochs/portal.nvim

It seems to be a jump list manager, not what I want

@Jint-lzxy
Copy link
Collaborator

@goodpaperman I would like to provide a vim-builtin solution. If you need a location that you can jump to that is independent of what you do later, you can use a global mark (m[A-Z] to mark and `(or ')[A-Z] to goto a mark). This is extremely useful if your requirement is to "go back to the calling place". You may have your own marking rules so that you can mark in that order and return to the place you want. After a period of adaptation, you will find out that this feature can actually take you to anywhere you want.
:h mark
AFAIK Bram doesn't have a plan to implement features like "jump list modification". (Sorry I can't find that issue for the time being)

do you meaning make the function jump list by global mark? some comstomization is needed, I think. Using marks directly is inconvenient in my situation.

Yep, but you can go far beyond this. First you should create a mark list (the marks in this list are not commonly used [directly]), and then implement this feature by maintaining a stack + calling Lspsaga goto_definition. You can set a custom keymap to directly call this function.

@goodpaperman
Copy link
Author

Quantitative limitation for this solution? vim has 26 global marks at most, when I browse large project, that maybe not enough..

@Jint-lzxy
Copy link
Collaborator

Quantitative limitation for this solution? vim has 26 global marks at most, when I browse large project, that maybe not enough..

Then from another perspective. If you just don't want search jumps to be recorded in the jump list, you could define your own mapping like this (just an example):

["n|<A-n>"] = map_cr("keepjumps normal n"):with_noremap():with_silent(), -- search forward

:h :keepjumps


p.s., You can also use <leader>h to switch between the header file and corresponding source code if it's a C-family project.

nvimdots/lua/core/event.lua

Lines 107 to 111 in d0d63ad

{
"FileType",
"c,cpp",
"nnoremap <leader>h :ClangdSwitchSourceHeaderVSplit<CR>",
},

If you don't prefer to open this in a split, you can change it to:

"nnoremap <silent> <leader>h :ClangdSwitchSourceHeader<CR>",

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Feb 7, 2023

It seems to be a jump list manager, not what I want

how about this?

https:/asbjornhaland/telescope-send-to-harpoon.nvim

with harpoon.nvim

https://youtu.be/Qnos8aApa9g

@CharlesChiuGit CharlesChiuGit changed the title can I traverse the function jump stack ? Can I traverse functions with jump list? Feb 7, 2023
@CharlesChiuGit CharlesChiuGit changed the title Can I traverse functions with jump list? How can I traverse functions with jump list? Feb 7, 2023
@goodpaperman
Copy link
Author

Quantitative limitation for this solution? vim has 26 global marks at most, when I browse large project, that maybe not enough..

Then from another perspective. If you just don't want search jumps to be recorded in the jump list, you could define your own mapping like this (just an example):

["n|<A-n>"] = map_cr("keepjumps normal n"):with_noremap():with_silent(), -- search forward

:h :keepjumps

p.s., You can also use <leader>h to switch between the header file and corresponding source code if it's a C-family project.

nvimdots/lua/core/event.lua

Lines 107 to 111 in d0d63ad

{
"FileType",
"c,cpp",
"nnoremap <leader>h :ClangdSwitchSourceHeaderVSplit<CR>",
},

If you don't prefer to open this in a split, you can change it to:

"nnoremap <silent> <leader>h :ClangdSwitchSourceHeader<CR>",

I know your idea: filter out other jumps to keep the jump list only record function jumps.
that's novel, I will consider.

knowlege about switch between cpp & h is useful, I have change my configures. thanks a lot~

@goodpaperman
Copy link
Author

It seems to be a jump list manager, not what I want

how about this?

https:/asbjornhaland/telescope-send-to-harpoon.nvim

with harpoon.nvim

https://youtu.be/Qnos8aApa9g

Learn much from the demo video, harpoon focus on jumps between files, auto saves positions when switch buffer or quit, but jumps inside a large file is not supported, maybe need a little customize, I will refer to it, thanks a lot~

@CharlesChiuGit CharlesChiuGit added the educational Issues that contain useful content label Feb 12, 2023
@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Feb 13, 2023

@goodpaperman I think maybe you'll be interested with this plugin: https:/DNLHC/glance.nvim

@ayamir ayamir closed this as completed Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
educational Issues that contain useful content enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants