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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LSP keymap to format current buffer #814

Closed
wants to merge 2 commits into from

Conversation

GCrispino
Copy link

Having a key map to format the current buffer seems like something that is useful and general enough to have in the kickstart config, so I'm proposing this addition here

Feel free to close if you think that this is not true, though 馃檹馃徏

@feoh
Copy link
Collaborator

feoh commented Mar 31, 2024

What do folks think? I might find this useful.

@GCrispino
Copy link
Author

To add some more context, I'm coming from a setup of vim + coc.nvim, whose default example configuration exposes a "Format" command for doing this, and was trying to find if I could do the same thing after setting kickstart up

init.lua Outdated
@@ -501,6 +501,11 @@ require('lazy').setup({
-- For example, in C this would take you to the header.
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')

-- Formats the current buffer
map('<space>f', function()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be <leader> instead of <space>? It might be the same at the moment, but if someone changes leader it might be confusing as to why formatting "stopped working"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :). Updated 馃憤馃徏

@dam9000
Copy link
Contributor

dam9000 commented Mar 31, 2024

In my view it would be better to use conform which is already included and does lsp fallback and also allows for visual range formatting. In fact that is what I use, I can open a PR with that if there is interest.

@dam9000
Copy link
Contributor

dam9000 commented Mar 31, 2024

Well here is the alternative using conform:
#817

Kickstart is already using conform for formatting and in lua case the stylua formatting differs from LSP formatter. So using this will be more consistent.

@feoh
Copy link
Collaborator

feoh commented Mar 31, 2024

Closing in favor of #817 @GCrispino thanks for the suggestion. I hope you don't mind that we went with @dam9000 's implementation. We introduced conform in the rewrite for exactly this kind of thing :)

@feoh feoh closed this Mar 31, 2024
@GCrispino
Copy link
Author

@feoh no problem. Thanks all for considering this :)

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

Successfully merging this pull request may close these issues.

None yet

4 participants