diff --git a/.config/nvim/.gitignore b/.config/nvim/.gitignore new file mode 100644 index 0000000..8cb205e --- /dev/null +++ b/.config/nvim/.gitignore @@ -0,0 +1 @@ +plugin diff --git a/.config/nvim/lua/mappings.lua b/.config/nvim/lua/mappings.lua index 0c4ed3d..b42c2db 100644 --- a/.config/nvim/lua/mappings.lua +++ b/.config/nvim/lua/mappings.lua @@ -52,3 +52,5 @@ map('n', 'bw', 'BufferOrderByWindowNumber', opts) --NVimTree map('n', '', 'NvimTreeToggle',opts) + + diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua new file mode 100644 index 0000000..749917a --- /dev/null +++ b/.config/nvim/lua/plugins/cmp.lua @@ -0,0 +1,134 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +--   פּ ﯟ   some other good icons +local kind_icons = { + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} +-- find more here: https://www.nerdfonts.com/cheat-sheet + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [""] = cmp.mapping { + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }, + -- Accept currently selected item. If none selected, `select` first item. + -- Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm { select = true }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "(LSP)", + luasnip = "(Snippet)", + buffer = "(Text)", + path = "(Path)", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered({ + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None" + }) + + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +} + diff --git a/.config/nvim/lua/plugins/lspconfig.lua b/.config/nvim/lua/plugins/lspconfig.lua index eb5f613..e61ec35 100644 --- a/.config/nvim/lua/plugins/lspconfig.lua +++ b/.config/nvim/lua/plugins/lspconfig.lua @@ -1,16 +1,49 @@ -local present, lspconfig = pcall(require,"lspconfig") -on_attach = function(client, bufnr) - client.server_capabilities.documentFormattingProvider = false - client.server_capabilities.documentRangeFormattingProvider = false +local opts = { noremap=true, silent=true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) - utils.load_mappings("lspconfig", { buffer = bufnr }) +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) end -capabilities = vim.lsp.protocol.make_client_capabilities() - - -lspconfig.hls.setup{} - -lspconfig.rust_analyzer.setup{} +require('lspconfig')['hls'].setup{ + on_attach = on_attach, + flags = lsp_flags, +} +require('lspconfig')['rust_analyzer'].setup{ + on_attach = on_attach, + flags = lsp_flags, + -- Server-specific settings... + settings = { + ["rust-analyzer"] = {} + } +} +require('lspconfig')['texlab'].setup{ + on_attach = on_attach, + flags = lsp_flags, +} diff --git a/.config/nvim/lua/plugins/nvim-coc.lua b/.config/nvim/lua/plugins/nvim-coc.lua deleted file mode 100644 index f6fa211..0000000 --- a/.config/nvim/lua/plugins/nvim-coc.lua +++ /dev/null @@ -1,181 +0,0 @@ --- Some servers have issues with backup files, see #649. -vim.opt.backup = false -vim.opt.writebackup = false - --- Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable --- delays and poor user experience. -vim.opt.updatetime = 300 - --- Always show the signcolumn, otherwise it would shift the text each time --- diagnostics appear/become resolved. -vim.opt.signcolumn = "yes" - -local keyset = vim.keymap.set --- Auto complete -function _G.check_back_space() - local col = vim.fn.col('.') - 1 - return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil -end - --- Use tab for trigger completion with characters ahead and navigate. --- NOTE: There's always complete item selected by default, you may want to enable --- no select by `"suggest.noselect": true` in your configuration file. --- NOTE: Use command ':verbose imap ' to make sure tab is not mapped by --- other plugin before putting this into your config. -local opts = {silent = true, noremap = true, expr = true, replace_keycodes = false} -keyset("i", "", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()', opts) -keyset("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts) - --- Make to accept selected completion item or notify coc.nvim to format --- u breaks current undo, please make your own choice. -keyset("i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], opts) - --- Use to trigger snippets -keyset("i", "", "(coc-snippets-expand-jump)") --- Use to trigger completion. -keyset("i", "", "coc#refresh()", {silent = true, expr = true}) - --- Use `[g` and `]g` to navigate diagnostics --- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. -keyset("n", "[g", "(coc-diagnostic-prev)", {silent = true}) -keyset("n", "]g", "(coc-diagnostic-next)", {silent = true}) - --- GoTo code navigation. -keyset("n", "gd", "(coc-definition)", {silent = true}) -keyset("n", "gy", "(coc-type-definition)", {silent = true}) -keyset("n", "gi", "(coc-implementation)", {silent = true}) -keyset("n", "gr", "(coc-references)", {silent = true}) - - --- Use K to show documentation in preview window. -function _G.show_docs() - local cw = vim.fn.expand('') - if vim.fn.index({'vim', 'help'}, vim.bo.filetype) >= 0 then - vim.api.nvim_command('h ' .. cw) - elseif vim.api.nvim_eval('coc#rpc#ready()') then - vim.fn.CocActionAsync('doHover') - else - vim.api.nvim_command('!' .. vim.o.keywordprg .. ' ' .. cw) - end -end -keyset("n", "K", 'lua _G.show_docs()', {silent = true}) - - --- Highlight the symbol and its references when holding the cursor. -vim.api.nvim_create_augroup("CocGroup", {}) -vim.api.nvim_create_autocmd("CursorHold", { - group = "CocGroup", - command = "silent call CocActionAsync('highlight')", - desc = "Highlight symbol under cursor on CursorHold" -}) - - --- Symbol renaming. -keyset("n", "rn", "(coc-rename)", {silent = true}) - - --- Formatting selected code. -keyset("x", "f", "(coc-format-selected)", {silent = true}) -keyset("n", "f", "(coc-format-selected)", {silent = true}) - - --- Setup formatexpr specified filetype(s). -vim.api.nvim_create_autocmd("FileType", { - group = "CocGroup", - pattern = "typescript,json", - command = "setl formatexpr=CocAction('formatSelected')", - desc = "Setup formatexpr specified filetype(s)." -}) - --- Update signature help on jump placeholder. -vim.api.nvim_create_autocmd("User", { - group = "CocGroup", - pattern = "CocJumpPlaceholder", - command = "call CocActionAsync('showSignatureHelp')", - desc = "Update signature help on jump placeholder" -}) - - --- Applying codeAction to the selected region. --- Example: `aap` for current paragraph -local opts = {silent = true, nowait = true} -keyset("x", "a", "(coc-codeaction-selected)", opts) -keyset("n", "a", "(coc-codeaction-selected)", opts) - --- Remap keys for applying codeAction to the current buffer. -keyset("n", "ac", "(coc-codeaction)", opts) - - --- Apply AutoFix to problem on the current line. -keyset("n", "qf", "(coc-fix-current)", opts) - - --- Run the Code Lens action on the current line. -keyset("n", "cl", "(coc-codelens-action)", opts) - - --- Map function and class text objects --- NOTE: Requires 'textDocument.documentSymbol' support from the language server. -keyset("x", "if", "(coc-funcobj-i)", opts) -keyset("o", "if", "(coc-funcobj-i)", opts) -keyset("x", "af", "(coc-funcobj-a)", opts) -keyset("o", "af", "(coc-funcobj-a)", opts) -keyset("x", "ic", "(coc-classobj-i)", opts) -keyset("o", "ic", "(coc-classobj-i)", opts) -keyset("x", "ac", "(coc-classobj-a)", opts) -keyset("o", "ac", "(coc-classobj-a)", opts) - - --- Remap and for scroll float windows/popups. ----@diagnostic disable-next-line: redefined-local -local opts = {silent = true, nowait = true, expr = true} -keyset("n", "", 'coc#float#has_scroll() ? coc#float#scroll(1) : ""', opts) -keyset("n", "", 'coc#float#has_scroll() ? coc#float#scroll(0) : ""', opts) -keyset("i", "", - 'coc#float#has_scroll() ? "=coc#float#scroll(1)" : ""', opts) -keyset("i", "", - 'coc#float#has_scroll() ? "=coc#float#scroll(0)" : ""', opts) -keyset("v", "", 'coc#float#has_scroll() ? coc#float#scroll(1) : ""', opts) -keyset("v", "", 'coc#float#has_scroll() ? coc#float#scroll(0) : ""', opts) - - --- Use CTRL-S for selections ranges. --- Requires 'textDocument/selectionRange' support of language server. -keyset("n", "", "(coc-range-select)", {silent = true}) -keyset("x", "", "(coc-range-select)", {silent = true}) - - --- Add `:Format` command to format current buffer. -vim.api.nvim_create_user_command("Format", "call CocAction('format')", {}) - --- " Add `:Fold` command to fold current buffer. -vim.api.nvim_create_user_command("Fold", "call CocAction('fold', )", {nargs = '?'}) - --- Add `:OR` command for organize imports of the current buffer. -vim.api.nvim_create_user_command("OR", "call CocActionAsync('runCommand', 'editor.action.organizeImport')", {}) - --- Add (Neo)Vim's native statusline support. --- NOTE: Please see `:h coc-status` for integrations with external plugins that --- provide custom statusline: lightline.vim, vim-airline. -vim.opt.statusline:prepend("%{coc#status()}%{get(b:,'coc_current_function','')}") - --- Mappings for CoCList --- code actions and coc stuff ----@diagnostic disable-next-line: redefined-local -local opts = {silent = true, nowait = true} --- Show all diagnostics. -keyset("n", "a", ":CocList diagnostics", opts) --- Manage extensions. -keyset("n", "e", ":CocList extensions", opts) --- Show commands. -keyset("n", "c", ":CocList commands", opts) --- Find symbol of current document. -keyset("n", "o", ":CocList outline", opts) --- Search workspace symbols. -keyset("n", "s", ":CocList -I symbols", opts) --- Do default action for next item. -keyset("n", "j", ":CocNext", opts) --- Do default action for previous item. -keyset("n", "k", ":CocPrev", opts) --- Resume latest coc list. -keyset("n", "p", ":CocListResume", opts) diff --git a/.config/nvim/lua/plugins/packer.lua b/.config/nvim/lua/plugins/packer.lua index 815c86f..097b11b 100644 --- a/.config/nvim/lua/plugins/packer.lua +++ b/.config/nvim/lua/plugins/packer.lua @@ -29,31 +29,49 @@ local plugins = packer.startup({function(use) end } + use { "hrsh7th/nvim-cmp", + requires = { + 'hrsh7th/cmp-nvim-lsp', -- lsp + 'hrsh7th/cmp-buffer', --buffer completions + 'hrsh7th/cmp-path', --path completions + 'hrsh7th/cmp-cmdline' --cmdline completions + }, + config = function() + require "plugins.cmp" + end + } + use {'stevearc/dressing.nvim'} -- Rename variable pop up + + + use { "L3MON4D3/LuaSnip", + requires = { + "rafamadriz/friendly-snippets", + "saadparwaiz1/cmp_luasnip" + }, + } use { "williamboman/mason.nvim", config = function () require "plugins.mason" end } + use {'nvim-tree/nvim-tree.lua', + requires = { + 'nvim-tree/nvim-web-devicons', -- optional, for file icons + }, + require("nvim-tree").setup() + } use { "feline-nvim/feline.nvim" } use {"joshdick/onedark.vim" } - use {"nvim-tree/nvim-tree.lua", - requires = { - 'nvim-tree/nvim-web-devicons', - }, - config = function() - require("nvim-tree").setup() - end - } - use {"nvim-treesitter/nvim-treesitter", config = function() require "plugins.treesitter" end } + --Tabs use {'romgrk/barbar.nvim', requires = 'kyazdani42/nvim-web-devicons', config = function () @@ -61,24 +79,39 @@ local plugins = packer.startup({function(use) end } - use {"windwp/nvim-autopairs", - config = function() require("nvim-autopairs").setup {} end - } - - use {"neoclide/coc.nvim", - config = function() require("plugins.nvim-coc") end - } - + --fuzzy file finding use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', -- or , branch = '0.1.x', requires = { {'nvim-lua/plenary.nvim'} }, config = function() require('plugins.telescope') end } - + --live share like functionality use {"jbyuki/instant.nvim"} - end, + use {"narutoxy/silicon.lua", + requires = { "nvim-lua/plenary.nvim" }, + config = function() + require('silicon').setup({ + font = "FiraCode Nerd Font Mono", + output = "~/Pictures/SILICON_${year}-${month}-${date}.png", + debug = true + }) + require "plugins.silicon" + end + } + + use {"tpope/vim-surround"} + + use {"startup-nvim/startup.nvim", + requires = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"}, + config = function() + require("startup").setup { theme = "dashboard" } + end, + } + + end, + config = { auto_clean = true, compile_on_sync = true, diff --git a/.config/nvim/lua/plugins/silicon.lua b/.config/nvim/lua/plugins/silicon.lua new file mode 100644 index 0000000..f0b2e3a --- /dev/null +++ b/.config/nvim/lua/plugins/silicon.lua @@ -0,0 +1,6 @@ +local present, silicon = pcall(require,'silicon') + +-- Generate image of lines in a visual selection +vim.keymap.set('v', 's', function() silicon.visualise_api() end ) +-- Generate image of a whole buffer, with lines in a visual selection highlighted +vim.keymap.set('v', 'bs', function() silicon.visualise_api({to_clip = true, show_buf = true}) end )