From 39bb6188d82ea2af1af1bc616abc9c180b6893fd Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sun, 17 Sep 2023 21:05:50 +0200 Subject: [PATCH] refactor(nvim): extract formatter.nvim config --- nvimrc | 30 +----------------------------- vim/lua/formatter_config.lua | 27 +++++++++++++++++++++++++++ vim/lua/main.lua | 1 + 3 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 vim/lua/formatter_config.lua diff --git a/nvimrc b/nvimrc index b76a9af..59d16bc 100644 --- a/nvimrc +++ b/nvimrc @@ -334,35 +334,7 @@ packadd! editorconfig-vim " https://github.com/editorconfig/editorconfig-vim.gi packadd! vim-wordmotion " https://github.com/chaoren/vim-wordmotion.git " formatter.nvim -packadd! formatter.nvim " https://github.com/mhartington/formatter.nvim.git - -lua <F', 'silent Format', { noremap=true, silent=true }) -EOF +" See lua/formatter.lua " enable inline vim highlighting: let g:vimsyn_embed= 'lPr' diff --git a/vim/lua/formatter_config.lua b/vim/lua/formatter_config.lua new file mode 100644 index 0000000..e02909b --- /dev/null +++ b/vim/lua/formatter_config.lua @@ -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', 'F', 'silent Format', { noremap=true, silent=true }) diff --git a/vim/lua/main.lua b/vim/lua/main.lua index 882109f..bdf81d7 100644 --- a/vim/lua/main.lua +++ b/vim/lua/main.lua @@ -1,3 +1,4 @@ require "helpers" require "commands" require "test_runner" +require "formatter_config"