NeoVim配置文件基本的

2024-05-11 17:52
文章标签 基本 配置文件 neovim

本文主要是介绍NeoVim配置文件基本的,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

init.lua 文件

require('options') 
require('keymaps')
require('plugins')
require('colorscheme')
require('lsp')-- 插件
require("config.lualine")
require("config.nvim-tree")
require("config.treesitter")

~\lua\plugins.lua 文件

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) thenvim.fn.system({"git","clone","--filter=blob:none","https://github.com/folke/lazy.nvim.git","--branch=stable", -- latest stable releaselazypath,})
end
vim.opt.rtp:prepend(lazypath)require("lazy").setup({-- LSP manager"williamboman/mason.nvim","williamboman/mason-lspconfig.nvim","neovim/nvim-lspconfig",-- Vscode-like pictograms{"onsails/lspkind.nvim",event = { "VimEnter" },},-- Auto-completion engine{"hrsh7th/nvim-cmp",dependencies = {"lspkind.nvim","hrsh7th/cmp-nvim-lsp", -- lsp auto-completion"hrsh7th/cmp-buffer", -- buffer auto-completion"hrsh7th/cmp-path", -- path auto-completion"hrsh7th/cmp-cmdline", -- cmdline auto-completion},config = function()require("config.nvim-cmp")end,},-- Code snippet engine{"L3MON4D3/LuaSnip",version = "v2.*",},"navarasu/onedark.nvim","nvim-lualine/lualine.nvim",  -- 状态栏"nvim-tree/nvim-tree.lua",  -- 文档树"nvim-tree/nvim-web-devicons", -- 文档树图标"nvim-treesitter/nvim-treesitter", -- 语法高亮
})

~\lua\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-- 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-- UI config
vim.opt.number = true -- show absolute number
vim.opt.relativenumber = 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-- Searching
vim.opt.incsearch = true -- search as characters are entered
vim.opt.hlsearch = false -- do not 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

~\lua\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 installedensure_installed = { "lua_ls", "clangd" },
})-- 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 functionslocal 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,-- Only request null-ls for formattingfilter = function(client)return client.name == "null-ls"end,})end, bufopts)
end-- How to add a LSP for a specific language?
-- 1. Use `:Mason` to install the corresponding LSP.
-- 2. Add configuration below.
lspconfig.gopls.setup({on_attach = on_attach,
})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` globalglobals = { "vim" },},workspace = {-- Make the server aware of Neovim runtime fileslibrary = vim.api.nvim_get_runtime_file("", true),},-- Do not send telemetry data containing a randomized but unique identifiertelemetry = {enable = false,},},},
})-- source: https://rust-analyzer.github.io/manual.html#nvim-lsp
lspconfig.clangd.setup({on_attach = on_attach,
})lspconfig.ocamllsp.setup({on_attach = on_attach,
})

~\lua\keymaps.lua 文件

-- define common options
local opts = {noremap = true, -- non-recursivesilent = true, -- do not show message
}-----------------
-- Normal mode --
------------------- 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)-- 插入模式
vim.keymap.set("i", "jk", "<ESC>")-- 可视模式
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")

~\lua\colorscheme.lua 文件

-- define your colorscheme here
local colorscheme = 'onedark'local is_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
if not is_ok thenvim.notify('colorscheme ' .. colorscheme .. ' not found!')return
end

~\lua\conifg\lualine.lua 文件

require('lualine').setup({options = {theme = 'onedark'}
})

~\lua\conifg\nvim-cmp.lua 文件

local has_words_before = function()unpack = unpack or table.unpacklocal 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
endlocal luasnip = require("luasnip")
local cmp = require("cmp")cmp.setup({snippet = {-- REQUIRED - you must specify a snippet engineexpand = 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 oneif cmp.visible() thencmp.select_next_item()elseif has_words_before() thencmp.complete()elsefallback()endend, { "i", "s" }), -- i - insert mode; s - select mode["<S-Tab>"] = cmp.mapping(function(fallback)if cmp.visible() thencmp.select_prev_item()elseif luasnip.jumpable( -1) thenluasnip.jump( -1)elsefallback()endend, { "i", "s" }),}),-- Let's configure the item's appearance-- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearanceformatting = {-- Set order from left to right-- kind: single letter indicating the type of completion-- abbr: abbreviation of "word"; when not empty it is used in the menu instead of "word"-- menu: extra text for the popup menu, displayed after "word" or "abbr"fields = { 'abbr', 'menu' },-- customize the appearance of the completion menuformat = function(entry, vim_item)vim_item.menu = ({nvim_lsp = '[Lsp]',luasnip = '[Luasnip]',buffer = '[File]',path = '[Path]',})[entry.source.name]return vim_itemend,},-- Set source precedencesources = 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})
})

~\lua\conifg\nvim-tree.lua 文件

-- 默认不开启nvim-tree
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1require("nvim-tree").setup()

~\lua\conifg\treesitter.lua 文件

require'nvim-treesitter.configs'.setup {-- 添加不同语言ensure_installed = { "vim", "vimdoc", "c", "cpp", "javascript", "json", "lua", "typescript", "tsx", "css", "markdown", "markdown_inline" }, -- one of "all" or a list of languageshighlight = { enable = true },indent = { enable = true },-- 不同括号颜色区分rainbow = {enable = true,extended_mode = true,max_file_lines = nil,}
}

这篇关于NeoVim配置文件基本的的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/980244

相关文章

一文带你搞懂Nginx中的配置文件

《一文带你搞懂Nginx中的配置文件》Nginx(发音为“engine-x”)是一款高性能的Web服务器、反向代理服务器和负载均衡器,广泛应用于全球各类网站和应用中,下面就跟随小编一起来了解下如何... 目录摘要一、Nginx 配置文件结构概述二、全局配置(Global Configuration)1. w

基本知识点

1、c++的输入加上ios::sync_with_stdio(false);  等价于 c的输入,读取速度会加快(但是在字符串的题里面和容易出现问题) 2、lower_bound()和upper_bound() iterator lower_bound( const key_type &key ): 返回一个迭代器,指向键值>= key的第一个元素。 iterator upper_bou

【IPV6从入门到起飞】5-1 IPV6+Home Assistant(搭建基本环境)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant #搭建基本环境 1 背景2 docker下载 hass3 创建容器4 浏览器访问 hass5 手机APP远程访问hass6 更多玩法 1 背景 既然电脑可以IPV6入站,手机流量可以访问IPV6网络的服务,为什么不在电脑搭建Home Assistant(hass),来控制你的设备呢?@智能家居 @万物互联

C 语言的基本数据类型

C 语言的基本数据类型 注:本文面向 C 语言初学者,如果你是熟手,那就不用看了。 有人问我,char、short、int、long、float、double 等这些关键字到底是什么意思,如果说他们是数据类型的话,那么为啥有这么多数据类型呢? 如果写了一句: int a; 那么执行的时候在内存中会有什么变化呢? 橡皮泥大家都玩过吧,一般你买橡皮泥的时候,店家会赠送一些模板。 上

FreeRTOS-基本介绍和移植STM32

FreeRTOS-基本介绍和STM32移植 一、裸机开发和操作系统开发介绍二、任务调度和任务状态介绍2.1 任务调度2.1.1 抢占式调度2.1.2 时间片调度 2.2 任务状态 三、FreeRTOS源码和移植STM323.1 FreeRTOS源码3.2 FreeRTOS移植STM323.2.1 代码移植3.2.2 时钟中断配置 一、裸机开发和操作系统开发介绍 裸机:前后台系

Java 多线程的基本方式

Java 多线程的基本方式 基础实现两种方式: 通过实现Callable 接口方式(可得到返回值):

web群集--nginx配置文件location匹配符的优先级顺序详解及验证

文章目录 前言优先级顺序优先级顺序(详解)1. 精确匹配(Exact Match)2. 正则表达式匹配(Regex Match)3. 前缀匹配(Prefix Match) 匹配规则的综合应用验证优先级 前言 location的作用 在 NGINX 中,location 指令用于定义如何处理特定的请求 URI。由于网站往往需要不同的处理方式来适应各种请求,NGINX 提供了多种匹

Java基础回顾系列-第一天-基本语法

基本语法 Java基础回顾系列-第一天-基本语法基础常识人机交互方式常用的DOS命令什么是计算机语言(编程语言) Java语言简介Java程序运行机制Java虚拟机(Java Virtual Machine)垃圾收集机制(Garbage Collection) Java语言的特点面向对象健壮性跨平台性 编写第一个Java程序什么是JDK, JRE下载及安装 JDK配置环境变量 pathHe

前端-06-eslint9大变样后,如何生成旧版本的.eslintrc.cjs配置文件

目录 问题解决办法 问题 最近在写一个vue3+ts的项目,看了尚硅谷的视频,到了配置eslintrc.cjs的时候我犯了难,因为eslint从9.0之后重大更新,跟以前完全不一样,但是我还是想用和老师一样的eslintrc.cjs文件,该怎么做呢? 视频链接:尚硅谷Vue项目实战硅谷甄选,vue3项目+TypeScript前端项目一套通关 解决办法 首先 eslint 要

Gradle的基本使用

新建一个项目后,在项目文件夹下创建build.gradle文件,并加入内容:       apply plugin: 'eclipse'。    然后在终端运行gradle eclipse即可构建eclipse IDE的开发环境。    gradle默认值:gradle有些目录是有默认值存在,建议项目的配置,承袭了maven的风格,如:         java的源码目录:src/mai