all repos — dotfiles @ ce55dc4cbf1f46ab89198931a541808316d232d6

linux dotfiles

nvim: add nvim-cmp and other plugins, change theme
Prithu Goswami pg@prithu.dev
Fri, 09 Sep 2022 10:50:11 +0530
commit

ce55dc4cbf1f46ab89198931a541808316d232d6

parent

ebb3da8f06c16bbbb5a3b120db0cf7cd89f7c0fd

A config/nvim/.gitignore

@@ -0,0 +1,1 @@

+./plugin/packer_compiled.lua
M config/nvim/init.luaconfig/nvim/init.lua

@@ -1,12 +1,41 @@

require 'plugins' require 'options' require 'keymaps' +require 'completion' +vim.cmd('colorscheme darkplus') + --- OR setup with some options require("nvim-tree").setup({ sort_by = "case_sensitive", + filters = { + custom = {"__pycache__"} + }, + renderer = { + indent_markers = { + enable = true + }, + icons = { + git_placement = "after", + glyphs = { + git = { + unstaged = "△", + staged = "✔", + unmerged = "", + renamed = "➜", + untracked = "★", + deleted = "✗", + ignored = "◌", + } + } + } + }, view = { - adaptive_size = true, + mappings = { + list = { + { key = "t", action = "tabnew"}, + { key = "<C-s>", action = "split"} + } + } }, })
A config/nvim/lua/completion.lua

@@ -0,0 +1,128 @@

+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 = { + ["<C-k>"] = cmp.mapping.select_prev_item(), + ["<C-j>"] = cmp.mapping.select_next_item(), + ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + ["<C-e>"] = 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. + ["<CR>"] = cmp.mapping.confirm { select = true }, + ["<Tab>"] = 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", + }), + ["<S-Tab>"] = 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 = ({ + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +}
M config/nvim/lua/keymaps.luaconfig/nvim/lua/keymaps.lua

@@ -2,6 +2,7 @@ local k = vim.api.nvim_set_keymap

local options = { noremap = true, silent = true } vim.g.mapleader = ' ' +k('', '<Space>', '<Nop>', options) k('i', 'jk', '<esc>', options) -- move around visually (when line is wrapped)

@@ -23,14 +24,19 @@ k('n', '<C-n>', ':NvimTreeToggle<CR>', options)

-- folds -k('n', '<leader>j', 'za', options) +k('n', '<leader>l', 'za', options) -- add keymap to unfold and others -- visual -- copy to clipbaord in visual mode k('v', '<C-c>', '"+y', options) +-- move blocks of text visually k('v', 'J', ':m \'>+1<CR>gv=gv', options) k('v', 'K',':m \'<-2<CR>gv=gv', options) +-- stay in visual mode while indenting +k('v', '>', '>gv', options) +k('v', '<', '<gv', options) k('n', '<leader>m', ':nohlsearch<CR>', options) k('n', '<leader>z', ':MaximizerToggle<CR>', options) +k('n', '<leader>r', ':so ~/.config/nvim/init.lua<CR>', options)
M config/nvim/lua/options.luaconfig/nvim/lua/options.lua

@@ -1,20 +1,20 @@

-local o = vim.opt - -o.tabstop = 4 -o.softtabstop = 4 -o.shiftwidth = 4 -o.expandtab = true -o.smartindent = true -o.autoindent = true -o.undofile = true +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true +vim.opt.smartindent = true +vim.opt.autoindent = true +vim.opt.undofile = true --o.colorcolumn = '80' -o.mouse = 'a' -o.wildmenu = true -o.showmatch = true -o.incsearch = true -o.foldenable = true -o.foldmethod = 'indent' -o.foldlevelstart = 10 -o.foldnestmax = 10 -o.number = true -o.backspace = 'indent,eol,start' +vim.opt.mouse = 'a' +vim.opt.wildmenu = true +vim.opt.showmatch = true +vim.opt.incsearch = true +vim.opt.foldenable = true +vim.opt.foldmethod = 'indent' +vim.opt.foldlevelstart = 10 +vim.opt.foldnestmax = 10 +vim.opt.number = true +vim.opt.backspace = 'indent,eol,start' +vim.opt.iskeyword:append "-" -- treat hyphen a part of a word and not a boundary +vim.opt.termguicolors = true
M config/nvim/lua/plugins.luaconfig/nvim/lua/plugins.lua

@@ -3,7 +3,7 @@

vim.cmd([[ augroup packer_user_config autocmd! - autocmd BufWritePost plugins.lua source <afile> | PackerCompile + autocmd BufWritePost plugins.lua source <afile> | PackerSync augroup end ]])

@@ -13,6 +13,24 @@ use 'rstacruz/vim-closer'

use 'tpope/vim-fugitive' use 'tpope/vim-surround' use 'tpope/vim-commentary' + -- themes + use 'ayu-theme/ayu-vim' + use 'folke/tokyonight.nvim' + use 'LunarVim/Colorschemes' + use 'L3MON4D3/LuaSnip' + + -- completion + use 'hrsh7th/nvim-cmp' + use 'hrsh7th/cmp-buffer' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-cmdline' + use 'hrsh7th/cmp-nvim-lsp' + use 'saadparwaiz1/cmp_luasnip' + use 'rafamadriz/friendly-snippets' + + + use {'iamcco/markdown-preview.nvim', run = 'cd app && npm install', cmd = 'MarkdownPreview'} + use { 'kyazdani42/nvim-tree.lua', requires = {
D config/nvim/plugin/packer_compiled.lua

@@ -1,129 +0,0 @@

--- Automatically generated packer.nvim plugin loader code - -if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then - vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') - return -end - -vim.api.nvim_command('packadd packer.nvim') - -local no_errors, error_msg = pcall(function() - -_G._packer = _G._packer or {} -_G._packer.inside_compile = true - -local time -local profile_info -local should_profile = false -if should_profile then - local hrtime = vim.loop.hrtime - profile_info = {} - time = function(chunk, start) - if start then - profile_info[chunk] = hrtime() - else - profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 - end - end -else - time = function(chunk, start) end -end - -local function save_profiles(threshold) - local sorted_times = {} - for chunk_name, time_taken in pairs(profile_info) do - sorted_times[#sorted_times + 1] = {chunk_name, time_taken} - end - table.sort(sorted_times, function(a, b) return a[2] > b[2] end) - local results = {} - for i, elem in ipairs(sorted_times) do - if not threshold or threshold and elem[2] > threshold then - results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' - end - end - if threshold then - table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') - end - - _G._packer.profile_output = results -end - -time([[Luarocks path setup]], true) -local package_path_str = "/home/prithu/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/prithu/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/prithu/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/prithu/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/home/prithu/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" -if not string.find(package.path, package_path_str, 1, true) then - package.path = package.path .. ';' .. package_path_str -end - -if not string.find(package.cpath, install_cpath_pattern, 1, true) then - package.cpath = package.cpath .. ';' .. install_cpath_pattern -end - -time([[Luarocks path setup]], false) -time([[try_loadstring definition]], true) -local function try_loadstring(s, component, name) - local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) - if not success then - vim.schedule(function() - vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) - end) - end - return result -end - -time([[try_loadstring definition]], false) -time([[Defining packer_plugins]], true) -_G.packer_plugins = { - ["nvim-tree.lua"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", - url = "https://github.com/kyazdani42/nvim-tree.lua" - }, - ["nvim-web-devicons"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", - url = "https://github.com/kyazdani42/nvim-web-devicons" - }, - ["packer.nvim"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/packer.nvim", - url = "https://github.com/wbthomason/packer.nvim" - }, - ["vim-closer"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/vim-closer", - url = "https://github.com/rstacruz/vim-closer" - }, - ["vim-commentary"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/vim-commentary", - url = "https://github.com/tpope/vim-commentary" - }, - ["vim-fugitive"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/vim-fugitive", - url = "https://github.com/tpope/vim-fugitive" - }, - ["vim-surround"] = { - loaded = true, - path = "/home/prithu/.local/share/nvim/site/pack/packer/start/vim-surround", - url = "https://github.com/tpope/vim-surround" - } -} - -time([[Defining packer_plugins]], false) - -_G._packer.inside_compile = false -if _G._packer.needs_bufread == true then - vim.cmd("doautocmd BufRead") -end -_G._packer.needs_bufread = false - -if should_profile then save_profiles() end - -end) - -if not no_errors then - error_msg = error_msg:gsub('"', '\\"') - vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') -end