From 998742b3ba0742f724b938bb3a95170616f862da Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 18 Mar 2024 11:06:32 -0600 Subject: Use the LSP to format code if one is attached to the buffer. --- init.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/init.vim b/init.vim index 381a3a9..a91c4cd 100644 --- a/init.vim +++ b/init.vim @@ -86,7 +86,7 @@ noremap sTERM noremap Y y$ " Format code. This is -noremap ú FormatCode +noremap ú lua run_format_code() " Synstack to help profile syntax highlighting issues. noremap p (SynStack) @@ -317,5 +317,14 @@ lua << EOF }) vim.fn.HighlightColorColumns() + function run_format_code() + local lsps = vim.lsp.buf_get_clients() + if lsps and #lsps > 0 then + vim.lsp.buf.format() + else + vim.cmd("FormatCode") + end + end + EOF -- cgit