D Liebman
D Liebman

Reputation: 347

nvim configuration for dropdown suggestions

I've got a vim setup that is close to my desired setup. I can type and see suggestions in my text as I type. That is my goal. I have a NerdFonts font installed and NerTree, and I can see icons in NerTree. I cannot see icons in the text that drops down as I type, and that is my problem.

    set clipboard=unnamedplus   " using system clipboard
    set number

    set hidden 

    call plug#begin("~/.vim/plugged")
    Plug 'neovim/nvim-lspconfig'
    Plug 'hrsh7th/cmp-nvim-lsp'
    Plug 'hrsh7th/cmp-buffer'
    Plug 'hrsh7th/cmp-path'
    Plug 'hrsh7th/cmp-cmdline'
    Plug 'hrsh7th/nvim-cmp'


    Plug 'dracula/vim', { 'as': 'dracula' } " better dracula

    Plug 'preservim/nerdtree'
    Plug 'vim-airline/vim-airline'

    Plug 'williamboman/nvim-lsp-installer'
    Plug 'neovim/nvim-lspconfig'

    " start coc stuff here - auto complete js and python
    Plug 'neoclide/coc.nvim', {'branch': 'release'} " this is for auto complete, prettier and tslinting 

    Plug 'jiangmiao/auto-pairs' "this will auto close ( [ {

    " these two plugins will add highlighting and indenting to JSX and TSX files.
    Plug 'yuezk/vim-js'
    Plug 'HerringtonDarkholme/yats.vim'
    Plug 'maxmellon/vim-jsx-pretty'

    " Plug 'yamatsum/nvim-nonicons'

    Plug 'ryanoasis/vim-devicons'

    call plug#end()

    colorscheme dracula

    let g:coc_global_extensions = ['coc-tslint-plugin', 'coc-tsserver', 'coc-css', 'coc-html', 'coc-json', 'coc-prettier', 'coc-python', 'coc-pyright']  " list of CoC extensions needed


    set encoding=UTF-8

    " set guifont=agave\ Nerd\ Font\ Mono\ 12 

    " set guifont=DroidSansMono\ Nerd\ Font\ 12

    " Start NERDTree. If a file is specified, move the cursor to its window.
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

    " Close the tab if NERDTree is the only window remaining in it.
    autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

    set mouse=a 

    let g:NERDTreeMouseMode = 2 
    let g:airline_powerline_fonts = 1 

    if has("autocmd")
      au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
    endif

    let g:airline#extensions#tabline#enabled=1
    let g:airline_theme='dracula' " 'badwolf'
    let g:airline_powerline_fonts = 1 

    """"""""""""""""""""""""""""""""""""""""
    "" keymaps
    """"""""""""""""""""""""""""""""""""""""


    lua <<EOF
     require "keymap"
    EOF

    """"""""""""""""""""""""""""""""""""""""""""""
    "" cmp
    """"""""""""""""""""""""""""""""""""""""""""""
    set completeopt=menu,menuone,noselect


    set signcolumn=yes

    " 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 <tab>' to make sure tab is not mapped by
    " other plugin before putting this into your config.
    inoremap <silent><expr> <TAB>
          \ coc#pum#visible() ? coc#pum#next(1) :
          \ CheckBackspace() ? "\<Tab>" :
          \ coc#refresh()
    inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

    " Make <CR> to accept selected completion item or notify coc.nvim to format
    " <C-g>u breaks current undo, please make your own choice.
    inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                      \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

    function! CheckBackspace() abort
      let col = col('.') - 1
      return !col || getline('.')[col - 1]  =~# '\s'
    endfunction

nvim v0.7.2

enter image description here

See, on the right, there are colored letters but not icons.

Upvotes: 0

Views: 2683

Answers (2)

D Liebman
D Liebman

Reputation: 347

I am using neovim v0.7.2 . I am also using the Plug package manager. I believe the line below is important in the section where loadable packages are listed.

...
Plug 'neoclide/coc.nvim', {'branch': 'release'} 
...

After this we go to the site at this url:

https://www.chrisatmachine.com/blog/category/neovim/26-lsp-symbols

The idea is to add special definitions to the coc-settings.json file. You can open this file with the command :CocConfig. When you have edited the file, save it again and - if you have already installed coc.nvim - restart nvim. When you type in a supported file type you should get icons in the dropdown box next to the coc suggestion.

Below is a copy of the coc-settings.json file from my setup.

{
  "suggest.completionItemKindLabels": {
    "method": "  ",
    "function": "  ",
    "variable": "[]",
    "field": "  ",
    "typeParameter": "<>",
    "constant": "  ",
    "class": " פּ ",
    "interface": " 蘒",
    "struct": "  ",
    "event": "  ",
    "operator": "  ",
    "module": "  ",
    "property": "  ",
    "enum": " 練",
    "reference": "  ",
    "keyword": "  ",
    "file": "  ",
    "folder": " ﱮ ",
    "color": "  ",
    "unit": " 塞 ",
    "snippet": "  ",
    "text": "  ",
    "constructor": "  ",
    "value": "  ",
    "enumMember": "  "
  },
  "explorer.sources": [
    {
      "name": "buffer",
      "expand": true
    },
    {
      "name": "file",
      "expand": true
    }
  ],
  "explorer.keyMappings.global": {
    "<space>": "toggleSelection",
    "L": [
      "expandable?",
      ["expanded?", "cd", "expand"],
      ["collapse", "cd"]
    ]
  },
  "explorer.presets": {
    "floating": {
      "position": "floating",
      "open-action-strategy": "sourceWindow"
    }
  },
  "explorer.icon.enableNerdfont": true,
  "explorer.buffer.tabOnly": true,
  "explorer.file.reveal.whenOpen": false,
  "explorer.file.reveal.filter": {
    "literals": ["node_modules"]
  },
  "explorer.mouseMode": "singleclick",
  "explorer.debug": true
}

Here is a png with an example.

enter image description here

Upvotes: 0

LoneExile
LoneExile

Reputation: 187

hrsh7th/nvim-cmp is use nvim-web-devicons or you need to set an icon for each source.

Follow instructions here.

  cmp.setup {
  formatting = {
    format = function(entry, vim_item)
      if vim.tbl_contains({ 'path' }, entry.source.name) then
        local icon, hl_group = require('nvim-web-devicons').get_icon(entry:get_completion_item().label)
        if icon then
          vim_item.kind = icon
          vim_item.kind_hl_group = hl_group
          return vim_item
        end
      end
      return lspkind.cmp_format({ with_text = false })(entry, vim_item)
    end
  }
}

example setup

call plug#begin(s:plug_dir)
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
call plug#end()

set completeopt=menu,menuone,noselect

lua <<EOF

local icon = {
  Field = ' ',
  Variable = ' ',
}

 local cmp = require'cmp'
 cmp.setup({
  formatting = {
    fields = { 'kind', 'abbr', 'menu' },
    format = function(entry, vim_item)
      vim_item.kind = icon[vim_item.kind]
      return vim_item
    end,
  },
 })
EOF

Upvotes: 0

Related Questions