this post was submitted on 01 Jul 2023
7 points (100.0% liked)

Neovim

1726 readers
1 users here now

Neovim is a modal text editor forked off of Vim in 2014. Being modal means that you do not simply type text on screen, but the behavior and functionality of the editor changes entirely depending on the mode.

The most common and most used mode, the "normal mode" for Neovim is to essentially turn your keyboard in to hotkeys with which you can navigate and manipulate text. Several modes exist, but two other most common ones are "insert mode" where you type in text directly as if it was a traditional text editor, and "visual mode" where you select text.

Neovim seeks to enable further community participation in its development and to make drastic changes without turning it in to something that is "not Vim". Neovim also seeks to enable embedding the editor within GUI applications.

The Neovim logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 3 years ago
MODERATORS
 

I am rewriting my ancient vim config into Lua with nvim. I am using Mason to grab lsp language servers and for the most part it works great!

I have this in my remaps so I can <leader>f to format the current file (still need to figure out formatting on save too, but I can't for the life of me get Markdown formatting working.

vim.keymap.set("n", "<leader>f", function()
	vim.lsp.buf.format()
end)

I have markdownlint, marksman, prettier, and prettierd all installed wth Mason (though I haven't written any keymaps or configs for them). Any idea how I can format my Markdown? I write in it all day every day so it's gonna help a ton if I can get it working. Secondly any ideas how I can do the same mapping for the formatting on save? Still pretty new to Lua.

you are viewing a single comment's thread
view the rest of the comments
[–] muntoo@lemmy.world 2 points 1 year ago* (last edited 1 year ago)

For autoformatting, try an autocmd:

autocmd BufWritePre * lua vim.lsp.buf.format()

Or alternatively, I use:

autocmd BufWritePre * lua require("utils").format()
-- Formats the current buffer
function utils.format()
  local whitelist = { "python", "rust" }
  if vim.tbl_contains(whitelist, vim.bo.filetype) then
    vim.lsp.buf.format()
  end
end