diff --git a/init.lua b/init.lua index d448e67..9f847ca 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,5 @@ vim.g.mapleader = " " +vim.g.copilot_no_tab_map = true require('plugins') require('lsp') diff --git a/lua/lspconf.lua b/lua/lspconf.lua index 5efab65..fcad88f 100644 --- a/lua/lspconf.lua +++ b/lua/lspconf.lua @@ -1,4 +1,4 @@ --- local conform = require("conform") +local conform = require("conform") local on_attach = function(client, bufnr) if client.config.flags then @@ -28,13 +28,13 @@ local on_attach = function(client, bufnr) vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "f", function() + vim.keymap.set("n", "F", function() vim.lsp.buf.format({ async = true }) end, opts) - -- vim.keymap.set("n", "f", function() - -- conform.format({ bufnr = bufnr }) - -- end, opts) + vim.keymap.set("n", "f", function() + conform.format({ bufnr = bufnr }) + end, opts) vim.keymap.set("i", "", vim.lsp.completion.get, { desc = "trigger autocompletion" }) end diff --git a/lua/plugin/cmp.lua b/lua/plugin/cmp.lua index 33e73f0..c2cc6db 100644 --- a/lua/plugin/cmp.lua +++ b/lua/plugin/cmp.lua @@ -1,25 +1,25 @@ --- local cmp = require("cmp") +local cmp = require("cmp") --- cmp.setup({ --- snippet = { --- expand = function(args) --- require("luasnip").lsp_expand(args.body) -- For `luasnip` users. --- end, --- }, --- window = { --- completion = cmp.config.window.bordered(), --- documentation = cmp.config.window.bordered(), --- }, --- mapping = cmp.mapping.preset.insert({ --- [""] = cmp.mapping.scroll_docs(-4), --- [""] = cmp.mapping.scroll_docs(4), --- [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. --- }), +cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) -- For `luasnip` users. + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), --- sources = cmp.config.sources({ --- { name = "nvim_lsp" }, --- { name = "luasnip" }, -- For luasnip users. --- }, { --- { name = "buffer" }, --- }), --- }) + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, -- For luasnip users. + }, { + { name = "buffer" }, + }), +}) diff --git a/lua/plugin/code-companion.lua b/lua/plugin/code-companion.lua index 9d18c8b..f3e175e 100644 --- a/lua/plugin/code-companion.lua +++ b/lua/plugin/code-companion.lua @@ -1,10 +1,10 @@ --- require("codecompanion").setup({ --- strategies = { --- chat = { --- adapter = { --- name = "copilot", --- model = "claude-sonnet-4", --- }, --- }, --- }, --- }) +require("codecompanion").setup({ + strategies = { + chat = { + adapter = { + name = "copilot", + model = "claude-sonnet-4", + }, + }, + }, +}) diff --git a/lua/plugin/formatter.lua b/lua/plugin/formatter.lua index da57fe9..cfe2674 100644 --- a/lua/plugin/formatter.lua +++ b/lua/plugin/formatter.lua @@ -1,10 +1,10 @@ --- local formatter = require("conform") +local formatter = require("conform") --- formatter.setup({ --- formatters_by_ft = { --- lua = { "stylua" }, --- -- Use a sub-list to run only the first available formatter --- javascript = { "prettierd", "prettier" }, --- typescript = { "prettier" }, --- }, --- }) +formatter.setup({ + formatters_by_ft = { + lua = { "stylua" }, + -- Use a sub-list to run only the first available formatter + javascript = { "prettierd", "prettier" }, + typescript = { "prettier" }, + }, +}) diff --git a/lua/plugin/harpoon.lua b/lua/plugin/harpoon.lua index 097c6a2..028a44c 100644 --- a/lua/plugin/harpoon.lua +++ b/lua/plugin/harpoon.lua @@ -1,32 +1,32 @@ --- local harpoon = require("harpoon") +local harpoon = require("harpoon") --- harpoon:setup({}) +harpoon:setup({}) --- vim.keymap.set("n", "hh", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) --- vim.keymap.set("n", "h", function() harpoon:list():append() end) +vim.keymap.set("n", "hh", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) +vim.keymap.set("n", "h", function() harpoon:list():append() end) --- vim.keymap.set("n", "1", function() harpoon:list():select(1) end) --- vim.keymap.set("n", "2", function() harpoon:list():select(2) end) --- vim.keymap.set("n", "3", function() harpoon:list():select(3) end) --- vim.keymap.set("n", "4", function() harpoon:list():select(4) end) --- vim.keymap.set("n", "5", function() harpoon:list():select(5) end) --- vim.keymap.set("n", "6", function() harpoon:list():select(6) end) --- vim.keymap.set("n", "7", function() harpoon:list():select(7) end) --- vim.keymap.set("n", "8", function() harpoon:list():select(8) end) --- vim.keymap.set("n", "9", function() harpoon:list():select(9) end) +vim.keymap.set("n", "1", function() harpoon:list():select(1) end) +vim.keymap.set("n", "2", function() harpoon:list():select(2) end) +vim.keymap.set("n", "3", function() harpoon:list():select(3) end) +vim.keymap.set("n", "4", function() harpoon:list():select(4) end) +vim.keymap.set("n", "5", function() harpoon:list():select(5) end) +vim.keymap.set("n", "6", function() harpoon:list():select(6) end) +vim.keymap.set("n", "7", function() harpoon:list():select(7) end) +vim.keymap.set("n", "8", function() harpoon:list():select(8) end) +vim.keymap.set("n", "9", function() harpoon:list():select(9) end) --- vim.keymap.set("n", "d1", function() harpoon:list():removeAt(1) end) --- vim.keymap.set("n", "d2", function() harpoon:list():removeAt(2) end) --- vim.keymap.set("n", "d3", function() harpoon:list():removeAt(3) end) --- vim.keymap.set("n", "d4", function() harpoon:list():removeAt(4) end) --- vim.keymap.set("n", "d5", function() harpoon:list():removeAt(5) end) --- vim.keymap.set("n", "d6", function() harpoon:list():removeAt(6) end) --- vim.keymap.set("n", "d7", function() harpoon:list():removeAt(7) end) --- vim.keymap.set("n", "d8", function() harpoon:list():removeAt(8) end) --- vim.keymap.set("n", "d9", function() harpoon:list():removeAt(9) end) +vim.keymap.set("n", "d1", function() harpoon:list():removeAt(1) end) +vim.keymap.set("n", "d2", function() harpoon:list():removeAt(2) end) +vim.keymap.set("n", "d3", function() harpoon:list():removeAt(3) end) +vim.keymap.set("n", "d4", function() harpoon:list():removeAt(4) end) +vim.keymap.set("n", "d5", function() harpoon:list():removeAt(5) end) +vim.keymap.set("n", "d6", function() harpoon:list():removeAt(6) end) +vim.keymap.set("n", "d7", function() harpoon:list():removeAt(7) end) +vim.keymap.set("n", "d8", function() harpoon:list():removeAt(8) end) +vim.keymap.set("n", "d9", function() harpoon:list():removeAt(9) end) --- -- Toggle previous & next buffers stored within Harpoon list --- vim.keymap.set("n", "", function() harpoon:list():prev() end) --- vim.keymap.set("n", "", function() harpoon:list():next() end) +-- Toggle previous & next buffers stored within Harpoon list +vim.keymap.set("n", "", function() harpoon:list():prev() end) +vim.keymap.set("n", "", function() harpoon:list():next() end) diff --git a/lua/plugin/treesitter.lua b/lua/plugin/treesitter.lua index 678a043..cca4c57 100644 --- a/lua/plugin/treesitter.lua +++ b/lua/plugin/treesitter.lua @@ -1,20 +1,20 @@ --- local configs = require("nvim-treesitter.configs") +local configs = require("nvim-treesitter.configs") --- configs.setup({ --- ensure_installed = { --- "c", --- "lua", --- "vim", --- "vimdoc", --- "query", --- "elixir", --- "heex", --- "javascript", --- "html", --- "css", --- "typescript", --- }, --- sync_install = false, --- highlight = { enable = true }, --- indent = { enable = true }, --- }) +configs.setup({ + ensure_installed = { + "c", + "lua", + "vim", + "vimdoc", + "query", + "elixir", + "heex", + "javascript", + "html", + "css", + "typescript", + }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 594781e..37a6c22 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,68 +1,126 @@ -vim.pack.add({ - { src = "https://github.com/gruvbox-community/gruvbox" }, - { src = "https://github.com/lewis6991/gitsigns.nvim" }, - { src = "https://github.com/tpope/vim-commentary" }, - { src = "https://github.com/stevearc/oil.nvim" }, - { - src = "https://github.com/folke/snacks.nvim", - opts = { - explorer = { enabled = true }, - indent = { enabled = true }, - input = { enabled = true }, - picker = { enabled = true }, - lazygit = { enabled = true }, - }, - }, - { src = "https://github.com/neovim/nvim-lspconfig" }, -- Required - { - src = "https://github.com/williamboman/mason.nvim", - build = function() - pcall(vim.cmd, "MasonUpdate") - end, - }, - { src = "https://github.com/williamboman/mason-lspconfig.nvim" }, -- Optional - -- { - -- src = "https://github.com/ThePrimeagen/harpoon", - -- branch = "harpoon2", - -- }, - -- { - -- src = "https://github.com/iamcco/markdown-preview.nvim", - -- cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, - -- ft = { "markdown" }, - -- build = function() - -- vim.fn["mkdp#util#install"]() - -- end, - -- }, - -- { src = "https://github.com/mhinz/vim-startify" }, - -- { - -- src = "https://github.com/kristijanhusak/vim-dadbod-ui", - -- dependencies = { - -- { "tpope/vim-dadbod", lazy = true }, - -- { "kristijanhusak/vim-dadbod-completion", ft = { "sql", "mysql", "plsql" }, lazy = true }, - -- }, - -- cmd = { - -- "DBUI", - -- "DBUIToggle", - -- "DBUIAddConnection", - -- "DBUIFindBuffer", - -- }, - -- init = function() - -- -- Your DBUI configuration - -- vim.g.db_ui_use_nerd_fonts = 1 - -- end, - -- }, - -- { - -- src = "https://github.com/olimorris/codecompanion.nvim", - -- dependencies = { - -- "nvim-lua/plenary.nvim", - -- "nvim-treesitter/nvim-treesitter", - -- }, - -- }, +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end + +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + { "gruvbox-community/gruvbox" }, + { "lewis6991/gitsigns.nvim" }, + { "tpope/vim-commentary" }, + { "tpope/vim-surround" }, + { "sphamba/smear-cursor.nvim", opts = {}, }, + { + "folke/snacks.nvim", + priority = 1000, + lazy = false, + opts = { + -- bigfile = { enabled = true }, + -- dashboard = { enabled = true }, + -- explorer = { enabled = true }, + -- animate = { enabled = true }, + explorer = { enabled = true }, + indent = { enabled = true }, + input = { enabled = true }, + picker = { enabled = true }, + -- notifier = { enabled = true }, + -- quickfile = { enabled = true }, + -- scope = { enabled = true }, + scroll = { enabled = true }, + statuscolumn = { enabled = true }, + -- words = { enabled = true }, + lazygit = { enabled = true }, + }, + }, + { + "MeanderingProgrammer/render-markdown.nvim", + ft = { "markdown", "codecompanion" }, + }, + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + }, + { "neovim/nvim-lspconfig" }, -- Required + { -- Optional + "williamboman/mason.nvim", + build = function() + pcall(vim.cmd, "MasonUpdate") + end, + }, + { "williamboman/mason-lspconfig.nvim" }, -- Optional + { + "stevearc/conform.nvim", + }, + -- Autocompletion + { "hrsh7th/nvim-cmp" }, -- Required + { "hrsh7th/cmp-nvim-lsp" }, -- Required + { "L3MON4D3/LuaSnip" }, -- Required + -- roslyn + { + "seblyng/roslyn.nvim", + ft = "cs", + opts = { + -- your configuration comes here; leave empty for default settings + }, + }, + { + "stevearc/oil.nvim", + opts = {}, + dependencies = { { "echasnovski/mini.icons", opts = {} } }, + lazy = false, + }, + { + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + ft = { "markdown" }, + build = function() + vim.fn["mkdp#util#install"]() + end, + }, + { "mhinz/vim-startify" }, + { + "kristijanhusak/vim-dadbod-ui", + dependencies = { + { "tpope/vim-dadbod", lazy = true }, + { "kristijanhusak/vim-dadbod-completion", ft = { "sql", "mysql", "plsql" }, lazy = true }, + }, + cmd = { + "DBUI", + "DBUIToggle", + "DBUIAddConnection", + "DBUIFindBuffer", + }, + init = function() + -- Your DBUI configuration + vim.g.db_ui_use_nerd_fonts = 1 + end, + }, + { + "olimorris/codecompanion.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + }, + }, }, opts) local files = vim.split(vim.fn.globpath(vim.fn.stdpath("config") .. "/lua/plugin", "*.lua", true), "\n") for _, f in ipairs(files) do - local name = vim.fn.fnamemodify(f, ":t:r") - require("plugin." .. name) + local name = vim.fn.fnamemodify(f, ":t:r") + require("plugin." .. name) end diff --git a/lua/remap.lua b/lua/remap.lua index fc31313..0aaf481 100644 --- a/lua/remap.lua +++ b/lua/remap.lua @@ -1,5 +1,16 @@ vim.keymap.set("n", "kk", "Oil", { desc = "Open parent directory" }) +-- jk to escape +vim.keymap.set("i", "jk", "") + +-- allow moving line / lines in all modes with M-j/k +vim.keymap.set("n", "", ":m .+1==") +vim.keymap.set("n", "", ":m .-2==") +vim.keymap.set("i", "", ":m .+1==gi") +vim.keymap.set("i", "", ":m .-2==gi") +vim.keymap.set("v", "", ":m '>+1gv=gv") +vim.keymap.set("v", "", ":m '<-2gv=gv") + -- C-x to close buffer vim.keymap.set("n", "", ":bd") @@ -17,3 +28,8 @@ vim.keymap.set("n", "tc", ":tabc") -- copy current file path vim.keymap.set("n", "cp", ":let @+ = expand('%')") + +-- code companion +vim.keymap.set({"n", "v"}, "cc", ":CodeCompanionChat Toggle") +vim.keymap.set("v", "acc", "CodeCompanionChat Add") + diff --git a/lua/set.lua b/lua/set.lua index 496d94c..14fcff0 100644 --- a/lua/set.lua +++ b/lua/set.lua @@ -33,15 +33,53 @@ vim.opt.updatetime = 50 -- use system clipboard vim.opt.clipboard = "unnamedplus" --- vim.g.clipboard = { --- name = "win32yank-wsl", --- copy = { --- ["+"] = "win32yank.exe -i --crlf", --- ["*"] = "win32yank.exe -i --crlf" --- }, --- paste = { --- ["+"] = "win32yank.exe -o --crlf", --- ["*"] = "win32yank.exe -o --crlf" --- }, --- cache_enable = 0, --- } +vim.g.clipboard = { + name = "win32yank-wsl", + copy = { + ["+"] = "win32yank.exe -i --crlf", + ["*"] = "win32yank.exe -i --crlf" + }, + paste = { + ["+"] = "win32yank.exe -o --crlf", + ["*"] = "win32yank.exe -o --crlf" + }, + cache_enable = 0, +} + +local function fzf_open_terminal() + local tmp = vim.fn.tempname() + local cwd = vim.fn.getcwd() + + local rg = [[rg --files --hidden --glob "!.git/**" --glob "!node_modules/**" --glob "!.angular/**"]] + local awk = [[awk -F'/' '{dir = (NF>1 ? substr($0, 1, length($0)-length($NF)-1) : "."); printf("%s [%s]\t%s\n", $NF, dir, $0)}']] + local inner = string.format("cd %s && %s | %s | fzf --height 40%% > %s", + vim.fn.shellescape(cwd), rg, awk, vim.fn.shellescape(tmp)) + + vim.cmd('belowright split') + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_win_set_buf(0, bufnr) + + -- pass argv form to avoid fish parsing issues + vim.fn.termopen({'bash', '-ic', inner}, { + on_exit = function() + local lines = vim.fn.readfile(tmp) + os.remove(tmp) + if #lines == 0 then + vim.schedule(function() + if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, {force=true}) end + end) + return + end + local sel = lines[1]:match("\t(.*)$") or lines[1] + vim.schedule(function() + + if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, {force=true}) end + vim.cmd('edit ' .. vim.fn.fnameescape(sel)) + end) + end, + }) + + vim.cmd('startinsert') +end + +vim.keymap.set('n', 'o', fzf_open_terminal, {noremap=true, silent=true})