Changed a few things with CMP

This commit is contained in:
Afonso Franco 2023-01-01 16:30:31 +00:00
parent cc96473d89
commit 793f053367
Signed by: afonso
GPG key ID: C459E0BB3DCEE899
4 changed files with 151 additions and 145 deletions

View file

@ -7,6 +7,9 @@ vim.wo.relativenumber= true
vim.opt.hlsearch = false vim.opt.hlsearch = false
vim.opt.incsearch = true vim.opt.incsearch = true
vim.opt.smartindent = true vim.opt.smartindent = true
--Move lines
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
--Remove Wrap --Remove Wrap
vim.opt.wrap = false vim.opt.wrap = false
--Not let cursor go bellow 10 chars. --Not let cursor go bellow 10 chars.
@ -16,6 +19,9 @@ vim.opt.tabstop = 4
vim.opt.softtabstop = 4 vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4 vim.opt.shiftwidth = 4
vim.opt.expandtab = true vim.opt.expandtab = true
--quickfix keybinds
vim.keymap.set("n", "<C-k>", "<cmd>cnext<CR>zz")
vim.keymap.set("n", "<C-j>", "<cmd>cprev<CR>zz")
--Undo dir --Undo dir
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
vim.opt.undofile = true vim.opt.undofile = true

View file

@ -1,140 +1,145 @@
local cmp_status_ok, cmp = pcall(require, "cmp") local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then if not cmp_status_ok then
return return
end end
local snip_status_ok, luasnip = pcall(require, "luasnip") local snip_status_ok, luasnip = pcall(require, "luasnip")
if not snip_status_ok then if not snip_status_ok then
return return
end end
require("luasnip/loaders/from_vscode").lazy_load() require("luasnip/loaders/from_vscode").lazy_load()
local check_backspace = function() local check_backspace = function()
local col = vim.fn.col "." - 1 local col = vim.fn.col "." - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
end end
--   פּ ﯟ   some other good icons --   פּ ﯟ   some other good icons
local kind_icons = { local kind_icons = {
Text = "", Text = "",
Method = "m", Method = "m",
Function = "", Function = "",
Constructor = "", Constructor = "",
Field = "", Field = "",
Variable = "", Variable = "",
Class = "", Class = "",
Interface = "", Interface = "",
Module = "", Module = "",
Property = "", Property = "",
Unit = "", Unit = "",
Value = "", Value = "",
Enum = "", Enum = "",
Keyword = "", Keyword = "",
Snippet = "", Snippet = "",
Color = "", Color = "",
File = "", File = "",
Reference = "", Reference = "",
Folder = "", Folder = "",
EnumMember = "", EnumMember = "",
Constant = "", Constant = "",
Struct = "", Struct = "",
Event = "", Event = "",
Operator = "", Operator = "",
TypeParameter = "", TypeParameter = "",
} }
-- find more here: https://www.nerdfonts.com/cheat-sheet -- find more here: https://www.nerdfonts.com/cheat-sheet
cmp.setup { cmp.setup {
snippet = { snippet = {
expand = function(args) expand = function(args)
luasnip.lsp_expand(args.body) -- For `luasnip` users. luasnip.lsp_expand(args.body) -- For `luasnip` users.
end, end,
}, },
mapping = { mapping = {
["<C-k>"] = cmp.mapping.select_prev_item(), ["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(), ["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = 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-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping. ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
["<C-e>"] = cmp.mapping { ["<C-e>"] = cmp.mapping {
i = cmp.mapping.abort(), i = cmp.mapping.abort(),
c = cmp.mapping.close(), c = cmp.mapping.close(),
}, },
-- Accept currently selected item. If none selected, `select` first item. -- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items. -- Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm { select = true }, ["<CR>"] = cmp.mapping.confirm { select = true },
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expandable() then elseif luasnip.expandable() then
luasnip.expand() luasnip.expand()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
elseif check_backspace() then elseif check_backspace() then
fallback() fallback()
else else
fallback() fallback()
end end
end, { end, {
"i", "i",
"s", "s",
}), }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
else else
fallback() fallback()
end end
end, { end, {
"i", "i",
"s", "s",
}), }),
}, },
formatting = { formatting = {
fields = { "kind", "abbr", "menu" }, fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item) format = function(entry, vim_item)
-- Kind icons -- Kind icons
vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) 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.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 = ({ vim_item.menu = ({
nvim_lsp = "(LSP)", nvim_lsp = "(LSP)",
luasnip = "(Snippet)", luasnip = "(Snippet)",
buffer = "(Text)", buffer = "(Text)",
path = "(Path)", path = "(Path)",
})[entry.source.name] })[entry.source.name]
return vim_item return vim_item
end, end,
}, },
sorting = { sorting = {
comparators = { comparators = {
cmp.config.compare.exact, cmp.config.compare.exact,
cmp.config.compare.offset, cmp.config.compare.offset,
cmp.config.compare.recently_used, cmp.config.compare.recently_used,
} }
}, },
sources = { sources = cmp.config.sources(
{ name = "nvim_lsp" }, {
{ name = "luasnip" }, { name = "nvim_lsp" },
{ name = "buffer" }, { name = "luasnip" },
{ name = "path" }, { name = "path" },
}, },
confirm_opts = { {
behavior = cmp.ConfirmBehavior.Replace, --This sources will only show up if there aren't any sources from the other list
select = false, { name = "buffer", keyword_length = 5 },
}, }
window = { ),
documentation = cmp.config.window.bordered(), confirm_opts = {
completion = cmp.config.window.bordered({ behavior = cmp.ConfirmBehavior.Replace,
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None" select = false,
}) },
window = {
documentation = cmp.config.window.bordered(),
completion = cmp.config.window.bordered({
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None"
})
}, },
experimental = { experimental = {
ghost_text = false, ghost_text = true,
native_menu = false, native_menu = false,
}, },
} }

View file

@ -1,5 +1,4 @@
local mason_lspconfig = require "mason-lspconfig" local mason_lspconfig = require "mason-lspconfig"
local notify = require "notify"
mason_lspconfig.setup({ mason_lspconfig.setup({
ensure_installed = { "sumneko_lua", "rust_analyzer", "texlab", "hls", "yamlls" }, ensure_installed = { "sumneko_lua", "rust_analyzer", "texlab", "hls", "yamlls" },
@ -48,11 +47,6 @@ local on_attach = function(client, bufnr)
end end
end end
local on_init = function (client, initialize_result)
-- Alert user that LSP finished loading
notify("Finished loading " ..client.name, "info", {title = "LSP"})
end
local lspconfig = require "lspconfig" local lspconfig = require "lspconfig"
-- ADD NVIM CMP AS A CAPABILITY -- ADD NVIM CMP AS A CAPABILITY
@ -71,7 +65,6 @@ mason_lspconfig.setup_handlers {
function(server_name) function(server_name)
lspconfig[server_name].setup { lspconfig[server_name].setup {
on_attach = on_attach, on_attach = on_attach,
on_init = on_init,
flags = lsp_flags, flags = lsp_flags,
capabilities = capabilities, capabilities = capabilities,
} }

View file

@ -24,36 +24,38 @@ local plugins = packer.startup({ function(use)
end end
} }
use { 'stevearc/dressing.nvim' } -- Rename variable pop up use { "stevearc/dressing.nvim" } -- Rename variable pop up
use { "windwp/nvim-autopairs", use { "windwp/nvim-autopairs",
config = function() require("nvim-autopairs").setup {} config = function() require("nvim-autopairs").setup {}
end end
} }
use { 'kyazdani42/nvim-web-devicons' } use { "kyazdani42/nvim-web-devicons" }
use { use {
'nvim-lualine/lualine.nvim', "nvim-lualine/lualine.nvim",
requires = { 'kyazdani42/nvim-web-devicons', opt = true }, requires = { "kyazdani42/nvim-web-devicons", opt = true },
config = function() config = function()
require 'plugins.lualine' require 'plugins.lualine'
end end
} }
use { 'rcarriga/nvim-notify', use {"j-hui/fidget.nvim",
config = function() config = function ()
vim.notify = require("notify") require("fidget").setup{}
end end
} }
use {"voldikss/vim-floaterm"}
--------------------------------------------------SUGGESTION BOX----------------------------------------- --------------------------------------------------SUGGESTION BOX-----------------------------------------
use { "hrsh7th/nvim-cmp", use { "hrsh7th/nvim-cmp",
requires = { requires = {
'hrsh7th/cmp-nvim-lsp', -- lsp "hrsh7th/cmp-nvim-lsp", -- lsp
'hrsh7th/cmp-buffer', --buffer completions "hrsh7th/cmp-buffer", --buffer completions
'hrsh7th/cmp-path', --path completions "hrsh7th/cmp-path", --path completions
'hrsh7th/cmp-cmdline' --cmdline completions "hrsh7th/cmp-cmdline" --cmdline completions
}, },
config = function() config = function()
require "plugins.cmp" require "plugins.cmp"
@ -92,9 +94,9 @@ local plugins = packer.startup({ function(use)
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
use { 'nvim-tree/nvim-tree.lua', use { "nvim-tree/nvim-tree.lua",
requires = { requires = {
'nvim-tree/nvim-web-devicons', -- optional, for file icons "nvim-tree/nvim-web-devicons", -- optional, for file icons
}, },
config = function() config = function()
require("nvim-tree").setup() require("nvim-tree").setup()
@ -119,8 +121,8 @@ local plugins = packer.startup({ function(use)
} }
--Tabs --Tabs
use { 'romgrk/barbar.nvim', use { "romgrk/barbar.nvim",
requires = 'kyazdani42/nvim-web-devicons', requires = "kyazdani42/nvim-web-devicons",
config = function() config = function()
require "plugins.barbar" require "plugins.barbar"
end end
@ -128,9 +130,9 @@ local plugins = packer.startup({ function(use)
--fuzzy file finding --fuzzy file finding
use { use {
'nvim-telescope/telescope.nvim', tag = '0.1.0', "nvim-telescope/telescope.nvim", tag = '0.1.0',
-- or , branch = '0.1.x', -- or , branch = '0.1.x',
requires = { { 'nvim-lua/plenary.nvim' } }, requires = { { "nvim-lua/plenary.nvim" } },
config = function() require('plugins.telescope') end config = function() require('plugins.telescope') end
} }