【问题标题】:nvim configuration for dropdown suggestions下拉建议的 nvim 配置
【发布时间】:2022-11-17 08:23:10
【问题描述】:

我有一个接近我想要的设置的 vim 设置。我可以在输入时在文本中输入和查看建议。那是我的目标。我安装了 NerdFonts 字体和 NerTree,我可以在 NerTree 中看到图标。我在键入时看不到下拉文本中的图标,这是我的问题。

    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

看,在右侧,有彩色字母但没有图标。

【问题讨论】:

    标签: lua neovim


    【解决方案1】:

    hrsh7th/nvim-cmp正在使用nvim-web-devicons 或者您需要为每个来源设置一个图标。

    按照说明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
      }
    }
    

    示例设置

    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
    

    【讨论】:

    • 我用local cmp = require'cmp'试过这个。不幸的是它仍然无法正常工作。我的抱怨和上面一样。
    • @DLiebman 你调用了这个插件但是你是否像上面提到的 LoneExile 那样设置了插件?你也有没有在你的 vim 插件上安装 nvim-web-devicons
    • 是的,我尝试了上面的 sn-p 以及 Plug 'nvim-web-devicons' 行。我不得不说,我有 NERDTree 的图标,只是没有可能完成的下拉列表。是我不够清楚吗?还是有问题...
    • 我正在使用 Gnome-Terminal 和 DroidSansMono Nerd 字体。我在 Gnome-Terminal 的首选项文件中设置了字体。我被告知 guifont 仅适用于 vim gui。当我在 init.vim 中更改它时,什么也没有发生。
    • 我添加了一个示例设置。你能测试一下吗?
    猜你喜欢
    • 2022-08-22
    • 2017-12-11
    • 1970-01-01
    • 2012-09-22
    • 2019-11-13
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 2013-05-24
    相关资源
    最近更新 更多