From 4bb6d86f9a0effd10cadbdd7244b12fc5d7d70db Mon Sep 17 00:00:00 2001 From: Denis Lantsman Date: Fri, 24 May 2024 22:02:18 -0700 Subject: [PATCH] oil, copilot --- alacritty.yml | 20 ++ helix.toml | 26 ++ init.sh | 4 + npm.sh | 9 + nvim/lua/config/completion-and-snippets.lua | 288 ++++++++++++++------ nvim/lua/config/lsp.lua | 2 +- nvim/lua/config/nvimtree.lua | 25 +- nvim/lua/config/oil.lua | 13 + nvim/lua/init-native.lua | 3 +- nvim/lua/plugins.lua | 38 ++- tmux.conf | 3 +- zshrc | 8 +- 12 files changed, 333 insertions(+), 106 deletions(-) create mode 100644 alacritty.yml create mode 100644 helix.toml create mode 100755 npm.sh create mode 100644 nvim/lua/config/oil.lua diff --git a/alacritty.yml b/alacritty.yml new file mode 100644 index 0000000..ea8970e --- /dev/null +++ b/alacritty.yml @@ -0,0 +1,20 @@ +import: + - ~/.alacritty-colorscheme/themes/doom_one.yaml + +# Font configuration (changes require restart) +font: + normal: + family: "JetBrainsMono Nerd Font Mono" + style: Regular + bold: + family: "JetBrainsMono Nerd Font Mono" + style: Bold + italic: + family: "JetBrainsMono Nerd Font Mono" + style: Italic + +env: + TERM: xterm-256color + +window: + option_as_alt: Both diff --git a/helix.toml b/helix.toml new file mode 100644 index 0000000..f9a627f --- /dev/null +++ b/helix.toml @@ -0,0 +1,26 @@ +theme = "ayu_dark" + +[editor] +line-number = "relative" +auto-pairs = false +cursorline = true +mouse = true +auto-format = true +auto-save = true +rulers = [80] +bufferline = "multiple" + +[editor.cursor-shape] +insert = "bar" +normal = "block" +select = "underline" + +[editor.statusline] +left = ["mode", "spinner", "version-control", "file-name"] + +[editor.lsp] +display-messages = true + +[keys.normal] +"]"= {j = "jump_forward"} +"[" = {j = "jump_backward"} diff --git a/init.sh b/init.sh index 2631ca9..42ee3bd 100755 --- a/init.sh +++ b/init.sh @@ -5,6 +5,10 @@ ln -sf ~/src/dotfiles/digrc ~/.digrc ln -sf ~/src/dotfiles/zpreztorc ~/.zpreztorc ln -sf ~/src/dotfiles/nvim/init.lua ~/.config/nvim/init.lua ln -sf ~/src/dotfiles/nvim/lua ~/.config/nvim/lua +mkdir -p ~/.config/alacritty +ln -sf ~/src/dotfiles/alacritty.yml ~/.config/alacritty/ +mkdir -p ~/.config/helix +ln -sf ~/src/dotfiles/helix.yml ~/.config/helix/config.toml ln -sf ~/src/dotfiles/scripts/start-tmux /usr/local/bin/start-tmux ln -sf ~/src/dotfiles/scripts/tmux-session-using-fzf /usr/local/bin/tmux-session-using-fzf diff --git a/npm.sh b/npm.sh new file mode 100755 index 0000000..323ce9f --- /dev/null +++ b/npm.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +npm install -g \ + lua-fmt \ + bash-language-server \ + typescript \ + typescript-language-server \ + yaml-language-server \ + vscode-langservers-extracted diff --git a/nvim/lua/config/completion-and-snippets.lua b/nvim/lua/config/completion-and-snippets.lua index 3fc5f77..889989a 100644 --- a/nvim/lua/config/completion-and-snippets.lua +++ b/nvim/lua/config/completion-and-snippets.lua @@ -1,60 +1,9 @@ --- vim.g.coq_settings = { --- ['auto_start'] = 'shut-up', --- ['display.ghost_text.enabled'] = false --- } - --- nvim-cmp supports additional completion capabilities --- local capabilities = vim.lsp.protocol.make_client_capabilities() --- capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) +-- borrows heavily from +-- https://github.com/MunifTanjim/dotfiles/tree/3d81d787b5a7a745598e623d6cdbd61fb10cef97/private_dot_config/nvim/lua/plugins -- luasnip setup local luasnip = require "luasnip" - --- nvim-cmp setup -local cmp = require "cmp" -vim.o.completeopt = "menu,menuone,noselect" -cmp.setup { - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end - }, - mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true - }, - [""] = function(fallback) - if cmp.visible() then - cmp.select_next_item() - else - fallback() - end - end, - [""] = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end - }, - sources = { - {name = "nvim_lsp"}, - {name = "luasnip"}, - {name = "buffer"}, - {name = "path"} - } -} - ---[[ -local cmp = require "cmp" +local lspkind = require("lspkind") local has_words_before = function() if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then @@ -64,57 +13,220 @@ local has_words_before = function() return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end -local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) -end +-- nvim-cmp setup +local cmp = require "cmp" +vim.o.completeopt = "menu,menuone,noselect" cmp.setup { - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end + -- snippet = { + -- expand = function(args) + -- require("luasnip").lsp_expand(args.body) + -- end + -- }, + completion = { + autocomplete = false, + completeopt = vim.o.completeopt + }, + exprimental = { + ghost_text = true + }, + formatting = { + format = lspkind.cmp_format( + { + with_text = true, + menu = { + buffer = "[buf]", + luasnip = "[snip]", + nvim_lsp = "[lsp]", + nvim_lua = "[vim]", + path = "[path]" + } + } + ) }, mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true - }, + [""] = cmp.mapping(cmp.mapping.complete(), {"i", "c"}), [""] = cmp.mapping( function(fallback) - if vim.fn.pumvisible() == 1 then - feedkey("", "n") - elseif vim.fn["vsnip#available"]() == 1 then - feedkey("(vsnip-expand-or-jump)", "") + if require("copilot.suggestion").is_visible() then + require("copilot.suggestion").accept() + elseif cmp.visible() then + cmp.select_next_item({behavior = cmp.SelectBehavior.Insert}) + elseif luasnip.expandable() then + luasnip.expand() elseif has_words_before() then cmp.complete() else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + fallback() end end, - {"i", "s"} + { + "i", + "s" + } ), [""] = cmp.mapping( function() - if vim.fn.pumvisible() == 1 then - feedkey("", "n") - elseif vim.fn["vsnip#jumpable"](-1) == 1 then - feedkey("(vsnip-jump-prev)", "") + if cmp.visible() then + cmp.select_prev_item({behavior = cmp.SelectBehavior.Insert}) end end, - {"i", "s"} + { + "i", + "s" + } + ), + [""] = cmp.mapping(cmp.mapping.confirm({select = true}), {"i", "c"}), + -- [""] = cmp.mapping.abort(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(3), {"i", "c"}), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-3), {"i", "c"}) + }, + sources = cmp.config.sources( + { + {name = "nvim_lsp", priority = 3}, + {name = "luasnip", priority = 1} + }, + { + {name = "buffer"}, + {name = "path"} + } + ) +} + +cmp.setup.cmdline( + "/", + { + sources = { + {name = "buffer"} + } + } +) + +cmp.setup.cmdline( + ":", + { + sources = cmp.config.sources( + { + {name = "path"} + }, + { + {name = "cmdline"} + } ) + } +) + +cmp.event:on( + "menu_opened", + function() + vim.b.copilot_suggestion_hidden = true + end +) + +cmp.event:on( + "menu_closed", + function() + vim.b.copilot_suggestion_hidden = false + end +) + +require("copilot").setup( + { + panel = { + auto_refresh = false, + keymap = { + accept = "", + jump_prev = "[[", + jump_next = "]]", + refresh = "gr", + open = "" + } + }, + suggestion = { + auto_trigger = false, + keymap = { + accept = false, + accept_word = "", + accept_line = "", + prev = "", + next = "", + dismiss = "" + } + } + } +) + +local suggestion = require("copilot.suggestion") + +---@param mode string|string[] +---@param lhs string +---@param rhs string|fun():nil +---@param desc_or_opts string|table +---@param opts? table +function set_keymap(mode, lhs, rhs, desc_or_opts, opts) + if not opts then + opts = type(desc_or_opts) == "table" and desc_or_opts or {desc = desc_or_opts} + else + opts.desc = desc_or_opts + end + vim.keymap.set(mode, lhs, rhs, opts) +end + +set_keymap( + "i", + "", + function() + if suggestion.is_visible() then + suggestion.accept() + else + suggestion.next() + end + end, + "[copilot] accept or next suggestion" +) + +-- init CopilotChat +require("CopilotChat").setup { + prompts = { + Explain = { + prompt = '/COPILOT_EXPLAIN Write an explanation for the active selection as paragraphs of text.', + mapping = 'ce', + description = 'Explain how the selection works.', + selection = require('CopilotChat.select').visual + }, }, - sources = { - {name = "nvim_lsp"}, - {name = "buffer"}, - {name = "path"}, - {name = "vsnip"} + + mappings = { + reset = { + normal = "", + insert = "" + } + }, + + window = { + width = 0.5, + height = 0.5 } } -]] -- + +-- keybindings for neovim CopilotChat +set_keymap( + "n", + "cc", + function() + require("CopilotChat").toggle() + end, + "toggle CopilotChat" +) + +set_keymap( + "n", + "cq", + function() + local input = vim.fn.input("Quick Chat: ") + if input ~= "" then + require("CopilotChat").ask(input, {selection = require("CopilotChat.select").buffer}) + end + end, + "ask a quick question about the buffer" +) diff --git a/nvim/lua/config/lsp.lua b/nvim/lua/config/lsp.lua index 9a1c39e..8db5dcf 100644 --- a/nvim/lua/config/lsp.lua +++ b/nvim/lua/config/lsp.lua @@ -28,7 +28,7 @@ local on_attach = function(client, bufnr) } end -local servers = {"dockerls", "bashls", "jsonls", "terraformls", "tflint"} +local servers = {"dockerls", "bashls", "jsonls", "terraformls", "tflint", "eslint", "yamlls"} for _, server in ipairs(servers) do lsp[server].setup { on_attach = on_attach, diff --git a/nvim/lua/config/nvimtree.lua b/nvim/lua/config/nvimtree.lua index a9b62f9..77c209b 100644 --- a/nvim/lua/config/nvimtree.lua +++ b/nvim/lua/config/nvimtree.lua @@ -1,3 +1,24 @@ -require("nvim-tree").setup() +-- from https://github.com/nvim-tree/nvim-tree.lua#custom-mappings +local function my_on_attach(bufnr) + local api = require "nvim-tree.api" -vim.api.nvim_set_keymap("n", "-", ":NvimTreeFindFile", {noremap = true}) + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + -- default mappings + api.config.mappings.default_on_attach(bufnr) + + -- custom mappings + vim.keymap.set("n", "+", ":NvimTreeResize +20", opts('Resize +')) + vim.keymap.set("n", "-", ":NvimTreeResize -20", opts('Resize -')) +end + +vim.api.nvim_set_keymap("n", "-", ":NvimTreeFindFileToggle", {noremap = true}) + +require("nvim-tree").setup({ + view = { + width = 50, + }, + on_attach = my_on_attach, +}) diff --git a/nvim/lua/config/oil.lua b/nvim/lua/config/oil.lua new file mode 100644 index 0000000..e8890aa --- /dev/null +++ b/nvim/lua/config/oil.lua @@ -0,0 +1,13 @@ +-- from https://github.com/stevearc/oil.nvim?tab=readme-ov-file#quick-start +require("oil").setup({ + default_file_explorer = true, + columns = { "icon", }, + keymaps = { + [""] = false + }, + view_options = { + show_hidden = true + } +}) + +vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) diff --git a/nvim/lua/init-native.lua b/nvim/lua/init-native.lua index 07a409a..6ccc13f 100644 --- a/nvim/lua/init-native.lua +++ b/nvim/lua/init-native.lua @@ -61,7 +61,8 @@ require "config/harpoon" -- require "config/lua-dev" -- require "config/telescope" require "config/terraform" -require "config/nvimtree" +-- require "config/nvimtree" +require "config/oil" -- fzf -- vim.cmd "set rtp+=/opt/homebrew/opt/fzf" diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 145b2a0..0ae1f5f 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -34,7 +34,10 @@ require("packer").startup( use { "ibhagwan/fzf-lua", -- optional for icon support - requires = {"nvim-tree/nvim-web-devicons"} + requires = {"nvim-tree/nvim-web-devicons"}, + config = function() + require "fzf-lua".setup({"default"}) + end } use "ThePrimeagen/harpoon" @@ -42,8 +45,12 @@ require("packer").startup( use "mhinz/vim-grepper" -- navigation + -- use { + -- "nvim-tree/nvim-tree.lua", + -- requires = {"nvim-tree/nvim-web-devicons"} + -- } use { - "nvim-tree/nvim-tree.lua", + "stevearc/oil.nvim", requires = {"nvim-tree/nvim-web-devicons"} } @@ -82,7 +89,7 @@ require("packer").startup( "pwntester/octo.nvim", requires = { "nvim-lua/plenary.nvim", - 'nvim-telescope/telescope.nvim', + "nvim-telescope/telescope.nvim", "nvim-tree/nvim-web-devicons" }, config = function() @@ -100,7 +107,13 @@ require("packer").startup( use "tpope/vim-rhubarb" -- vim enhancements (motion, repeatability) - use "tpope/vim-commentary" + -- use "tpope/vim-commentary" + use { + "numToStr/Comment.nvim", + config = function() + require("Comment").setup() + end + } -- use "tpope/vim-unimpaired" use "tpope/vim-abolish" @@ -111,8 +124,8 @@ require("packer").startup( -- Neovim motions on speed! use { - "phaazon/hop.nvim", - branch = "v2", -- optional but strongly recommended + "smoka7/hop.nvim", + tag = "*", -- optional but strongly recommended config = function() -- you can configure Hop the way you like here; see :h hop-config require "hop".setup {keys = "etovxqpdygfblzhckisuran"} @@ -152,6 +165,7 @@ require("packer").startup( use "mhartington/formatter.nvim" -- Neovim Completion + use "onsails/lspkind.nvim" use { "hrsh7th/nvim-cmp", requires = { @@ -167,6 +181,18 @@ require("packer").startup( } } + use { + "zbirenbaum/copilot.lua", + requires = { + "nvim-lua/plenary.nvim" + } + } + + use { + "CopilotC-Nvim/CopilotChat.nvim", + branch = "canary" + } + use "mfussenegger/nvim-jdtls" -- use { diff --git a/tmux.conf b/tmux.conf index 85c442b..46a4305 100644 --- a/tmux.conf +++ b/tmux.conf @@ -1,4 +1,5 @@ -set -g default-terminal "screen-256color" +set -g default-terminal 'xterm-256color' + set-window-option -g mode-keys vi set -sg escape-time 0 diff --git a/zshrc b/zshrc index ca6a862..a2a89d8 100644 --- a/zshrc +++ b/zshrc @@ -59,13 +59,7 @@ fi # Created by `pipx` on 2022-08-09 17:54:32 export PATH="$PATH:/Users/dlants/.local/bin" export PATH="/usr/local/opt/postgresql@12/bin:$PATH" - -pyenv_setup() { - export PATH="$(pyenv root)/shims:$(pyenv root)/bin:$PATH" - eval "$(pyenv init --path)" - eval "$(pyenv init -)" - eval "$(pyenv virtualenv-init -)" -} +export PATH="$(pyenv root)/shims:$PATH" # installing this through prezto does not work w/ alacritty! # to make this line work, brew install zsh-syntax-highlighting