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 to make Cheatsheet.txt dynamic? #7

Closed
siduck opened this issue Aug 15, 2021 · 16 comments
Closed

How to make Cheatsheet.txt dynamic? #7

siduck opened this issue Aug 15, 2021 · 16 comments

Comments

@siduck
Copy link

siduck commented Aug 15, 2021

hi @sudormrfbin , very cool plugin! Im liking it so far but one thing bugs me . We can write our mappings in cheatsheet.txt , Is there anyway to make this automatic?

Im trying to add this plugin in NvChad and the user config contains this

image

So obviously I cant define any mappings in the cheatsheet.txt since the user would change his mappings here and would have to manually do it again in cheatsheet.txt :c .

Is there a way get all defined mappings ( keys and their cmds) and get it work with cheatsheet.nvim?

@sudormrfbin
Copy link
Owner

Hi @siduck76 :)

Glad to hear that you're trying to add it to NvChad! There was a recent question regarding the same issue, and I'm planning to solve it along with whichkey.nvim integration. I'm thinking of adding something like this...

local cheatsheet = require('cheatsheet.nvim')
cheatsheet.add_cheat("Toggle NvimTree", "<C-N>", "optional-section-name")

... so that it's possible to add them programmatically. Then I think it'll be easy for you to loop over the mappings table and add the cheats. Does that solve your usecase ?

@siduck
Copy link
Author

siduck commented Aug 16, 2021

Hi @siduck76 :)

Glad to hear that you're trying to add it to NvChad! There was a recent question regarding the same issue, and I'm planning to solve it along with whichkey.nvim integration. I'm thinking of adding something like this...

local cheatsheet = require('cheatsheet.nvim')
cheatsheet.add_cheat("Toggle NvimTree", "<C-N>", "optional-section-name")

... so that it's possible to add them programmatically. Then I think it'll be easy for you to loop over the mappings table and add the cheats. Does that solve your usecase ?

yes :D

@siduck
Copy link
Author

siduck commented Aug 16, 2021

@sudormrfbin let me if this gets before 18th please! I need to release v1.0 before 19th of this month :c

@siduck
Copy link
Author

siduck commented Aug 16, 2021

Also would it be possible to add heading for the mappings?

like :

Telescope

old files | fw
buffer | fb

@siduck
Copy link
Author

siduck commented Aug 16, 2021

hi @sudormrfbin , very cool plugin! Im liking it so far but one thing bugs me . We can write our mappings in cheatsheet.txt , Is there anyway to make this automatic?

Im trying to add this plugin in NvChad and the user config contains this

image

So obviously I cant define any mappings in the cheatsheet.txt since the user would change his mappings here and would have to manually do it again in cheatsheet.txt :c .

Is there a way get all defined mappings ( keys and their cmds) and get it work with cheatsheet.nvim?

So I have this mappings table , with multiple tables in it ( for each plugin ) so I wanna loop through and do something like this :

local cheatsheet = require('cheatsheet.nvim')

for index, data in pairs(mappings) do
    print(index .. "\n")  

    for key, val in pairs(data) do
      cheatsheet.add_cheat(key, val)
    end
end

@sudormrfbin
Copy link
Owner

sudormrfbin commented Aug 16, 2021

@sudormrfbin let me if this gets before 18th please! I need to release v1.0 before 19th of this month :c

I'll try to finish it up before 18th then, most probably tomorrow :)

Also would it be possible to add heading for the mappings?

That should be handled by sections:

add_cheat("old files", "<leader>fw", "Telescope")

@siduck
Copy link
Author

siduck commented Aug 16, 2021

```lua
add_cheat("old files", "<leader>fw", "Telescope")

is this a config? I didnt find it in the readme

@sudormrfbin
Copy link
Owner

I meant the section-name in the readme

  • ## starts a metadata comment for specifying sections and tags.

    ## section-name @tag1 @tag2: here section-name is the name of a plugin or a simple name to group some cheats together. tag1 and tag2 are alternative names that you might later remember the section name with. For example the section name can be sandwich and the tag can be @surround.

@siduck
Copy link
Author

siduck commented Aug 16, 2021

I meant the section-name in the readme

  • ## starts a metadata comment for specifying sections and tags.
    ## section-name @tag1 @tag2: here section-name is the name of a plugin or a simple name to group some cheats together. tag1 and tag2 are alternative names that you might later remember the section name with. For example the section name can be sandwich and the tag can be @surround.

I cant write the cheatsheet keybinds manually tho :/ , isnt there any automatic way?

@siduck
Copy link
Author

siduck commented Aug 16, 2021

Since the mappings file in NvChad config will be modified by the user , writing the cheatsheet manually which will get old ( when the user changes his mappings ) is not gonna work.

@sudormrfbin
Copy link
Owner

Oh you misunderstood me, add_cheat("old files", "<leader>fw", "Telescope") is the proposed API I'm working on right now; it should be ready by today. I thought you didn't realize that it's possible to set sections already from the files, so I was suggesting that it'll also be possible programmatically after I push the new API.

@siduck
Copy link
Author

siduck commented Aug 16, 2021

Oh you misunderstood me, add_cheat("old files", "<leader>fw", "Telescope") is the proposed API I'm working on right now; it should be ready by today. I thought you didn't realize that it's possible to set sections already from the files, so I was suggesting that it'll also be possible programmatically after I push the new API.

ohh cool , lemme know when it gets done ❤️

@sudormrfbin
Copy link
Owner

I've added add_cheat in 5be58ae:

local cheatsheet = require('cheatsheet')

for section, data in pairs(mappings) do
    for description, keymap in pairs(data) do
      cheatsheet.add_cheat(description, keymap, section)
    end
end

I suggest adding better worded descriptions for each of the mappings since here we are simply using the key name of the mapping in the table as a substitute (it doesn't play nice with the search because of underscores and camelCase).

@siduck
Copy link
Author

siduck commented Aug 16, 2021

I meant the section-name in the readme

  • ## starts a metadata comment for specifying sections and tags.
    ## section-name @tag1 @tag2: here section-name is the name of a plugin or a simple name to group some cheats together. tag1 and tag2 are alternative names that you might later remember the section name with. For example the section name can be sandwich and the tag can be @surround.

Thanks this works! Btw how do I make the cheatsheet popup ( telescope ) show and list out only cheatsheet made by mappings? I dont wanna list cheatsheet for default vim mappings .

so I'll make two mappings :

  1. for :Cheatsheet ( will show default cheetsheet with default vim mappings and stuff )

  2. for user cheatsheet ( will show those from mappings table only )

@sudormrfbin
Copy link
Owner

You can do it like so (with cf069d8):

cheatsheet = require('cheatsheet')

-- for :Cheatsheet ( will show default cheetsheet with default vim mappings and stuff )
cheatsheet.show_cheatsheet_telescope()

-- for user cheatsheet ( will show those from mappings table only )
cheatsheet.show_cheatsheet_telescope({bundled_cheatsheets=false, bundled_plugin_cheatsheets=false})

@siduck
Copy link
Author

siduck commented Aug 16, 2021

works perfect!

image

@siduck siduck closed this as completed Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants