首页 > 其他分享 >nvim configration

nvim configration

时间:2023-05-14 19:00:52浏览次数:40  
标签:opt map use configration -- vim nvim

in nvim

in ~/.config/nvim 

create a  file named "init.lua"

and a directory named lua

in lua create files as

keybinding.lua basic.lua plugins.lua and 

directory as 

plugin-config

-- 自动安装 Packer.nvim
-- 插件安装目录
-- ~/.local/share/nvim/site/pack/packer/
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
local paccker_bootstrap
if fn.empty(fn.glob(install_path)) > 0 then
  vim.notify("正在安装Pakcer.nvim,请稍后...")
  paccker_bootstrap = fn.system({
    "git",
    "clone",
    "--depth",
    "1",
    "https://github.com/wbthomason/packer.nvim",
    -- "https://gitcode.net/mirrors/wbthomason/packer.nvim",
    install_path,
  })

  -- https://github.com/wbthomason/packer.nvim/issues/750
  local rtp_addition = vim.fn.stdpath("data") .. "/site/pack/*/start/*"
  if not string.find(vim.o.runtimepath, rtp_addition) then
    vim.o.runtimepath = rtp_addition .. "," .. vim.o.runtimepath
  end
  vim.notify("Pakcer.nvim 安装完毕")
end

-- Use a protected call so we don't error out on first use
local status_ok, packer = pcall(require, "packer")
if not status_ok then
  vim.notify("没有安装 packer.nvim")
  return
end

packer.startup({
  function(use)
    -- Packer 可以升级自己
    use{"wbthomason/packer.nvim"}

    -------------------------- plugins -------------------------------------------
    -------- coc.nvim
    use{'neoclide/coc.nvim', branch = 'release'}
    use{"nvim-tree/nvim-web-devicons"}

    -------- nvim-tree
    use {
      'nvim-tree/nvim-tree.lua',
      requires = {
        'nvim-tree/nvim-web-devicons', -- optional
      },
--      config = function()
 --       require("nvim-tree").setup {}
  --    end
    }

    -- bufferline
    use {'akinsho/bufferline.nvim', 
    tag = "*", 
    requires = {'nvim-tree/nvim-web-devicons',"moll/vim-bbye"}
    }

    -- lualine
    use{
      "nvim-lualine/lualine.nvim",
      requires = { "nvim-tree/nvim-web-devicons",opt=true }
    }
    use("arkav/lualine-lsp-progress")

    -- telescope
    use {
      'nvim-telescope/telescope.nvim', tag = '0.1.1',
    -- or                            , branch = '0.1.x',
      requires = { {'nvim-lua/plenary.nvim'} }
    }
    -- telescope extensions
    use("nvim-telescope/telescope-ui-select.nvim")

    -- dashboard-nvim
    use {
      'glepnir/dashboard-nvim',
   --   event = 'VimEnter',
    --  config = function()
     --   require('dashboard').setup {
      --    -- config
       -- }
     -- end,
      requires = {'nvim-tree/nvim-web-devicons'}
    }
    -------------------------------------------------------
    ---terminal
    use {"akinsho/toggleterm.nvim", tag = '*'}
    --config = function()
      --require("toggleterm").setup()
    --end}
    -- surround
    use{"ur4ltz/surround.nvim"}
    -- Comment
    use{"numToStr/Comment.nvim"}
    -- nvim-autopairs
    use{"windwp/nvim-autopairs"}
    -- git
    use{"lewis6991/gitsigns.nvim" }
    -- whichkey
    use{
      "folke/which-key.nvim",
      --config = function()
        --vim.o.timeout = true
        --vim.o.timeoutlen = 300
        --require("which-key").setup {
          -- your configuration comes here
          -- or leave it empty to use the default settings
          -- refer to the configuration section below
        --}
      --end
    }

    -- vimspectuse {
    use{
      "puremourning/vimspector",
      cmd = { "VimspectorInstall", "VimspectorUpdate" },
      fn = { "vimspector#Launch()", "vimspector#ToggleBreakpoint", "vimspector#Continue" },
      --config = function()
      --  require("config.vimspector").setup()
      --end,
    }

    -- project
    use {
    "ahmedkhalf/project.nvim",
    --config = function()
    --  require("project_nvim").setup {
        -- your configuration comes here
        -- or leave it empty to use the default settings
        -- refer to the configuration section below
     -- }
    --end
    }
    -- treesitter
    use{
      "nvim-treesitter/nvim-treesitter",
      run = ":TSUpdate",
    }
    use{"p00f/nvim-ts-rainbow"}

    -- indent-blankline
    use{"lukas-reineke/indent-blankline.nvim"}
    --------------------- colorschemes --------------------
    -- tokyonight
    use{"folke/tokyonight.nvim"}
    -- gruvbox
    use{
      "ellisonleao/gruvbox.nvim",
      requires = {{ "rktjmp/lush.nvim" }},
    }

    ----------------------------------------------
    use("mfussenegger/nvim-dap")
    use("theHamsta/nvim-dap-virtual-text")
    use("rcarriga/nvim-dap-ui")

    -- display the status of lsp
    use("j-hui/fidget.nvim")

    --------------------- LSP --------------------
    -- use("Pocco81/DAPInstall.nvim")
    -- use("jbyuki/one-small-step-for-vimkind")
    --use("LinArcX/telescope-env.nvim")
    -- use({ "williamboman/nvim-lsp-installer", commit = "36b44679f7cc73968dbb3b09246798a19f7c14e0" })
    --use({ "williamboman/nvim-lsp-installer" })
    -- Lspconfig
    --use({ "neovim/nvim-lspconfig" })
    -- 补全引擎
    --use("hrsh7th/nvim-cmp")
    -- Snippet 引擎
    --use("hrsh7th/vim-vsnip")
    -- 补全源
    --use("hrsh7th/cmp-vsnip")
    --use("hrsh7th/cmp-nvim-lsp") -- { name = nvim_lsp }
    --use("hrsh7th/cmp-buffer") -- { name = 'buffer' },
    --use("hrsh7th/cmp-path") -- { name = 'path' }
    --use("hrsh7th/cmp-cmdline") -- { name = 'cmdline' }
    --use("hrsh7th/cmp-nvim-lsp-signature-help") -- { name = 'nvim_lsp_signature_help' }
    -- 常见编程语言代码段
    --use("rafamadriz/friendly-snippets")
    -- UI 增强
    --use("onsails/lspkind-nvim")
    --use("tami5/lspsaga.nvim")
    -- 代码格式化
    --use("mhartington/formatter.nvim")
    --use({ "jose-elias-alvarez/null-ls.nvim", requires = "nvim-lua/plenary.nvim" })
    -- TypeScript 增强
    --use({ "jose-elias-alvarez/nvim-lsp-ts-utils", requires = "nvim-lua/plenary.nvim" })
    -- Lua 增强
    --use("folke/lua-dev.nvim")
    -- JSON 增强
    --use("b0o/schemastore.nvim")
    -- Rust 增强
    --use("simrat39/rust-tools.nvim")

    if paccker_bootstrap then
      packer.sync()
    end

  end,
  config = {
    -- 锁定插件版本在snapshots目录
    snapshot_path = require("packer.util").join_paths(vim.fn.stdpath("config"), "snapshots"),
    -- 这里锁定插件版本在v1,不会继续更新插件
    snapshot = "v1",

    -- 最大并发数
    max_jobs = 16,
    -- 自定义源
    git = {
      -- default_url_format = "https://hub.fastgit.xyz/%s",
      -- default_url_format = "https://mirror.ghproxy.com/https://github.com/%s",
      -- default_url_format = "https://gitcode.net/mirrors/%s",
      -- default_url_format = "https://gitclone.com/github.com/%s",
    },
    -- display = {
    -- 使用浮动窗口显示
    --   open_fn = function()
    --     return require("packer.util").float({ border = "single" })
    --   end,
    -- },
  },
})

-- 每次保存 plugins.lua 自动安装插件
-- move to autocmds.lua
-- pcall(
--   vim.cmd,
--   [[
-- augroup packer_user_config
-- autocmd!
-- autocmd BufWritePost plugins.lua source <afile> | PackerSync
-- augroup end
-- ]]
-- )

 

 

-- utf8
vim.g.encoding = "UTF-8"
vim.o.fileencoding = "utf-8"
-- jkhl 移动时光标周围保留8行
vim.o.scrolloff = 8
vim.o.sidescrolloff = 8
-- 使用相对行号
vim.wo.number = true
vim.wo.relativenumber = true
-- 高亮所在行
vim.wo.cursorline = true
-- 显示左侧图标指示列
vim.wo.signcolumn = "yes"
-- 右侧参考线,超过表示代码太长了,考虑换行
vim.wo.colorcolumn = "80"
-- 缩进2个空格等于一个Tab
vim.o.tabstop = 2
vim.bo.tabstop = 2
vim.o.softtabstop = 2
vim.o.shiftround = true
-- >> << 时移动长度
vim.o.shiftwidth = 2
vim.bo.shiftwidth = 2
-- 空格替代tab
vim.o.expandtab = true
vim.bo.expandtab = true
-- 新行对齐当前行
vim.o.autoindent = true
vim.bo.autoindent = true
vim.o.smartindent = true
-- 搜索大小写不敏感,除非包含大写
vim.o.ignorecase = true
vim.o.smartcase = true
-- 搜索不要高亮
vim.o.hlsearch = false
-- 边输入边搜索
vim.o.incsearch = true
-- 命令行高为2,提供足够的显示空间
vim.o.cmdheight = 1
-- 当文件被外部程序修改时,自动加载
vim.o.autoread = true
vim.bo.autoread = true
-- 禁止折行
vim.wo.wrap = false
-- 光标在行首尾时<Left><Right>可以跳到下一行
vim.o.whichwrap = "<,>,[,]"
-- 允许隐藏被修改过的buffer
vim.o.hidden = true
-- 鼠标支持
vim.o.mouse = "a"
-- 禁止创建备份文件
vim.o.backup = false
vim.o.writebackup = false
vim.o.swapfile = false
-- smaller updatetime
vim.o.updatetime = 300
-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒,可根据需要设置
-- 遇到问题详见:https://github.com/nshen/learn-neovim-lua/issues/1
vim.o.timeoutlen = 500
-- split window 从下边和右边出现
vim.o.splitbelow = true
vim.o.splitright = true
-- 自动补全不自动选中
vim.g.completeopt = "menu,menuone,noselect,noinsert"
-- 样式
vim.o.termguicolors = true
vim.opt.termguicolors = true
-- 是否显示不可见字符
vim.o.list = false
-- 不可见字符的显示,这里只把空格显示为一个点
vim.o.listchars = "space:·,tab:··"
-- 补全增强
vim.o.wildmenu = true
-- Dont' pass messages to |ins-completin menu|
vim.o.shortmess = vim.o.shortmess .. "c"
-- 补全最多显示10行
vim.o.pumheight = 10
-- 永远显示 tabline
vim.o.showtabline = 2
-- 使用增强状态栏插件后不再需要 vim 的模式提示
vim.o.showmode = false
-- 配置剪切板
vim.opt.clipboard = "unnamedplus"
-- Modes
--   normal_mode = "n",
--   insert_mode = "i",
--   visual_mode = "v",
--   visual_block_mode = "x",
--   term_mode = "t",
--   command_mode = "c",

-- leader key 为空
vim.g.mapleader = " "
vim.g.maplocalleader = " "

local opt = {
  noremap = true,
  silent = true,
}

-- 本地变量
local map = vim.api.nvim_set_keymap

map("n","9","$",opt)
map("n","0","^",opt)

-- $跳到行尾不带空格 (交换$ 和 g_)
map("v", "$", "g_", opt)
map("v", "g_", "$", opt)
map("n", "$", "g_", opt)
map("n", "g_", "$", opt)

-- 命令行下 Ctrl+j/k  上一个下一个
map("c", "<C-j>", "<C-n>", { noremap = false })
map("c", "<C-k>", "<C-p>", { noremap = false })

map("n", "<leader>w", ":w<CR>", opt)
map("n", "<leader>wq", ":wqa!<CR>", opt)

-- fix :set wrap
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })

-- 上下滚动浏览
map("n", "<C-j>", "5j", opt)
map("n", "<C-k>", "5k", opt)
map("v", "<C-j>", "5j", opt)
map("v", "<C-k>", "5k", opt)
-- ctrl u / ctrl + d  只移动9行,默认移动半屏
map("n", "<C-u>", "10k", opt)
map("n", "<C-d>", "10j", opt)

-- magic search
map("n", "/", "/\\v", { noremap = true, silent = false })
map("v", "/", "/\\v", { noremap = true, silent = false })

-- visual模式下缩进代码
map("v", "<", "<gv", opt)
map("v", ">", ">gv", opt)
-- 上下移动选中文本
map("v", "<A-j>", ":move '>+1<CR>gv-gv", opt)
map("v", "<A-k>", ":move '<-2<CR>gv-gv", opt)
map("n","<A-j>","mz:m.+1<CR>'z",opt)
map("n","<A-k>","mz:m.-2<CR>'z",opt)

-- 在visual mode 里粘贴不要复制
map("v", "p", '"_dP', opt)

-- 退出
map("n", "qq", ":q!<CR>", opt)
map("n", "<leader>q", ":qa!<CR>", opt)

-- insert 模式下,跳到行首行尾
-- map("i", "<C-h>", "<ESC>I", opt)
-- map("i", "<C-l>", "<ESC>A", opt)

------------------------------------------------------------------
-- windows 分屏快捷键
------------------------------------------------------------------
-- 取消 s 默认功能
--map("n", "s", "", opt)
map("n", "sv", ":vsp<CR>", opt)
map("n", "sh", ":sp<CR>", opt)
-- 关闭当前
map("n", "sc", "<C-w>c", opt)
-- 关闭其他
map("n", "so", "<C-w>o", opt) -- close others
-- alt + hjkl  窗口之间跳转
map("n", "wh", "<C-w>h", opt)
map("n", "wj", "<C-w>j", opt)
map("n", "wk", "<C-w>k", opt)
map("n", "wl", "<C-w>l", opt)
-- <leader> + hjkl 窗口之间跳转
map("n", "<leader>h", "<C-w>h", opt)
map("n", "<leader>j", "<C-w>j", opt)
map("n", "<leader>k", "<C-w>k", opt)
map("n", "<leader>l", "<C-w>l", opt)
-- 左右比例控制
map("n", "<C-Left>", ":vertical resize -2<CR>", opt)
map("n", "<C-Right>", ":vertical resize +2<CR>", opt)
map("n", "s,", ":vertical resize -10<CR>", opt)
map("n", "s.", ":vertical resize +10<CR>", opt)
-- 上下比例
map("n", "sj", ":resize +10<CR>", opt)
map("n", "sk", ":resize -10<CR>", opt)
map("n", "<C-Down>", ":resize +2<CR>", opt)
map("n", "<C-Up>", ":resize -2<CR>", opt)
-- 相等比例
map("n", "s=", "<C-w>=", opt)

-- Terminal相关
map("n", "st", ":sp | terminal<CR>", opt)
map("n", "stv", ":vsp | terminal<CR>", opt)
-- Esc 回 Normal 模式
map("t", "<Esc>", "<C-\\><C-n>", opt)
map("t", "<A-h>", [[ <C-\><C-N><C-w>h ]], opt)
map("t", "<A-j>", [[ <C-\><C-N><C-w>j ]], opt)
map("t", "<A-k>", [[ <C-\><C-N><C-w>k ]], opt)
map("t", "<A-l>", [[ <C-\><C-N><C-w>l ]], opt)
map("t", "<leader>h", [[ <C-\><C-N><C-w>h ]], opt)
map("t", "<leader>j", [[ <C-\><C-N><C-w>j ]], opt)
map("t", "<leader>k", [[ <C-\><C-N><C-w>k ]], opt)
map("t", "<leader>l", [[ <C-\><C-N><C-w>l ]], opt)
--------------------------------------------------------------------
-- 插件快捷键
local pluginKeys = {}

-- treesitter 折叠
map("n", "zz", ":foldclose<CR>", opt)
map("n", "Z", ":foldopen<CR>", opt)

-- lsp 回调函数快捷键设置
pluginKeys.mapLSP = function(mapbuf)
  -- rename
  --[[
  Lspsaga 替换 rn
  mapbuf("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opt)
  --]]
  mapbuf("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opt)
  -- code action
  --[[
  Lspsaga 替换 ca
  mapbuf("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opt)
  --]]
  mapbuf("n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opt)
  -- go xx
  --[[
    mapbuf('n', 'gd', '<cmd>Lspsaga preview_definition<CR>', opt)
  mapbuf("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opt)
  --]]
  mapbuf("n", "gd", "<cmd>lua require'telescope.builtin'.lsp_definitions({ initial_mode = 'normal', })<CR>", opt)
  --[[
  mapbuf("n", "gh", "<cmd>Lspsaga hover_doc<cr>", opt)
  Lspsaga 替换 gh
  --]]
  mapbuf("n", "gh", "<cmd>lua vim.lsp.buf.hover()<CR>", opt)
  --[[
  Lspsaga 替换 gr
  mapbuf("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opt)
  --]]
  mapbuf("n", "gr", "<cmd>Lspsaga lsp_finder<CR>", opt)
  --[[
  Lspsaga 替换 gp, gj, gk
  mapbuf("n", "gp", "<cmd>lua vim.diagnostic.open_float()<CR>", opt)
  mapbuf("n", "gj", "<cmd>lua vim.diagnostic.goto_next()<CR>", opt)
  mapbuf("n", "gk", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opt)
  --]]
  -- diagnostic
  mapbuf("n", "gp", "<cmd>Lspsaga show_line_diagnostics<CR>", opt)
  mapbuf("n", "gj", "<cmd>Lspsaga diagnostic_jump_next<cr>", opt)
  mapbuf("n", "gk", "<cmd>Lspsaga diagnostic_jump_prev<cr>", opt)
  mapbuf("n", "<leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opt)
  -- 未用
  -- mapbuf("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opt)
  -- mapbuf("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opt)
  -- mapbuf('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
  -- mapbuf("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opt)
  -- mapbuf('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opt)
  -- mapbuf('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opt)
  -- mapbuf('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opt)
  -- mapbuf('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opt)
end

-- typescript 快捷键
pluginKeys.mapTsLSP = function(mapbuf)
  mapbuf("n", "gs", ":TSLspOrganize<CR>", opt)
  mapbuf("n", "gR", ":TSLspRenameFile<CR>", opt)
  mapbuf("n", "gi", ":TSLspImportAll<CR>", opt)
end



return pluginKeys

 

标签:opt,map,use,configration,--,vim,nvim
From: https://www.cnblogs.com/dogingate/p/17399897.html

相关文章

  • nvim中dashboard配置
     localstatus,db=pcall(require,"dashboard")ifnotstatusthenvim.notify("没有找到dashboard")returnenddb.setup({theme='hyper',config={week_header={enable=true,},shortcut={......
  • nvim-dap C++ cpptools
    https://github.com/microsoft/vscode-cpptoolsgccgdblocaldap=require("dap")dap.adapters.cppdbg={id='cppdbg',type='executable',command='c:\\gnu\\tool\\cpptools\\extension\\debugAdapters\......
  • nvim-treesitter coc.nvim
    PSC:\Users\dev\AppData\Local\nvim-data\plugged\nvim-treesitter\parser>lsdbash.socpp.sodockerfile.sohtml.solatex.soninja.sorust.sotypescript.soc.socss.sodot.sojava.sollvm......
  • mingw64 + nvim + coc.nvim + nvim-dap : C++ windows - 01
    目标用做C++编译器尽量不要扩展其它功能python是避免不了,所以才安装的。1.1下载安装https://mirror.tuna.tsinghua.edu.cn/msys2/distrib/msys2-x86_64-latest.exe安装路径:C:\gnu\msys641.2mingw64.exe使用这个:C:\gnu\msys64\mingw64.exe1.3安装程序:pac......
  • mingw64 + nvim + coc.nvim + nvim-dap : C++ windows - 02
    2.1命令行工具https://github.com/sharkdp/fdhttps://github.com/junegunn/fzfhttps://github.com/BurntSushi/ripgrephttps://github.com/tree-sitter/tree-sitterC:\gnu\cli\fd.exeC:\gnu\cli\fzf.exeC:\gnu\cli\rg.exeC:\gnu\cli\tree-sitter.exe添加到path......
  • mingw64 + nvim + coc.nvim + nvim-dap : C++ windows - 03
    3.1cclshttps://github.com/MaskRay/ccls/wiki/Build在msys中:pacman-S--noconfirmmingw-w64-x86_64-clangmingw-w64-x86_64-clang-tools-extramingw64/mingw-w64-x86_64-pollymingw-w64-x86_64-cmakemingw-w64-x86_64-jqmingw-w64-x86_64-ninjamingw-w64-x86_64-n......
  • mingw64 + nvim + coc.nvim + nvim-dap : C++ windows - 04
    4.1init.vim将init.vim放置到下面:echostdpath('config')~\AppData\Local\nvim4.2plughttps://github.com/junegunn/vim-plug将plug.vim放置到下面~\AppData\Local\nvim-data\site\autoload4.3:PlugInstall4.3.1网络问题gitproxy4.3.2process4.3......
  • mingw64 + nvim + coc.nvim + nvim-dap : C++ windows - 05
    PSC:\Users\dev\Desktop\cpp>cd.\build\PSC:\Users\dev\Desktop\cpp\build>cmake..-DCMAKE_BUILD_TYPE=Debug--Buildingfor:Ninja--TheCcompileridentificationisGNU12.2.0--TheCXXcompileridentificationisGNU12.2.0--Detect......
  • coc-nvim
    配置文件:CocConfig~/.config/nvim/coc-settings.jsoncoc-settings.json{"languageserver":{"ccls":{"command":"ccls","filetypes":["c","cpp","hpp","......
  • nvim-dap
    localdap=require("dap")localcmd=os.getenv('HOME')..'/tool/debug/codelldb/adapter/codelldb'dap.adapters.codelldb=function(on_adapter)--Thisasksthesystemforafreeportlocaltcp=vim.loop.new_tcp()tc......