@@ -99,7 +99,7 @@ vim.g.maplocalleader = ' '
9999vim .opt .number = true
100100-- You can also add relative line numbers, for help with jumping.
101101-- Experiment for yourself to see if you like it!
102- -- vim.opt.relativenumber = true
102+ vim .opt .relativenumber = true
103103
104104-- Enable mouse mode, can be useful for resizing splits for example!
105105vim .opt .mouse = ' a'
@@ -155,6 +155,9 @@ vim.opt.scrolloff = 10
155155vim .opt .hlsearch = true
156156vim .keymap .set (' n' , ' <Esc>' , ' <cmd>nohlsearch<CR>' )
157157
158+ vim .opt .tabstop = 4
159+ vim .opt .shiftwidth = 4
160+
158161-- Diagnostic keymaps
159162vim .keymap .set (' n' , ' [d' , vim .diagnostic .goto_prev , { desc = ' Go to previous [D]iagnostic message' })
160163vim .keymap .set (' n' , ' ]d' , vim .diagnostic .goto_next , { desc = ' Go to next [D]iagnostic message' })
@@ -221,6 +224,7 @@ vim.opt.rtp:prepend(lazypath)
221224require (' lazy' ).setup {
222225 -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
223226 ' tpope/vim-sleuth' , -- Detect tabstop and shiftwidth automatically
227+ ' tpope/vim-fugitive' , -- Git commands in nvim
224228
225229 -- NOTE: Plugins can also be added by using a table,
226230 -- with the first argument being the link and the following
@@ -290,6 +294,9 @@ require('lazy').setup {
290294 -- you do for a plugin at the top level, you can do for a dependency.
291295 --
292296 -- Use the `dependencies` key to specify the dependencies of a particular plugin
297+ {
298+ ' github/copilot.vim' ,
299+ },
293300
294301 { -- Fuzzy Finder (files, lsp, etc)
295302 ' nvim-telescope/telescope.nvim' ,
@@ -543,6 +550,24 @@ require('lazy').setup {
543550 -- But for many setups, the LSP (`tsserver`) will work just fine
544551 -- tsserver = {},
545552 --
553+ intelephense = {},
554+ terraformls = {},
555+ templ = {
556+ filetypes = { ' templ' },
557+ },
558+ tsserver = {},
559+ gopls = {
560+ settings = {
561+ gopls = {
562+ analyses = {
563+ unusedparams = true ,
564+ },
565+ staticcheck = true ,
566+ gofumpt = true ,
567+ },
568+ },
569+ },
570+ -- phan = {},
546571
547572 lua_ls = {
548573 -- cmd = {...},
@@ -607,10 +632,13 @@ require('lazy').setup {
607632 ' stevearc/conform.nvim' ,
608633 opts = {
609634 notify_on_error = false ,
610- format_on_save = {
611- timeout_ms = 500 ,
612- lsp_fallback = true ,
613- },
635+ format_on_save = function (bufnr )
636+ -- Disable with a global or buffer-local variable
637+ if vim .g .disable_autoformat or vim .b [bufnr ].disable_autoformat then
638+ return
639+ end
640+ return { timeout_ms = 500 , lsp_fallback = true }
641+ end ,
614642 formatters_by_ft = {
615643 lua = { ' stylua' },
616644 -- Conform can also run multiple formatters sequentially
@@ -781,7 +809,7 @@ require('lazy').setup {
781809
782810 --- @diagnostic disable-next-line : missing-fields
783811 require (' nvim-treesitter.configs' ).setup {
784- ensure_installed = { ' bash' , ' c' , ' html' , ' lua' , ' markdown' , ' vim' , ' vimdoc' },
812+ ensure_installed = { ' bash' , ' c' , ' go ' , ' html' , ' javascript ' , ' lua' , ' markdown' , ' php ' , ' terraform ' , ' vim' , ' vimdoc' },
785813 -- Autoinstall languages that are not installed
786814 auto_install = true ,
787815 highlight = { enable = true },
@@ -819,3 +847,52 @@ require('lazy').setup {
819847
820848-- The line beneath this is called `modeline`. See `:help modeline`
821849-- vim: ts=2 sts=2 sw=2 et
850+
851+ vim .filetype .add {
852+ extension = {
853+ templ = ' templ' ,
854+ },
855+ }
856+
857+ -- Toggle Auto formatting
858+ vim .api .nvim_create_user_command (' FormatDisable' , function (args )
859+ if args .bang then
860+ -- FormatDisable! will disable formatting just for this buffer
861+ vim .b .disable_autoformat = true
862+ else
863+ vim .g .disable_autoformat = true
864+ end
865+ end , {
866+ desc = ' Disable autoformat-on-save' ,
867+ bang = true ,
868+ })
869+ vim .api .nvim_create_user_command (' FormatEnable' , function ()
870+ vim .b .disable_autoformat = false
871+ vim .g .disable_autoformat = false
872+ end , {
873+ desc = ' Re-enable autoformat-on-save' ,
874+ })
875+
876+ -- Automatically organize imports and format Go code on save
877+ vim .api .nvim_create_autocmd (' BufWritePre' , {
878+ pattern = ' *.go' ,
879+ callback = function ()
880+ local params = vim .lsp .util .make_range_params ()
881+ params .context = { only = { ' source.organizeImports' } }
882+ -- buf_request_sync defaults to a 1000ms timeout. Depending on your
883+ -- machine and codebase, you may want longer. Add an additional
884+ -- argument after params if you find that you have to write the file
885+ -- twice for changes to be saved.
886+ -- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
887+ local result = vim .lsp .buf_request_sync (0 , ' textDocument/codeAction' , params )
888+ for cid , res in pairs (result or {}) do
889+ for _ , r in pairs (res .result or {}) do
890+ if r .edit then
891+ local enc = (vim .lsp .get_client_by_id (cid ) or {}).offset_encoding or ' utf-16'
892+ vim .lsp .util .apply_workspace_edit (r .edit , enc )
893+ end
894+ end
895+ end
896+ vim .lsp .buf .format { async = false }
897+ end ,
898+ })
0 commit comments