首页 > 其他分享 >NVIM 配置

NVIM 配置

时间:2024-01-14 21:13:35浏览次数:32  
标签:set -- 配置 vim keymap NVIM true nvim

大部分代码来自 https://martinlwx.github.io/zh-cn/config-neovim-from-scratch/

预先安装 git clang nvim 与 windows terminal。

找好 nerd font。

在 Appdata/Local/nvim/ 下新建以下结构。

│  init.lua
│
├─lua
│  │  colorscheme.lua
│  │  keymaps.lua
│  │  lsp.lua
│  │  options.lua
│  │  plugins.lua
│  │
│  └─config
│          cph.lua
│          gitsigns.lua
│          indent-blankline.lua
│          lualine.lua
│          mason-null-ls.lua
│          nvim-cmp.lua
│          nvim-tree.lua
│          toggleterm.lua
init.lua
-- load options
require('options')        


-- load keymappings
require('keymaps')


-- load Packervim
require('plugins')


-- Set colorscheme
require('colorscheme')


-- Set LSP
require('lsp')

options.lua
-- Hint: use `:h <option>` to figure out the meaning if needed
-- vim.opt.clipboard = 'unnamedplus' -- use system clipboard
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
vim.opt.mouse = 'a' -- allow the mouse to be used in Nvim

vim.cmd(':lan zh_CN.UTF-8')

-- Tab
vim.opt.tabstop = 4 -- number of visual spaces per TAB
--vim.opt.softtabstop = 4 -- number of spacesin tab when editing
vim.opt.shiftwidth = 4 -- insert 4 spaces on a tab
vim.opt.expandtab = true -- tabs are spaces, mainly because of python
vim.opt.cindent=true

-- UI config
vim.opt.number = true -- show absolute number
vim.opt.ruler = true -- add numbers to each line on the left side
-- vim.opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
vim.opt.splitbelow = true -- open new vertical split bottom
vim.opt.splitright = true -- open new horizontal splits right
vim.opt.termguicolors = true -- enabl 24-bit RGB color in the TUI
-- vim.opt.showmode = false -- we are experienced, wo don't need the "-- INSERT --" mode hint
vim.opt.autochdir=true
vim.opt.laststatus=2
--vim.opt.noswapfile=true
--vim.opt.noundofile=true
--vim.opt.nobackup=true
vim.opt.showmatch=true
vim.opt.backspace=indent,eol,start

-- Searching
--vim.opt.incsearch = true -- search as characters are entered
vim.opt.hlsearch = true -- do highlight matches
--vim.opt.ignorecase = true -- ignore case in searches by default
--vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered

-- for nvim-tree
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

keymaps.lua
-- define common options
local opts = {
    noremap = true, -- non-recursive
    silent = true, -- do not show message
}

-----------------
-- Normal mode --
-----------------

vim.keymap.set('n','<F9>','ggVG"+y',opts)

vim.keymap.set('i','{','{<CR>}<ESC>kA',opts)

vim.cmd('noremap <expr>0 col(\'.\') == 1 ? \'^\': \'0\'')

-- Hint: see `:h vim.map.set()`
-- Better window navigation
-- vim.keymap.set('n', '<C-h>', '<C-w>h', opts)
-- vim.keymap.set('n', '<C-j>', '<C-w>j', opts)
-- vim.keymap.set('n', '<C-k>', '<C-w>k', opts)
-- vim.keymap.set('n', '<C-l>', '<C-w>l', opts)

-- Resize with arrows
-- delta: 2 lines
-- vim.keymap.set('n', '<C-Up>', ':resize -2<CR>', opts)
-- vim.keymap.set('n', '<C-Down>', ':resize +2<CR>', opts)
-- vim.keymap.set('n', '<C-Left>', ':vertical resize -2<CR>', opts)
-- vim.keymap.set('n', '<C-Right>', ':vertical resize +2<CR>', opts)

-- for nvim-tree
-- default leader key: \
vim.keymap.set('n', '<leader>e', ':NvimTreeToggle<CR>', opts)

-----------------
-- Visual mode --
-----------------

-- Hint: start visual mode with the same area as the previous area and the same mode
--vim.keymap.set('v', '<', '<gv', opts)
--vim.keymap.set('v', '>', '>gv', opts)


colorscheme.lua
-- define your colorscheme here
local colorscheme = 'dracula'

local is_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
if not is_ok then
    vim.notify('colorscheme ' .. colorscheme .. ' not found!')
    return
end

plugins.lua
-----------------
-- Packer.nvim --
-----------------
-- Install Packer automatically if it's not installed(Bootstraping)
-- Hint: string concatenation is done by `..`
local ensure_packer = function()
    local fn = vim.fn
    local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
    if fn.empty(fn.glob(install_path)) > 0 then
        fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path })
        vim.cmd [[packadd packer.nvim]]
        return true
    end
    return false
end
local packer_bootstrap = ensure_packer()


-- Reload configurations if we modify plugins.lua
-- Hint
--     <afile> - replaced with the filename of the buffer being manipulated
vim.cmd([[
  augroup packer_user_config
    autocmd!
    autocmd BufWritePost plugins.lua source <afile> | PackerSync
  augroup end
]])


-- Install plugins here - `use ...`
-- Packer.nvim hints
--     after = string or list,           -- Specifies plugins to load before this plugin. See "sequencing" below
--     config = string or function,      -- Specifies code to run after this plugin is loaded
--     requires = string or list,        -- Specifies plugin dependencies. See "dependencies".
--     ft = string or list,              -- Specifies filetypes which load this plugin.
--     run = string, function, or table, -- Specify operations to be run after successful installs/updates of a plugin
return require('packer').startup(function(use)
        -- Packer can manage itself
        use 'wbthomason/packer.nvim'

        -- LSP manager
        use { 'williamboman/mason.nvim' }
        use { 'williamboman/mason-lspconfig.nvim' }
        use { 'neovim/nvim-lspconfig' }
        -- Add hooks to LSP to support Linter && Formatter
        use { 'nvim-lua/plenary.nvim' }
        use {
            'jay-babu/mason-null-ls.nvim',
            after = 'plenary.nvim',
            requires = { 'jose-elias-alvarez/null-ls.nvim' },
            config=[[require('config.mason-null-ls')]]
        }
        use {
            'xeluxee/competitest.nvim',
            requires = 'MunifTanjim/nui.nvim',
            config = [[require('config.cph')]]
        }
        -- Vscode-like pictograms
        use { 'onsails/lspkind.nvim', event = 'VimEnter' }

        -- Auto-completion engine
        -- Note:
        --     the default search path for `require` is ~/.config/nvim/lua
        --     use a `.` as a path seperator
        --     the suffix `.lua` is not needed
        use { 'hrsh7th/nvim-cmp', after = 'lspkind.nvim', config = [[require('config.nvim-cmp')]] }
        use { 'hrsh7th/cmp-nvim-lsp', after = 'nvim-cmp' }
        use { 'hrsh7th/cmp-buffer', after = 'nvim-cmp' } -- buffer auto-completion
        use { 'hrsh7th/cmp-path', after = 'nvim-cmp' } -- path auto-completion
        use { 'hrsh7th/cmp-cmdline', after = 'nvim-cmp' } -- cmdline auto-completion


        -- Code snippet engine
        use 'L3MON4D3/LuaSnip'
        use { 'saadparwaiz1/cmp_luasnip', after = { 'nvim-cmp', 'LuaSnip' } }

        -- Git integration
        use 'tpope/vim-fugitive'

        -- Git decorations
        use { 'lewis6991/gitsigns.nvim', config = [[require('config.gitsigns')]] }

        -- Autopairs: [], (), "", '', etc
        -- it relies on nvim-cmp
        --use {
        --    "windwp/nvim-autopairs",
        --    after = 'nvim-cmp',
        --    config = [[require('config.nvim-autopairs')]],
        --}

        -- Code comment helper
        --     1. `gcc` to comment a line
        --     2. select lines in visual mode and run `gc` to comment/uncomment lines
        use 'tpope/vim-commentary'

        -- Treesitter-integration
        --use {
        --    'nvim-treesitter/nvim-treesitter',
        --    run = function()
        --        local ts_update = require('nvim-treesitter.install').update({ with_sync = true })
        --        ts_update()
        --    end,
        --    config = [[require('config.nvim-treesitter')]],
        --}

        -- Show indentation and blankline
        use { 'lukas-reineke/indent-blankline.nvim', config = [[require('config.indent-blankline')]] }

        use 'Mofiqul/dracula.nvim'

        -- Status line
        use {
            'nvim-lualine/lualine.nvim',
            requires = { 'kyazdani42/nvim-web-devicons', opt = true },
            config = [[require('config.lualine')]],
        }

        -- Markdown support
        use { 'preservim/vim-markdown', ft = { 'markdown' } }

        -- Markdown previewer
        -- It require nodejs and yarn. Use homebrew to install first
        use {
            "iamcco/markdown-preview.nvim",
            run = "cd app && npm install",
            setup = function() vim.g.mkdp_filetypes = { "markdown" } end,
            ft = { "markdown" },
        }

        -- Smart indentation for Python
        use { "Vimjas/vim-python-pep8-indent", ft = { "python" } }

        -- File explorer
        use {
            'nvim-tree/nvim-tree.lua',
            requires = {
                'nvim-tree/nvim-web-devicons', -- optional, for file icons
            },
            config = [[require('config.nvim-tree')]]
        }

        -- Smart motion
        use {
            'phaazon/hop.nvim',
            branch = 'v2', -- optional but strongly recommended
            config = function()
                -- you can configure Hop the way you like here; see :h hop-config
                require'hop'.setup { keys = 'etovxqpdygfblzhckisuran' }
            end
        }

        -- Better terminal integration
        -- tag = string,                -- Specifies a git tag to use. Supports '*' for "latest tag"
        use { "akinsho/toggleterm.nvim", tag = '*', config = [[require('config.toggleterm')]] }

        -- Automatically set up your configuration after cloning packer.nvim
        -- Put this at the end after all plugins
        if packer_bootstrap then
            require('packer').sync()
        end
    end)

lsp.lua
-- Note: The order matters: mason -> mason-lspconfig -> lspconfig
require('mason').setup({
    ui = {
        icons = {
            package_installed = "✓",
            package_pending = "➜",
            package_uninstalled = "✗"
        }
    }
})

require('mason-lspconfig').setup({
    -- A list of servers to automatically install if they're not already installed
    ensure_installed = { 'lua_ls' },
})


-- Set different settings for different languages' LSP
-- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D
--     - the settings table is sent to the LSP
--     - on_attach: a lua callback function to run after LSP attaches to a given buffer
local lspconfig = require('lspconfig')

-- Customized on_attach function
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
    -- Enable completion triggered by <c-x><c-o>
    vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

    -- See `:help vim.lsp.*` for documentation on any of the below functions
    local bufopts = { noremap = true, silent = true, buffer = bufnr }
    vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
    vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
    vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
    vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
    vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
    vim.keymap.set('n', '<space>wl', function()
        print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
    end, bufopts)
    vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
    vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
    vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
    vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
    vim.keymap.set('n', '<space>f', function()
        vim.lsp.buf.format({
            async = true,
            filter = function (client)
                return client.name == "null-ls"
            end
        })
    end, bufopts)
end

-- Configure each language
-- How to add LSP for a specific language?
-- 1. use `:Mason` to install corresponding LSP
-- 2. add configuration below
lspconfig.lua_ls.setup {
    on_attach = on_attach,
    settings = {
        Lua = {
            runtime = {
                -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
                version = 'LuaJIT',
            },
            diagnostics = {
                -- Get the language server to recognize the `vim` global
                globals = { 'vim' },
            },
            workspace = {
                -- Make the server aware of Neovim runtime files
                library = vim.api.nvim_get_runtime_file("", true),
            },
            -- Do not send telemetry data containing a randomized but unique identifier
            telemetry = {
                enable = false,
            },
        },
    },
}

lspconfig.clangd.setup({
    cmd={
        "clangd",
        "--query-driver=\"D:\\Program Files\\TDM-GCC-64\\bin\\g++.exe\",\"D:\\Program Files\\TDM-GCC-64\\bin\\gcc.exe\""
    },
    on_attach = on_attach,
})

lualine.lua
local is_ok, lualine = pcall(require, "lualine")
if not is_ok then
	return
end

lualine.setup({
	options = {
		icons_enabled = true,
		theme = "material",
		component_separators = { left = "", right = "" },
		section_separators = { left = "", right = "" },
		disabled_filetypes = {
			statusline = {},
			winbar = {},
		},
		ignore_focus = {},
		always_divide_middle = true,
		globalstatus = false,
		refresh = {
			statusline = 1000,
			tabline = 1000,
			winbar = 1000,
		},
	},
	-- Lualine has sections as shown below.
	-- +-------------------------------------------------+
	-- | A | B | C                             X | Y | Z |
	-- +-------------------------------------------------+
	-- Each sections holds its components
	sections = {
		lualine_a = { "mode" },
		lualine_b = {
			"branch",
			"diff",
			"diagnostics",
		},
		lualine_c = {
			{
				"filename",
				file_status = true, -- Displays file status (readonly status, modified status)
				-- Path configurations
				-- 0: Just the filename
				-- 1: Relative path
				-- 2: Absolute path
				-- 3: Absolute path, with tilde as the home directory
				-- 4: Filename and parent dir, with tilde as the home directory
				path = 3,
				shorting_target = 40, -- Shortens path to leave 40 spaces in the window
			},
		},
		lualine_x = { "encoding", "filesize", "filetype" },
		lualine_y = { "progress" },
		lualine_z = { "location" },
	},
	inactive_sections = {
		lualine_a = {},
		lualine_b = {},
		lualine_c = { "filename" },
		lualine_x = { "location" },
		lualine_y = {},
		lualine_z = {},
	},
	tabline = {},
	winbar = {},
	inactive_winbar = {},
	extensions = {},
})

cph.lua
local is_ok, cph = pcall(require, "competitest")
if not is_ok then
	return
end

cph.setup({
	floating_border = "rounded",
	floating_border_highlight = "FloatBorder",
	picker_ui = {
		width = 0.2,
		height = 0.3,
		mappings = {
			focus_next = { "j", "<down>", "<Tab>" },
			focus_prev = { "k", "<up>", "<S-Tab>" },
			close = { "<esc>", "<C-c>", "q", "Q" },
			submit = { "<cr>" },
		},
	},
	editor_ui = {
		popup_width = 0.4,
		popup_height = 0.6,
		show_nu = true,
		show_rnu = false,
		normal_mode_mappings = {
			switch_window = { "<C-h>", "<C-l>", "<C-i>" },
			save_and_close = "<C-s>",
			cancel = { "q", "Q" },
		},
		insert_mode_mappings = {
			switch_window = { "<C-h>", "<C-l>", "<C-i>" },
			save_and_close = "<C-s>",
			cancel = "<C-q>",
		},
	},
	runner_ui = {
		interface = "popup",
		selector_show_nu = false,
		selector_show_rnu = false,
		show_nu = true,
		show_rnu = false,
		mappings = {
			run_again = "R",
			run_all_again = "<C-r>",
			kill = "K",
			kill_all = "<C-k>",
			view_input = { "i", "I" },
			view_output = { "a", "A" },
			view_stdout = { "o", "O" },
			view_stderr = { "e", "E" },
			toggle_diff = { "d", "D" },
			close = { "q", "Q" },
		},
		viewer = {
			width = 0.5,
			height = 0.5,
			show_nu = true,
			show_rnu = false,
			close_mappings = { "q", "Q" },
		},
	},
	popup_ui = {
		total_width = 0.8,
		total_height = 0.8,
		layout = {
			{ 4, "tc" },
			{ 5, { { 1, "so" }, { 1, "si" } } },
			{ 5, { { 1, "eo" }, { 1, "se" } } },
		},
	},
	split_ui = {
		position = "right",
		relative_to_editor = true,
		total_width = 0.3,
		vertical_layout = {
			{ 1, "tc" },
			{ 1, { { 1, "so" }, { 1, "eo" } } },
			{ 1, { { 1, "si" }, { 1, "se" } } },
		},
		total_height = 0.4,
		horizontal_layout = {
			{ 2, "tc" },
			{ 3, { { 1, "so" }, { 1, "si" } } },
			{ 3, { { 1, "eo" }, { 1, "se" } } },
		},
	},

	save_current_file = true,
	save_all_files = false,
	compile_directory = ".",
    compile_command = {
        cpp = {
            exec = "g++",
            args = {
                "-Wall", "$(FNAME)", "-o", "$(FNOEXT)",
                "-Wshadow", "-Wfloat-equal","-Wformat=2","-Wconversion","-lm",
                "-std=c++14","-Wno-unused-variable","-Wno-sign-compare",
                "-Wno-unused-but-set-variable",
                "-Wl,--stack=130000000","-fno-ms-extensions","-Wunused-result","-O2"
            }
        },
    },
	running_directory = ".",
	run_command = {
		cpp = { exec = "./$(FNOEXT)" },
		python = { exec = "python", args = { "$(FNAME)" } },
	},
	multiple_testing = -1,
	maximum_time = 5000,
	output_compare_method = "squish",
	view_output_diff = false,

	testcases_directory = ".",
	testcases_use_single_file = false,
	testcases_auto_detect_storage = true,
	testcases_single_file_format = "$(FNOEXT).testcases",
	testcases_input_file_format = "$(FNOEXT)_input$(TCNUM).txt",
	testcases_output_file_format = "$(FNOEXT)_output$(TCNUM).txt",

	companion_port = 27121,
	receive_print_message = true,
    template_file = {
        cpp = "D:/Program Files/cpeditor/cpp.cpp",
    },
	evaluate_template_modifiers = false,
	date_format = "%c",
	received_files_extension = "cpp",
	received_problems_path = "$(CWD)/$(PROBLEM).$(FEXT)",
	received_problems_prompt_path = true,
	received_contests_directory = "$(CWD)",
	received_contests_problems_path = "$(PROBLEM).$(FEXT)",
	received_contests_prompt_directory = true,
	received_contests_prompt_extension = true,
	open_received_problems = true,
	open_received_contests = true,
	replace_received_testcases = false,
})

local opts = {
    noremap = true, -- non-recursive
}

vim.keymap.set('n','<F12>',':CompetiTest run<CR>',opts)
vim.keymap.set('n','<F10>',':CompetiTest receive testcases<CR>',opts)

gitsigns.lua
local is_ok, gitsigns = pcall(require, 'gitsigns')
if not is_ok then
    return
end

gitsigns.setup {
    signs                        = {
        add          = { text = '│' },
        change       = { text = '│' },
        delete       = { text = '_' },
        topdelete    = { text = '‾' },
        changedelete = { text = '~' },
        untracked    = { text = '┆' },
    },
    signcolumn                   = true, -- Toggle with `:Gitsigns toggle_signs`
    numhl                        = false, -- Toggle with `:Gitsigns toggle_numhl`
    linehl                       = false, -- Toggle with `:Gitsigns toggle_linehl`
    word_diff                    = false, -- Toggle with `:Gitsigns toggle_word_diff`
    watch_gitdir                 = {
        interval = 1000,
        follow_files = true
    },
    attach_to_untracked          = true,
    current_line_blame           = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
    current_line_blame_opts      = {
        virt_text = true,
        virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
        delay = 1000,
        ignore_whitespace = false,
    },
    current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
    sign_priority                = 6,
    update_debounce              = 100,
    status_formatter             = nil, -- Use default
    max_file_length              = 40000, -- Disable if file is longer than this (in lines)
    preview_config               = {
        -- Options passed to nvim_open_win
        border = 'single',
        style = 'minimal',
        relative = 'cursor',
        row = 0,
        col = 1
    },
    yadm                         = {
        enable = false
    },
}

indent-blankline.lua
local is_ok, indent_blankline = pcall(require, "ibl")
if not is_ok then
	return
end

indent_blankline.setup()

mason-null-ls.lua
local mason_ok, mason = pcall(require, "mason")
if not mason_ok then
	return
end

mason.setup()

local null_ls_ok, null_ls = pcall(require, "null-ls")
if not null_ls_ok then
	return
end

local sources = {
	null_ls.builtins.formatting.black.with({ extra_args = { "--target-version", "py310" } }),
	null_ls.builtins.formatting.stylua,
}

null_ls.setup({
	debug = false,
	log_level = "warn",
	update_in_insert = false,
	sources = sources,
})

local mason_null_ls_ok, mason_null_ls = pcall(require, "mason-null-ls")
if not mason_null_ls_ok then
	return
end

mason_null_ls.setup({
	-- A list of sources to install if they're not already installed.
	-- This setting has no relation with the `automatic_installation` setting.
	ensure_installed = {
		"clangd",
		"black",
		"stylua"
	},
	automatic_installation = false,
	-- Sources found installed in mason will automatically be setup for null-ls.
	automatic_setup = true,
	handlers = {},
})

nvim-cmp.lua
local luasnip_ok, luasnip = pcall(require, "luasnip")
local cmp_ok, cmp = pcall(require, "cmp")
local lspkind_ok, lspkind = pcall(require, "lspkind")

if not luasnip_ok or not cmp_ok or not lspkind_ok then
	return
end

local has_words_before = function()
	unpack = unpack or table.unpack
	local line, col = unpack(vim.api.nvim_win_get_cursor(0))
	return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

cmp.setup({
	snippet = {
		-- REQUIRED - you must specify a snippet engine
		expand = function(args)
			require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
		end,
	},
	mapping = cmp.mapping.preset.insert({
		-- Use <C-b/f> to scroll the docs
		["<C-b>"] = cmp.mapping.scroll_docs(-4),
		["<C-f>"] = cmp.mapping.scroll_docs(4),
		-- Use <C-k/j> to switch in items
		["<C-k>"] = cmp.mapping.select_prev_item(),
		["<C-j>"] = cmp.mapping.select_next_item(),
		-- Use <CR>(Enter) to confirm selection
		-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
		["<CR>"] = cmp.mapping.confirm({ select = true }),

		-- A super tab
		-- sourc: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
		["<Tab>"] = cmp.mapping(function(fallback)
			-- Hint: if the completion menu is visible select next one
			if cmp.visible() then
				cmp.select_next_item()
			elseif luasnip.expand_or_locally_jumpable() then
				-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
				-- they way you will only jump inside the snippet region
				luasnip.expand_or_jump()
			elseif has_words_before() then
				cmp.complete()
			else
				fallback()
			end
		end, { "i", "s" }), -- i - insert mode; s - select mode
		["<S-Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_prev_item()
			elseif luasnip.jumpable(-1) then
				luasnip.jump(-1)
			else
				fallback()
			end
		end, { "i", "s" }),
	}),
	-- Let's configure the item's appearance
	-- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance
	formatting = {
		-- customize the appearance of the completion menu
		format = lspkind.cmp_format({
			-- show only symbol annotations
			mode = "symbol_text",
			-- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
			maxwidth = 100,
			-- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
			ellipsis_char = "...",

			-- The function below will be called before any actual modifications from lspkind
			-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
			before = function(entry, vim_item)
				vim_item.menu = ({
					nvim_lsp = "[Lsp]",
					luasnip = "[Luasnip]",
					buffer = "[File]",
					path = "[Path]",
				})[entry.source.name]
				return vim_item
			end,
		}),
	},
	-- Set source precedence
	sources = cmp.config.sources({
		{ name = "nvim_lsp" }, -- For nvim-lsp
		{ name = "luasnip" }, -- For luasnip user
		{ name = "buffer" }, -- For buffer word completion
		{ name = "path" }, -- For path completion
	}),
})

-- 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" },
	}),
})

nvim-tree.lua
local is_ok, nvim_tree = pcall(require, "nvim-tree")
if not is_ok then
	return
end

--
-- This function has been generated from your
--   view.mappings.list
--   view.mappings.custom_only
--   remove_keymaps
--
-- You should add this function to your configuration and set on_attach = on_attach in the nvim-tree setup call.
--
-- Although care was taken to ensure correctness and completeness, your review is required.
--
-- Please check for the following issues in auto generated content:
--   "Mappings removed" is as you expect
--   "Mappings migrated" are correct
--
-- Please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach for assistance in migrating.
--

local function on_attach(bufnr)
	local api = require("nvim-tree.api")

	local function opts(desc)
		return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
	end

	-- Default mappings. Feel free to modify or remove as you wish.
	--
	-- BEGIN_DEFAULT_ON_ATTACH
	vim.keymap.set("n", "<C-]>", api.tree.change_root_to_node, opts("CD"))
	vim.keymap.set("n", "<C-e>", api.node.open.replace_tree_buffer, opts("Open: In Place"))
	vim.keymap.set("n", "<C-k>", api.node.show_info_popup, opts("Info"))
	vim.keymap.set("n", "<C-r>", api.fs.rename_sub, opts("Rename: Omit Filename"))
	vim.keymap.set("n", "<C-t>", api.node.open.tab, opts("Open: New Tab"))
	vim.keymap.set("n", "<C-v>", api.node.open.vertical, opts("Open: Vertical Split"))
	vim.keymap.set("n", "<C-x>", api.node.open.horizontal, opts("Open: Horizontal Split"))
	vim.keymap.set("n", "<BS>", api.node.navigate.parent_close, opts("Close Directory"))
	vim.keymap.set("n", "<CR>", api.node.open.edit, opts("Open"))
	vim.keymap.set("n", "<Tab>", api.node.open.preview, opts("Open Preview"))
	vim.keymap.set("n", ">", api.node.navigate.sibling.next, opts("Next Sibling"))
	vim.keymap.set("n", "<", api.node.navigate.sibling.prev, opts("Previous Sibling"))
	vim.keymap.set("n", ".", api.node.run.cmd, opts("Run Command"))
	vim.keymap.set("n", "-", api.tree.change_root_to_parent, opts("Up"))
	vim.keymap.set("n", "a", api.fs.create, opts("Create"))
	vim.keymap.set("n", "bmv", api.marks.bulk.move, opts("Move Bookmarked"))
	vim.keymap.set("n", "B", api.tree.toggle_no_buffer_filter, opts("Toggle No Buffer"))
	vim.keymap.set("n", "c", api.fs.copy.node, opts("Copy"))
	vim.keymap.set("n", "C", api.tree.toggle_git_clean_filter, opts("Toggle Git Clean"))
	vim.keymap.set("n", "[c", api.node.navigate.git.prev, opts("Prev Git"))
	vim.keymap.set("n", "]c", api.node.navigate.git.next, opts("Next Git"))
	vim.keymap.set("n", "d", api.fs.remove, opts("Delete"))
	vim.keymap.set("n", "D", api.fs.trash, opts("Trash"))
	vim.keymap.set("n", "E", api.tree.expand_all, opts("Expand All"))
	vim.keymap.set("n", "e", api.fs.rename_basename, opts("Rename: Basename"))
	vim.keymap.set("n", "]e", api.node.navigate.diagnostics.next, opts("Next Diagnostic"))
	vim.keymap.set("n", "[e", api.node.navigate.diagnostics.prev, opts("Prev Diagnostic"))
	vim.keymap.set("n", "F", api.live_filter.clear, opts("Clean Filter"))
	vim.keymap.set("n", "f", api.live_filter.start, opts("Filter"))
	vim.keymap.set("n", "g?", api.tree.toggle_help, opts("Help"))
	vim.keymap.set("n", "gy", api.fs.copy.absolute_path, opts("Copy Absolute Path"))
	vim.keymap.set("n", "H", api.tree.toggle_hidden_filter, opts("Toggle Dotfiles"))
	vim.keymap.set("n", "I", api.tree.toggle_gitignore_filter, opts("Toggle Git Ignore"))
	vim.keymap.set("n", "J", api.node.navigate.sibling.last, opts("Last Sibling"))
	vim.keymap.set("n", "K", api.node.navigate.sibling.first, opts("First Sibling"))
	vim.keymap.set("n", "m", api.marks.toggle, opts("Toggle Bookmark"))
	vim.keymap.set("n", "o", api.node.open.edit, opts("Open"))
	vim.keymap.set("n", "O", api.node.open.no_window_picker, opts("Open: No Window Picker"))
	vim.keymap.set("n", "p", api.fs.paste, opts("Paste"))
	vim.keymap.set("n", "P", api.node.navigate.parent, opts("Parent Directory"))
	vim.keymap.set("n", "q", api.tree.close, opts("Close"))
	vim.keymap.set("n", "r", api.fs.rename, opts("Rename"))
	vim.keymap.set("n", "R", api.tree.reload, opts("Refresh"))
	vim.keymap.set("n", "s", api.node.run.system, opts("Run System"))
	vim.keymap.set("n", "S", api.tree.search_node, opts("Search"))
	vim.keymap.set("n", "U", api.tree.toggle_custom_filter, opts("Toggle Hidden"))
	vim.keymap.set("n", "W", api.tree.collapse_all, opts("Collapse"))
	vim.keymap.set("n", "x", api.fs.cut, opts("Cut"))
	vim.keymap.set("n", "y", api.fs.copy.filename, opts("Copy Name"))
	vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("Copy Relative Path"))
	vim.keymap.set("n", "<2-LeftMouse>", api.node.open.edit, opts("Open"))
	vim.keymap.set("n", "<2-RightMouse>", api.tree.change_root_to_node, opts("CD"))
	-- END_DEFAULT_ON_ATTACH

	-- Mappings migrated from view.mappings.list
	--
	-- You will need to insert "your code goes here" for any mappings with a custom action_cb
	vim.keymap.set("n", "u", api.tree.change_root_to_parent, opts("Up"))
	vim.keymap.set("n", "o", api.node.open.edit, opts("Open"))
	vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close Directory"))
	vim.keymap.set("n", "v", api.node.open.vertical, opts("Open: Vertical Split"))
end

-- Hint: :help nvim-tree-default-mappings
-- setup with some options
nvim_tree.setup({
	sort_by = "case_sensitive",
	on_attach = on_attach,
	renderer = {
		group_empty = true,
	},
	filters = {
		dotfiles = true,
	},
	diagnostics = {
		enable = true,
	},
})

toggleterm.lua
local is_ok, toggleterm = pcall(require, 'toggleterm')
if not is_ok then
    return
end

toggleterm.setup({
    size = 20,
    open_mapping = [[<C-\>]], --  How to open a new terminal
    hide_numbers = true, -- hide the number column in toggleterm buffers
    direction = 'float',
    close_on_exit = true, -- close the terminal window when the process exits
    shell = vim.o.shell, -- change the default shell
    shade_filetypes = {},
    float_opts = {
        -- The border key is *almost* the same as 'nvim_open_win'
        -- see :h nvim_open_win for details on borders however
        -- the 'curved' border is a custom border type
        -- not natively supported but implemented in this plugin.
        border = 'single',
        winblend = 0,
    },
})


-- define key mappints
--  t: terminal mode
function _G.set_terminal_keymaps()
    local opts = { noremap = true, buffer = 0 }
    -- Use <C-\> to toggle terminals when direction='float'
    vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
    vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
    -- We can use <C-h/j/k/l> to move cursor among windows(including terminal window)
    -- If we set direction='float', these key mappings wont' helpful
    vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
    vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
    vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
    vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
end

-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')


-- Toggleterm also exposes the `Terminal` class so that this can be used to create
-- custom terminals for showing terminal UIs like `lazygit`, `htop` etc.
local Terminal = require('toggleterm.terminal').Terminal

-- cmd = string -- command to execute when creating the terminal e.g. 'top'
local htop = Terminal:new({ cmd = 'htop', hidden = true })

function _HTOP_TOGGLE()
    htop:toggle()
end








:PackerInstall 一次安装好插件。

重启安装 mason clangd。网够好。

Appdata/Local/clangd/config.yaml
CompileFlags:
  Add: [--target=x86_64-pc-windows-gnu, -Wall, -Wshadow, -Wfloat-equal, -Wformat=2, -Wconversion, -std=c++14, -Wno-unused-variable, -Wno-sign-compare, -Wno-unused-but-set-variable, -fno-ms-extensions, -Wunused-result]

clang target 若要设置成 g++,可以 g++ -v 查看 target 再填入。

目前没有解决 Wformat 不报警告的问题。

当前快捷键:F9 全文复制,F10 开始 receive Competitive Companion,F12 开始运行。

nerd-tree 运行时占用过高,最好是别用。

标签:set,--,配置,vim,keymap,NVIM,true,nvim
From: https://www.cnblogs.com/Zaunese/p/17964163

相关文章

  • 利用PowerShell修改网络配置
    title:利用PowerShell修改网络配置date:2022-03-30categories:编程tags:-PowerShell-网络-Windows前言修改IP、网关、子网掩码、DNS等配置时需要打开网络配置器配置,有些麻烦。尤其是经常需要重复性操作时(例如去学校图书馆蹭网)。用PowerShell脚本自动修改,方便简单而......
  • 第六天:bash shell的配置文件
    一、按生效范围划分两类 1、全局配置:针对所有用户皆有效/etc/profile/etc/profile.d/*.sh/etc/bashrc2、个人配置:只针对特定用户有效 ~/.bash_profile~/.bashrc二、shell登录两种方式分类 1、交互式登录直接通过终端输入账号密......
  • Spring Boot3 系列:Spring Boot3 跨域配置 Cors
    目录什么是CORS?SpringBoot如何配置CORS?前端代码注解配置全局配置过滤器配置注意事项什么是CORS?CORS,全称是“跨源资源共享”(Cross-OriginResourceSharing),是一种Web应用程序的安全机制,用于控制不同源的资源之间的交互。在Web应用程序中,CORS定义了一种机制,通过该机制,浏览器能......
  • jmeter-配置元件&用户参数
    5.1.3.配置元件可以配置各种信息5.1.3.1配置全局参数-用户定义的变量在测试计划-》用户定义的变量中可以定义全局变量。在测试计划-》添加-》配置元件-》用户定义的变量中可以定义全局变量。还可以在线程组-》添加-》配置元件-》用户定义的变量中可以定义全局变量优先级:线......
  • CAN通信配置过滤器和使用三个邮箱发送
    RM比赛用的电机基本都使用CAN通信,但是一条CAN线上只用一个发送邮箱在挂在设备多的情况可能会导致发送不完,但其实完全可以把三个发送邮箱都用上。这里贴一下自己的CAN筛选器,接收以及发送的代码。完整的工程可以看我开源的飞机云台程序~项目代码开源地址:https://github.com/ittuann......
  • 如何在WSL中下载配置oh my posh美化终端
    官网地址Home|OhMyPosh其中包含了使用方法安装手册,主题分类,等一些列教学1、安装ohmyposhsudowgetsudowgethttps://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64-O/usr/local/bin/oh-my-poshsudochmod+x/usr/local/bin/oh......
  • .NET中轻松应用SQLite:零配置数据库引擎的完美指南
     SQLite是一种轻量级的嵌入式数据库引擎,它在.NET中被广泛使用。SQLite是一个零配置的数据库引擎,不需要服务器,可以直接在应用程序中使用。下面是一个简单的示例,演示如何在.NET中使用SQLite,并提供了常见的查询、增加、修改和删除功能。首先,你需要在项目中安装 System.D......
  • hyperf 3.1安装和配置php-zookeeper扩展
    Hyperf提供了分布式系统的外部化配置支持,默认适配了:由携程开源的 ctripcorp/apollo,由 hyperf/config-apollo 组件提供功能支持。阿里云提供的免费配置中心服务 应用配置管理(ACM,ApplicationConfigManager),由 hyperf/config-aliyun-acm 组件提供功能支持。ETCDNac......
  • .Net Core 系列: 集成 CORS跨域配置
    .NetCore系列:集成CORS跨域配置  目录什么是CORS?Asp.NetCore种如何配置CORS?CorsPolicyBuilder类详解注册以及使用策略三种方式EnableCors和DisableCors特性关于带证书与不带证书代码的实现跨源(cross-origin)不带请求证书(Credentials)跨源(cross-origi......
  • DreadHunger恐惧饥荒海上狼人杀服务器配置要求
    DreadHunger恐惧饥荒海上狼人杀服务器配置要求大家好我是艾西,在这几天DreadHunger恐惧饥荒海上狼人杀技术组对于客户端做了一些调整修复,对于之前开房间只能默认7777端口做出了调整。目前经过我自己的测试是可以完全设置成你自己想要的端口,官方客户端更新固定游戏端口的设置,改成随机......