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