首页 > 其他分享 >nvim config

nvim config

时间:2023-03-31 19:13:15浏览次数:53  
标签:Plug set -- vim coc config nvim


" echo $MYVIMRC
" source $MYVIMRC

set enc=utf-8
set fencs=utf-8,gbk,big5,cp936,gb18030,gb2312,utf-16
set fenc=utf-8
set shortmess=atI

"禁止bell
set belloff=all
set visualbell
set t_vb=

let mapleader = "\<Space>"
inoremap jj <ESC>


"-------------------------------------------------------------------------------
" 去除行尾空白符 bronson/vim-trailing-whitespace
"-------------------------------------------------------------------------------
"This plugin causes trailing whitespace to be highlighted in red.

"To fix the whitespace errors, call :FixWhitespace.

"By default it operates on the entire file.

"Pass a range (or use V to select some lines)
"to restrict the portion of the file that gets fixed.

"fun! TrimWhiteSpace()
"    let l:save = winsaveview()
"    keeppatterns %s/\s\+$//e
"    call winrestview(l:save)
"endfun

"noremap <leader>t :call :FixWhitespace <CR>

"-------------------------------------------------------------------------------
" 注释 vim-commentary
"-------------------------------------------------------------------------------
" toggle注释单行
" normal mode: gcc

" toggle 多行注释
" 首先进入visual mode,然后选择。gc toggle注释

"-------------------------------------------------------------------------------
" 缩进
"-------------------------------------------------------------------------------
"  visual mode
"  shift+< 然后 > 增加缩进
"  shift+> 然后 > 减少缩进

" normal mode
" shift + > + >
" shift + < + <

"-------------------------------------------------------------------------------
" 大小写转换
"-------------------------------------------------------------------------------
"  visual mode
"  ~

"-------------------------------------------------------------------------------
"  视图
"-------------------------------------------------------------------------------
" normal mode
" <C-O>  <C-I> zz
" <C-E>  <C-D>
" <C-Y>  <C-U>
" G      gg

"-------------------------------------------------------------------------------
"  选择
"-------------------------------------------------------------------------------
" Make vaa select the entire file...
xmap aa VGo1G

" -------------------------------------------------------------------------------
" 搜索 yggdroot/leaderf
" -------------------------------------------------------------------------------
" 编译C语言扩展,搜索会快10倍
":LeaderfInstallCExtension

"<leader>f 打开窗口
"<C-R> 切换搜索模式,fuzzy或regex
"Ctrl j k 在搜索结果中选择
"<C-T> 在新标签页打开文件
"<C-]> 竖向分隔窗口打开文件

" let g:Lf_WindowPosition = 'popup'
"  let g:Lf_PreviewInPopup = 1
"  let g:Lf_WindowHeight = 0.85
"  let g:Lf_DefaultExternalTool = 'rg'
"  let g:Lf_ShowHidden = 1

"noremap <A-n> :Leaderf file --no-ignore <CR>
"noremap <A-m> :Leaderf rg --no-ignore<CR>

"  noremap <A-n> :Leaderf file <CR>
"  noremap <A-m> :Leaderf rg <CR>
"<C-P> 预览当前文件
"Ctrl H L 滚动预览窗口
"  let g:Lf_CommandMap = {'<C-Up>': ['<C-L>'], '<C-Down>': ['<C-H>']}

"-------------------------------------------------------------------------------
" copy paste
"-------------------------------------------------------------------------------
"https://ramezanpour.net/post/2022/07/24/access-os-clipboard-in-neovim

" macOS
set clipboard+=unnamedplus

" windows
" https://github.com/equalsraf/win32yank

" Linux Wayland
" sudo apt install wl-clipboard

" linux X11
" https://github.com/astrand/xclip

"-------------------------------------------------------------------------------
" 字体 行号 主题
"-------------------------------------------------------------------------------
" 不与 Vi 兼容(采用 Vim 自己的操作命令)
set nocompatible

"行号
set number

"自动保存
"Plug '907th/vim-auto-save'
let g:auto_save = 1

" 字体
 if has('gui_running')
    if has("win16") || has("win32") || has("win95") || has("win64")
        set guifont=Sarasa_Mono_Fixed:h14
    else
        set guifont=Sarasa\ Mono\ Fixed\ 14
    endif
endif

" 在状态栏显示正在输入的命令
set showcmd

set mouse=a

" 启用256色
set t_Co=256

" 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致
set autoindent

" 由于 Tab 键在不同的编辑器缩进不一致,该设置自动将 Tab 转为空格。
set expandtab
" tab相关变更
" 设置Tab键的宽度,等同的空格个数
set tabstop=4
" 每一次缩进对应的空格数
set shiftwidth=4
" 按退格键时可以一次删掉 4 个空格
set softtabstop=4

" 关闭自动折行
set nowrap

" 在状态栏显示光标的当前位置(位于哪一行哪一列)。
set  ruler
" 突出显示当前列
"set cursorcolumn
" 突出显示当前行
set cursorline

" 光标遇到圆括号、方括号、大括号时,自动高亮对应的另一个圆括号、方括号和大括号。
set showmatch

set history=10000

" 打开文件监视。如果在编辑过程中文件发生外部改变(比如被别的编辑器编辑了),就会发出提示。
set autoread

" undo redo
" u    <C-R>

"Square up visual selections...
set virtualedit=block

" Make BS/DEL work as expected in visual modes (i.e. delete the selected text)...
xmap <BS> x

" Prefer vertical orientation when using :diffsplit
set diffopt+=vertical

"可随时用倒退键删除
set backspace=2


"行号
map <leader>n  :set invnumber <CR>
"行折叠
map <leader>w  :set invwrap <CR>

"窗口分隔
map <leader>=  :vsp <CR>
map <leader>-  :sp <CR>

"窗口跳转
"<C-W> jkhl

"关闭当前window
nnoremap <C-q> <ESC>:q <CR>
inoremap <C-q> <ESC>:q <CR>


"新tab中打开本文件
inoremap <C-T> <ESC>:tabnew %<CR> i
nnoremap <C-T> <ESC>:tabnew %<CR>

" 创建新tab
inoremap <C-N> <C-O>:tabnew <CR>
nnoremap <C-N> :tabnew <CR> i


"-------------------------------------------------------------------------------
" 安装插件
"-------------------------------------------------------------------------------
call plug#begin()
"file explorer
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

" search file, content
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' }
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }

" hight light
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'RRethy/vim-illuminate'

" auto compeletion
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'

Plug 'williamboman/mason.nvim', { 'do': ':MasonUpdate' }

" LSP
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/syntastic'

" DAP
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Plug 'theHamsta/nvim-dap-virtual-text'
Plug 'ldelossa/nvim-dap-projects'

" Theme
Plug 'Mofiqul/vscode.nvim'
"  Plug 'navarasu/onedark.nvim'
"  Plug 'sickill/vim-monokai'

" icon
Plug 'nvim-tree/nvim-web-devicons'

" Project
Plug 'ahmedkhalf/project.nvim'

" column limit
Plug 'm4xshen/smartcolumn.nvim'

" status bar
Plug 'nvim-lualine/lualine.nvim'
" If you want to have icons in your statusline choose one of these
Plug 'nvim-tree/nvim-web-devicons'

" tab
Plug 'akinsho/bufferline.nvim', { 'tag': 'v3.*' }

" window
Plug 'sindrets/winshift.nvim'

" register
Plug 'gennaro-tedesco/nvim-peekup'

" color
Plug 'NvChad/nvim-colorizer.lua'

" start up
Plug 'glepnir/dashboard-nvim'

" terminal
Plug 'akinsho/toggleterm.nvim', {'tag' : '*'}

" comment
Plug 'numToStr/Comment.nvim'
Plug 'folke/todo-comments.nvim'

" UI
Plug 'MunifTanjim/nui.nvim'
Plug 'rcarriga/nvim-notify'
Plug 'folke/noice.nvim'

" git
Plug 'f-person/git-blame.nvim'
Plug 'sindrets/diffview.nvim'

" bookmark
Plug 'MattesGroeger/vim-bookmarks'

" scroll
Plug 'dstein64/nvim-scrollview', { 'branch': 'main' }

" mini map
Plug 'gorbit99/codewindow.nvim'

" pair
Plug 'windwp/nvim-autopairs'
Plug 'luochen1990/rainbow'
Plug 'tpope/vim-surround'

" format
Plug 'lukas-reineke/indent-blankline.nvim'
Plug 'bronson/vim-trailing-whitespace'

" ascii art
Plug 'godlygeek/tabular'

" autosave
Plug '907th/vim-auto-save'

" mouse key
Plug 'folke/which-key.nvim'

call plug#end()

"-------------------------------------------------------------------------------
"  Theme
"-------------------------------------------------------------------------------
"  syntax enable
"  colorscheme monokai

lua <<EOF
-- Lua:
-- For dark theme (neovim's default)
vim.o.background = 'dark'
-- For light theme
-- vim.o.background = 'light'

local c = require('vscode.colors').get_colors()
require('vscode').setup({
    -- Alternatively set style in setup
    -- style = 'light'

    -- Enable transparent background
    transparent = true,

    -- Enable italic comment
    italic_comments = true,

    -- Disable nvim-tree background color
    disable_nvimtree_bg = true,

    -- Override colors (see ./lua/vscode/colors.lua)
    color_overrides = {
        vscFront = '#cecece',
        vscBack = '#1c1c1c',
    },

    -- Override highlight groups (see ./lua/vscode/theme.lua)
    group_overrides = {
        -- this supports the same val table as vim.api.nvim_set_hl
        -- use colors from this colorscheme by requiring vscode.colors!
        Cursor = { fg=c.vscDarkBlue, bg=c.vscLightGreen, bold=true },
    }
})
require('vscode').load()
EOF


"  lua <<EOF
"  -- Lua
"  require('onedark').setup  {
"      -- Main options --
"      style = 'dark', -- Default theme style. Choose between 'dark', 'darker', 'cool', 'deep', 'warm', 'warmer' and 'light'
"      transparent = false,  -- Show/hide background
"      term_colors = true, -- Change terminal color as per the selected theme style
"      ending_tildes = false, -- Show the end-of-buffer tildes. By default they are hidden
"      cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu

"      -- toggle theme style ---
"      toggle_style_key = nil, -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "<leader>ts"
"      toggle_style_list = {'dark', 'darker', 'cool', 'deep', 'warm', 'warmer', 'light'}, -- List of styles to toggle between

"      -- Change code style ---
"      -- Options are italic, bold, underline, none
"      -- You can configure multiple style with comma separated, For e.g., keywords = 'italic,bold'
"      code_style = {
"          comments = 'italic',
"          keywords = 'none',
"          functions = 'bold',
"          strings = 'none',
"          variables = 'none'
"      },

"      -- Lualine options --
"      lualine = {
"          transparent = false, -- lualine center bar transparency
"      },

"      -- Custom Highlights --
"      colors = {}, -- Override default colors
"      highlights = {}, -- Override highlight groups

"      -- Plugins Config --
"      diagnostics = {
"          darker = true, -- darker colors for diagnostic
"          undercurl = true,   -- use undercurl instead of underline for diagnostics
"          background = true,    -- use background color for virtual text
"      },
"  }

"  require('onedark').load()
"  EOF

"-------------------------------------------------------------------------------
" NERDTree
"-------------------------------------------------------------------------------

"toggle panel
map <leader>e :NERDTreeToggle<CR>

let NERDTreeAutoCenter=1

let NERDTreeShowLineNumbers=1

let NERDTreeShowHidden=1

let NERDTreeWinSize=35

" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1

let g:NERDTreeGitStatusIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }

"-------------------------------------------------------------------------------
" 搜索
"-------------------------------------------------------------------------------
" 搜索时,高亮显示匹配结果。
set hlsearch
"highlight clear Search

"清除高亮
map <leader>c :nohl <CR>

" 搜索设置
set ignorecase
set incsearch


"===============================================================================
" telescope.nvim
"===============================================================================
" Dep plug
" https://github.com/nvim-telescope/telescope-fzf-native.nvim
" https://github.com/nvim-treesitter/nvim-treesitter
" https://github.com/nvim-tree/nvim-web-devicons

" Dep cli
" https://github.com/BurntSushi/ripgrep
" https://github.com/sharkdp/fd

lua << EOF
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
EOF

"===============================================================================
" telescope-fzf-native.nvim
"===============================================================================
lua << EOF
-- You dont need to set any of these options. These are the default ones. Only
-- the loading is important
require('telescope').setup {
  extensions = {
    fzf = {
      fuzzy = true,                    -- false will only do exact matching
      override_generic_sorter = true,  -- override the generic sorter
      override_file_sorter = true,     -- override the file sorter
      case_mode = "smart_case",        -- or "ignore_case" or "respect_case"
                                       -- the default case_mode is "smart_case"
    }
  }
}
-- To get fzf loaded and working with telescope, you need to call
-- load_extension, somewhere after setup function:
require('telescope').load_extension('fzf')
EOF

"===============================================================================
" nvim-treesitter/nvim-treesitter
"===============================================================================
" The goal of nvim-treesitter is both to provide
" a simple and easy way to use the interface for tree-sitter in Neovim and
" to provide some basic functionality such as highlighting based on it

" :TSModuleInfo [{module}] " list information about modules state for each filetyp
" :TSUpdate {language}. To update all parsers unconditionally, use :TSUpdate all or just :TSUpdate.
lua << EOF
require('nvim-treesitter.configs').setup{
  -- A list of parser names, or "all" (the five listed parsers should always be installed)
  ensure_installed = { "c","cpp", "lua", "vim", "help", "query","bash", "c_sharp","cmake","cuda", "diff","dockerfile","dot","glsl","go","html","css","scss","tsx","sql","java","javascript","typescript","vue","yaml","json","json5","latex","llvm","make","ninja","python","rust", "regex" },

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  -- List of parsers to ignore installing (for "all")
  ignore_install = { "javascript" },

  ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!

  highlight = {
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { "c", "rust" },
    -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
    disable = function(lang, buf)
        local max_filesize = 100 * 1024 -- 100 KB
        local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        if ok and stats and stats.size > max_filesize then
            return true
        end
    end,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}
EOF

"===============================================================================
" hrsh7th/nvim-cmp
"===============================================================================
lua <<EOF
  -- Set up nvim-cmp.
  local cmp = require'cmp'

  cmp.setup({
    snippet = {
      -- REQUIRED - you must specify a snippet engine
      expand = function(args)
        vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
        -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
        -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
        -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
      end,
    },
    window = {
      -- completion = cmp.config.window.bordered(),
      -- documentation = cmp.config.window.bordered(),
    },
    mapping = cmp.mapping.preset.insert({
      ['<C-b>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.abort(),
      ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
    }),
    sources = cmp.config.sources({
      { name = 'nvim_lsp' },
      { name = 'vsnip' }, -- For vsnip users.
      -- { name = 'luasnip' }, -- For luasnip users.
      -- { name = 'ultisnips' }, -- For ultisnips users.
      -- { name = 'snippy' }, -- For snippy users.
    }, {
      { name = 'buffer' },
    })
  })

  -- Set configuration for specific filetype.
  cmp.setup.filetype('gitcommit', {
    sources = cmp.config.sources({
      { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
    }, {
      { name = 'buffer' },
    })
  })

  -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline({ '/', '?' }, {
    mapping = cmp.mapping.preset.cmdline(),
    sources = {
      { name = 'buffer' }
    }
  })

  -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline(),
    sources = cmp.config.sources({
      { name = 'path' }
    }, {
      { name = 'cmdline' }
    })
  })

  -- Set up lspconfig.
  local capabilities = require('cmp_nvim_lsp').default_capabilities()
  -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
  --require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
  --  capabilities = capabilities
  --}
EOF


"===============================================================================
"   coc-nvim
"===============================================================================
" static analysis
let g:coc_global_extensions = ['coc-marketplace', 'coc-calc' ,'coc-clangd' ,'coc-cmake' ,'coc-css' ,'coc-cssmodules' ,'coc-diagnostic' ,'coc-docker' ,'coc-eslint' ,'coc-explorer' ,'coc-floaterm' ,'coc-fzf-preview' ,'coc-git' ,'coc-glslx' ,'coc-go' ,'coc-highlight' ,'coc-html' ,'coc-html-css-support' ,'coc-htmlhint' ,'coc-java' ,'coc-json' ,'coc-lists' ,'coc-ltex' ,'coc-lua' ,'coc-markdownlint' ,'coc-nav' ,'coc-omnisharp' ,'coc-pairs' ,'coc-perl' ,'coc-powershell' ,'coc-prettier' ,'coc-pyright' ,'coc-python' ,'coc-rust-analyzer' ,'coc-sh' ,'coc-snippets' ,'coc-spell-checker' ,'coc-sql' ,'coc-stylua' ,'coc-svg' ,'coc-swagger' ,'coc-syntax' ,'coc-tsserver' ,'coc-xml' ,'coc-yaml' ,'coc-yank']
":CocList marketplace

" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

"  lua require("mason").setup()

lua << EOF
 -- Setup language servers.
 local lspconfig = require('lspconfig')
 lspconfig.ccls.setup {
   init_options = {
     compilationDatabaseDirectory = "build";
     index = {
       threads = 0;
     };
     clang = {
       excludeArgs = { "-frounding-math"} ;
     };
   }
 }
EOF

"===============================================================================
"   dap
"===============================================================================
" debug
lua <<EOF
require('nvim-dap-projects').search_project_config()
require("dapui").setup()
require("nvim-dap-virtual-text").setup()

vim.fn.sign_define('DapBreakpoint',{ text ='

标签:Plug,set,--,vim,coc,config,nvim
From: https://www.cnblogs.com/Searchor/p/17277238.html

相关文章