refactor(nvim): extract formatter.nvim config

This commit is contained in:
Rob Watson 2023-09-17 21:05:50 +02:00
parent 124691d0d9
commit 39bb6188d8
3 changed files with 29 additions and 29 deletions

30
nvimrc
View File

@ -334,35 +334,7 @@ packadd! editorconfig-vim " https://github.com/editorconfig/editorconfig-vim.gi
packadd! vim-wordmotion " https://github.com/chaoren/vim-wordmotion.git packadd! vim-wordmotion " https://github.com/chaoren/vim-wordmotion.git
" formatter.nvim " formatter.nvim
packadd! formatter.nvim " https://github.com/mhartington/formatter.nvim.git " See lua/formatter.lua
lua <<EOF
local prettier = function()
return {
exe = Get_project_node_modules_path() .. "/.bin/prettier",
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), '--single-quote'},
stdin = true
}
end
require('formatter').setup({
filetype = {
javascript = { prettier },
typescript = { prettier },
typescriptreact = { prettier },
}
})
vim.api.nvim_exec([[
augroup FormatAutogroup
autocmd!
autocmd BufWritePost *.js,*.ts,*.tsx silent FormatWrite
augroup END
]], true)
local bufnr = vim.call("bufnr", "%")
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>F', '<Cmd>silent Format<CR>', { noremap=true, silent=true })
EOF
" enable inline vim highlighting: " enable inline vim highlighting:
let g:vimsyn_embed= 'lPr' let g:vimsyn_embed= 'lPr'

View File

@ -0,0 +1,27 @@
vim.api.nvim_command("packadd formatter.nvim")
local prettier = function()
return {
exe = Get_project_node_modules_path() .. "/.bin/prettier",
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), '--single-quote'},
stdin = true
}
end
require('formatter').setup({
filetype = {
javascript = { prettier },
typescript = { prettier },
typescriptreact = { prettier },
}
})
vim.api.nvim_exec2([[
augroup FormatAutogroup
autocmd!
autocmd BufWritePost *.js,*.ts,*.tsx silent FormatWrite
augroup END
]], { output = true })
local bufnr = vim.fn.bufnr("%")
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>F', '<Cmd>silent Format<CR>', { noremap=true, silent=true })

View File

@ -1,3 +1,4 @@
require "helpers" require "helpers"
require "commands" require "commands"
require "test_runner" require "test_runner"
require "formatter_config"