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

Defaults: map gd to CTRL-] #28476

Open
gpanders opened this issue Apr 23, 2024 · 10 comments
Open

Defaults: map gd to CTRL-] #28476

gpanders opened this issue Apr 23, 2024 · 10 comments
Labels
defaults issues or PRs involving changing the defaults enhancement feature request

Comments

@gpanders
Copy link
Member

gpanders commented Apr 23, 2024

The default mapping for "jump to tag" is <C-]>, but this is awkward or difficult to type on some keyboards.

Nvim's LSP client sets tagfunc by default which enables jumping to a definition with <C-]>. gd is a very popular custom mapping for jumping to a definition, so mapping gd to <C-]> would essentially provide that mapping for free.

We could either do this universally, or only when an LSP buffer is attached. One downside of doing it universally is that if an LSP buffer is not attached, and there are no valid tags files, then we lose the builtin gd behavior (which is, frankly, not very good, but some people may rely on it).

Note that we do not simply map gd to vim.lsp.buf.definition() by default because using 'tagfunc' provides a lot of other useful functionality (opening a definition in a split, searching for identifiers with :ts, etc.).

EDIT: This is really only useful if mapping gd to <C-]> also gets us <C-W>gd "for free", which I'm not sure if it does.

@zeertzjq zeertzjq added enhancement feature request defaults issues or PRs involving changing the defaults labels Apr 23, 2024
@altermo
Copy link
Contributor

altermo commented Apr 24, 2024

We could also do <C-]> when either 'tagfunc' is defined or when len(tagfiles()) is over 0, and otherwise gd.

Example keymap
vim.keymap.set('n', 'gd', function()
    if vim.o.tagfunc ~= '' or #vim.fn.tagfiles() > 0 then
        return '<C-]>'
    end
    return 'gd'
end, { expr = true })

Or we also could do that if <C-]> errors with E426: Tag not found or E433: No tags file then fallback to gd, though this may require som C code changes.

@mfussenegger
Copy link
Member

Note that we currently also have the unmapped:

  • vim.lsp.buf.declaration()
  • vim.lsp.buf.implementation()
  • vim.lsp.buf.type_definition()

all of which also fit into the gd / gD area. My vote would go towards using the gd and gD to cover these by default instead of having two ways for go-to-definition.

@bluss

This comment was marked as off-topic.

@clason

This comment was marked as off-topic.

@kaddkaka
Copy link
Contributor

In help pages K can be used to follow tags and links, I'm not sure if this should be considered for following tags in general.

@gpanders
Copy link
Member Author

The original justification for this suggestion was that it was awkward or difficult to use <C-]> on some keyboards, though that appears to not actually be the case? (cc @dundargoc). In that case we can drop the original proposal and repurpose this issue for establishing other defaults that @mfussenegger suggested.

@gegoune
Copy link
Sponsor

gegoune commented Apr 24, 2024

difficult to use <C-]> on some keyboards, though that appears to not actually be the case?

I am using corne keyboard and it is somewhat inconvenient indeed.
(I like staying as close to defaults as possible and was looking forward for this proposal to materialise.)

@dundargoc
Copy link
Member

dundargoc commented Apr 24, 2024

The context is that is that <C-]> did not work for me. I had initially
assumed this was a problem with the ] character and that there was a problem
interpreting the combination needed to write ] (which on swedish mac is
Option+9). The reason for this assumption was because e.g. <C-i> and <C-o>
worked as documented.

This is completely incorrect. It turns out <C-]> does not mean Ctrl + ],
it means byte 29 (unsure about the correct terminology) as described in
https://ss64.com/ascii.html. In layman's terms, it will be Ctrl + the key
that is on the same location as ] in an american keyboard. On Swedish
keyboards, which I use, <C-]> is actually a combination of Ctrl + ¨. On
French keyboards, it is Ctrl + $. On Cyrillic keyboards it is Ctrl + ъ.

This phenomenon is not isolated to ], I just never noticed the other cases as
Swedish and American keyboards happens to coincide for other characters. But
for Cyrillic keyboards for example, <C-o> is actually a combination of
CTRL+щ and <C-i> is CTRL+ш.

@justinmk
Copy link
Member

In layman's terms, it will be Ctrl + the key
that is on the same location as ] in an american keyboard. On Swedish
keyboards, which I use, <C-]> is actually a combination of Ctrl + ¨. On
French keyboards, it is Ctrl + $. On Cyrillic keyboards it is Ctrl + ъ.

Seems worth mentioning at :help ctrl-]. That lets us use gd for something else (as discussed above).

@bluss

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defaults issues or PRs involving changing the defaults enhancement feature request
Projects
None yet
Development

No branches or pull requests

10 participants