Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot insert emoji text #7

Open
vishalbalaji opened this issue Jan 17, 2023 · 5 comments · May be fixed by #10
Open

Cannot insert emoji text #7

vishalbalaji opened this issue Jan 17, 2023 · 5 comments · May be fixed by #10

Comments

@vishalbalaji
Copy link

Confirming the emoji inserts the emoji instead of the emoji name even though insert = false is set. Is there any way to get around that?

@hrsh7th
Copy link
Owner

hrsh7th commented Jan 17, 2023

Could you provide youe cmp.setup?

@vishalbalaji
Copy link
Author

local M = {
  "hrsh7th/nvim-cmp",
  enabled = true,
  event = "VeryLazy",

  dependencies = {
    "hrsh7th/cmp-nvim-lsp",
    "hrsh7th/cmp-buffer",
    "hrsh7th/cmp-path",
    "hrsh7th/cmp-cmdline",
    "hrsh7th/cmp-emoji",
    'saadparwaiz1/cmp_luasnip',

    require("config.plugins.lsp.luasnip"),
  },
}

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 = "",
}

M.config = function()
  local cmp = require("cmp")
  local luasnip = require("luasnip")
  local compare = cmp.config.compare

  vim.opt.completeopt = "menu,menuone"

  local config = {}
  local cmp_select = { behavior = cmp.SelectBehavior.Select }

  config.snippet = {
    expand = function(args)
      luasnip.lsp_expand(args.body) -- For `luasnip` users.
    end,
  }

  config.mapping = {
    ["<C-Space>"] = cmp.mapping.complete({ reason = 'manual' }),
    ["<C-e>"]     = cmp.mapping.abort(),
    ["<C-k>"]     = cmp.mapping.select_prev_item(cmp_select),
    ["<C-j>"]     = cmp.mapping.select_next_item(cmp_select),
    ["<C-p>"]     = cmp.mapping.select_prev_item(),
    ["<C-n>"]     = cmp.mapping.select_next_item(),
    ["<CR>"]      = cmp.mapping.confirm(),
  }

  config.sorting =  {
    comparators = {
      compare.offset,
      compare.exact,
      compare.score,
      compare.recently_used,
      compare.locality,
      compare.kind,
      compare.sort_text,
      compare.length,
      compare.order,
    },
  }

  config.window = {
    completion = cmp.config.window.bordered(),
    documentation = cmp.config.window.bordered(),
  }

  config.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.menu = ({
        nvim_lsp = "[LSP]",
        luasnip = "[Snippet]",
        buffer = "[Buffer]",
        path = "[Path]",
        emoji = "[Emoji]",
        cmdline = "[CMD]",
      })[entry.source.name]
      return vim_item
    end,
  }

  config.sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
    { name = "path" },
    { name = "luasnip" },
    { name = "emoji", insert = false },
  })


  -- Setup
  cmp.setup(config)
  cmp.setup.cmdline(":", {
    mapping = {
      ["<Tab>"] = cmp.mapping(cmp.mapping.confirm(), { "i", "c" }),
      ["<C-k>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
      ["<C-j>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
    },
    sources = {
      { name = "cmdline" },
      { name = "path" },
    },
  })

  cmp.setup.cmdline({ "/", "?" }, {
    mapping = {
      ["<Tab>"] = cmp.mapping(cmp.mapping.confirm(), { "i", "c" }),
      ["<C-k>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
      ["<C-j>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
    },
    sources = {
      { name = "buffer" },
    },
  })
end

return M

@lychronicity
Copy link

lychronicity commented Mar 28, 2023

Hiya, just wanted to chime in here as well seeing that this issue hasn't had much movement.

I have also tried setting the insert option to true and false but both have the same outcome i.e. the completion inserts the unicode emoji icon (😄) rather than the emoji text (:smile:)

Edit: Added relevant config snippet

cmp.setup.filetype('markdown', {
  sources = {
    { name = 'emoji', option = { insert = false } },
  }
})

@rlopzc
Copy link

rlopzc commented Apr 20, 2023

+1 I have the same behavior, icon is always inserted instead of the text regardless o setting the option.insert to false

@UtkarshKunwar
Copy link

UtkarshKunwar commented Jan 14, 2024

Is there any update on this issue? I tried to revert to earlier commits of the project as well in my config but I am still getting the same behaviour of getting the emoji 😄 instead of :smile:

EDIT: I've created a PR #10 which solves this issue for me. Feedback is appreciated.

@UtkarshKunwar UtkarshKunwar linked a pull request Jan 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants