1
Fork 0

Make prettier format on save

This commit is contained in:
Hadeed 2024-04-27 03:04:56 +05:00
parent 117569e09a
commit fc86df21d6
2 changed files with 27 additions and 6 deletions

View file

@ -10,13 +10,28 @@ vim.filetype.add({
["dot-zshenv"] = "zsh", ["dot-zshenv"] = "zsh",
["dot-zshrc"] = "zsh" ["dot-zshrc"] = "zsh"
}, },
pattern = { pattern = {
[".*/git/config"] = "gitconfig" [".*/git/config"] = "gitconfig"
} }
}) })
vim.api.nvim_create_autocmd('Filetype', { vim.api.nvim_create_autocmd("Filetype", {
group = vim.api.nvim_create_augroup('setIndent', { clear = true }), group = vim.api.nvim_create_augroup("setIndent", {}),
pattern = { "lua", "html", "css", "javascript", "javascriptreact", "typescript", "typescriptreact" }, pattern = { "lua" },
command = 'setlocal tabstop=2 softtabstop=2 shiftwidth=2' command = "setlocal tabstop=2 softtabstop=2 shiftwidth=2"
})
vim.api.nvim_create_autocmd("Filetype", {
group = vim.api.nvim_create_augroup("webDev", {}),
pattern = { "html", "css", "javascript", "javascriptreact" },
callback = function()
vim.cmd [[setlocal tabstop=2 softtabstop=2 shiftwidth=2]]
vim.bo.formatprg = "npx prettier --stdin-filepath %"
vim.api.nvim_create_autocmd("BufWritePre", {
command = "Format",
buffer = 0
})
end
}) })

View file

@ -39,7 +39,13 @@ window_map("j")
window_map("k") window_map("k")
window_map("l") window_map("l")
vim.api.nvim_create_user_command("Format", "normal mzgg=G'zzz", {}) vim.api.nvim_create_user_command("Format", function()
if vim.bo.formatprg ~= "" then
vim.cmd [[normal mzgggqG'zzz]]
else
vim.cmd [[normal mzgg=G'zzz]]
end
end, {})
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Plugin Maps -- -- Plugin Maps --