Make prettier format on save
This commit is contained in:
parent
117569e09a
commit
fc86df21d6
2 changed files with 27 additions and 6 deletions
|
@ -10,13 +10,28 @@ vim.filetype.add({
|
|||
["dot-zshenv"] = "zsh",
|
||||
["dot-zshrc"] = "zsh"
|
||||
},
|
||||
|
||||
pattern = {
|
||||
[".*/git/config"] = "gitconfig"
|
||||
[".*/git/config"] = "gitconfig"
|
||||
}
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('Filetype', {
|
||||
group = vim.api.nvim_create_augroup('setIndent', { clear = true }),
|
||||
pattern = { "lua", "html", "css", "javascript", "javascriptreact", "typescript", "typescriptreact" },
|
||||
command = 'setlocal tabstop=2 softtabstop=2 shiftwidth=2'
|
||||
vim.api.nvim_create_autocmd("Filetype", {
|
||||
group = vim.api.nvim_create_augroup("setIndent", {}),
|
||||
pattern = { "lua" },
|
||||
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
|
||||
})
|
||||
|
|
|
@ -39,7 +39,13 @@ window_map("j")
|
|||
window_map("k")
|
||||
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 --
|
||||
|
|
Loading…
Reference in a new issue