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
More options for context menu in general #2674
Comments
Thanks, I'm glad to hear that!
Yes, that was actually sort of the plan. Not necessarily to add everything, but to populate it with more features. But I never really found time or inspiration/motivation to do more than what I've already added.
Thanks. Yes, these things can be implemented to be discoverable with the context feature.
Many of the mentioned features are really close to what I would call "core" Vim concepts. The use of text objects, additional verbs (like "change surrounding", "delete surrounding", "toggle surrounding"), are meant to feel intuitive to experienced Vim users. I understand that this is off putting to less experienced users who are still learning Vim concepts, and I understand that there is a lot to learn and that discoverability can be very useful!
Well, ok; first - I think the context menu can and should be improved with additional features and contexts! But I think there are better alternatives for the "standard" mappings and commands, including compiler commands, and the Thus, for me, the question is: which existing features are less discoverable and will fit in the context menu? This would e.g. be features that don't have an existing default mapping or something that is typically very contextual. I think these may be interesting to consider:
Also, new features that may be useful:
Finally, a short answer to this:
Adding a new context handler should not be very hard*. We need a new module in the code, i.e. a new file under |
which-key.nvimYes, VimTeX works out of the box. Here three screenshots. However, explicit support could be added by providing better descriptions since, e.g. https://github.com/folke/which-key.nvim#-setup
|
Thanks, @kiryph! This does prove my assumption and shows where it works well and where it is clearly lacking. IMHO, it seems to work well for e.g. A solution (for long term future) would be to use lua with the However, I believe it should not be too hard to manually add descriptions here? I'm not very interested in doing that work myself. But if it makes sense to either 1) include it in the repo, or 2) add something about this to the docs, then I would not mind help to do so.
I assume one would need something like this, at some level: wk.register({
ts = {
name = "Toggle surrounding",
e = { "tse", "Environment" },
d = { "tsd", "Delimiter" },
},
cs = {
name = "Change surrounding",
e = { "cse", "Environment" },
d = { "csd", "Delimiter" },
},
}) |
Here a possible user configuration for neovim using which-key.nvim: vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*.tex",
callback = function()
require("vimtexwhichkey")
end,
}) file vimtexwhichkey.lua-- file vimtexwhichkey.lua
local wk = require("which-key")
local opts = {
mode = "n", -- NORMAL mode
buffer = vim.api.nvim_get_current_buf(), -- Specify a buffer number for buffer local mappings to show only in tex buffers
}
local mappings = {
["<localleader>l"] = {
name = "+VimTeX",
a = "Show Context Menu",
C = "Full Clean",
c = "Clean",
e = "Show Errors",
G = "Show Status for All",
g = "Show Status",
i = "Show Info",
I = "Show Full Info",
k = "Stop VimTeX",
K = "Stop All VimTeX",
L = "Compile Selection",
l = "Compile",
m = "Show Imaps",
o = "Show Compiler Output",
q = "Show VimTeX Log",
s = "Toggle Main",
t = "Open Table of Contents",
T = "Toggle Table of Contents",
v = "View Compiled Document",
X = "Reload VimTeX State",
x = "Reload VimTeX",
},
["ts"] = {
name = "VimTeX Toggles & Cycles", -- optional group name
["$"] = "Cycle inline, display & numbered equation",
c = "Toggle star of command",
d = "Cycle (), \\left(\\right) [,...]",
D = "Reverse Cycle (), \\left(\\right) [, ...]",
e = "Toggle star of environment",
f = "Toggle a/b vs \\frac{a}{b}",
},
["[/"] = "Previous start of a LaTeX comment",
["[*"] = "Previous end of a LaTeX comment",
["[["] = "Previous beginning of a section",
["[]"] = "Previous end of a section",
["[m"] = "Previous \\begin",
["[M"] = "Previous \\end",
["[n"] = "Previous start of a math zone",
["[N"] = "Previous end of a math zone",
["[r"] = "Previous \\begin{frame}",
["[R"] = "Previous \\end{frame}",
["]/"] = "Next start of a LaTeX comment %",
["]*"] = "Next end of a LaTeX comment %",
["]["] = "Next beginning of a section",
["]]"] = "Next end of a section",
["]m"] = "Next \\begin",
["]M"] = "Next \\end",
["]n"] = "Next start of a math zone",
["]N"] = "Next end of a math zone",
["]r"] = "Next \\begin{frame}",
["]R"] = "Next \\end{frame}",
["cs"] = {
c = "Change surrounding command",
e = "Change surrounding environment",
["$"] = "Change surrounding math zone",
d = "Change surrounding delimiter",
},
["ds"] = {
c = "Delete surrounding command",
e = "Delete surrounding environment",
["$"] = "Delete surrounding math zone",
d = "Delete surrounding delimiter",
},
}
wk.register(mappings, opts)
-- VimTeX Text Objects without variants with targets.vim
opts = {
mode = "o", -- Operator pending mode
buffer = vim.api.nvim_get_current_buf(),
}
local objects = {
["ic"] = [[LaTeX Command]],
["ac"] = [[LaTeX Command]],
["id"] = [[LaTeX Math Delimiter]],
["ad"] = [[LaTeX Math Delimiter]],
["ie"] = [[LaTeX Environment]],
["ae"] = [[LaTeX Environment]],
["i$"] = [[LaTeX Math Zone]],
["a$"] = [[LaTeX Math Zone]],
["iP"] = [[LaTeX Section, Paragraph, ...]],
["aP"] = [[LaTeX Section, Paragraph, ...]],
["im"] = [[LaTeX Item]],
["am"] = [[LaTeX Item]],
}
wk.register(objects, opts) which will turn my screenshots from before into It is not yet complete, but should you get started. (And writing yourself will help you to explore it.) Autocommand idea from folke/which-key.nvim#165 (comment) (Side note: I have installed https://github.com/afreakk/unimpaired-which-key.nvim so that the menus for |
Hello, firstly thanks for the great plugin, latex with this plugin made me enjoy writing documents. There are a lot of vimtex features that I discover even now, for example, only after two years of usage I've found extremely useful table of contents. Maybe half a year ago I discovered context menu for some bibliography management. The point here is that vimtex offers a huge number of options, but not all of them are used(by some users in some cases).
And since I had some experience with lsp servers that provide context menu options too (for example rust-analyzer), I thought, maybe it is possible to expand vimtex's context menu to other things?
Let me provide explanation and some ideas:
There are a lot of ways to change environments, like changing them, toggling starred option, deleting them etc. While these actions are made in the vim's way so you can memorize them, like
cse = change surrounding environment
, in my experience it is not enough. I don't really remember every mapping except often used, but it doesn't mean, that I don't need some rarely used.The same goes with math environment: options like
tsd, ts$, tsf
(by the way I've found the last one only just now)So, my idea here is to use context menu based on current cursor position. In my opinion, it could make vimtex more friendly for new users and also expose some rarely used features for those who tend to forget them or just don't know about them. I mean if the cursor placed on or inside environment, invoking context menu will bring options based on that context, like
cse, dse, tse
, maybe visual options too.I can imagine that it is possible to extend it even more, for example, to show document compiling options like starting the compiler, cleaning after it is stopped etc. Or it would be nice to have a preview on labels like on bib entries, so instead of gd it'd be possible to remind what it was without jumping twice.
It can be generalized like this: use the context menu to show all available options based on the current cursor position and maybe some additional features for certain contexts.
I don't know if it is hard to implement, or it does not follow your vision on vimtex, so if you don't like I'll close the issue. Or if you find this idea interesting, maybe others can better than me propose some good ideas on context menu usage, maybe some of my suggestions are bad or not good enough, but the idea itself has some potential.
The text was updated successfully, but these errors were encountered: