跳至主要內容

neovim使用

CentosvimCentosvim大约 2 分钟约 732 字全民制作人ikun

neovim使用

安装

官网:https://neovim.io/open in new window

教程:https://www.mintimate.cn/2023/01/10/guideForLunarvim/open in new window

centos7安装nvim:

wget https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-linux64.tar.gz

解压,然后链接:

/root/tools/nvim-linux64/bin/nvim这是我的位置

ln -s /root/tools/nvim-linux64/bin/nvim /bin/nvim

插件

开箱即用:https://github.com/nvim-lua/kickstart.nvimopen in new window

git clone https://github.com/nvim-lua/kickstart.nvim.git "${XDG_CONFIG_HOME:-$HOME/.config}"/nvim

lazy

nvim-telescope:https://github.com/nvim-telescope/telescope.nvim,需要安装:ripgrepopen in new window

LSP:

mason:https://github.com/williamboman/mason.nvimopen in new window

pyright

neovim/nvim-lspconfig

一些使用方法:

用法快捷键说明
横向切屏control+w+v
移动到右侧屏幕control+w+l
移动到左侧屏幕control+w+h

安装(MacOS)

brew install neovim

配置

/.config/下创建一个nvim文件夹

再创建一个init.lua进行配置

一些简单基本配置:

local set = vim.o
-- 设置行号
set.number=true
-- 设置相对行号
set.relativenumber=true
-- 设置vim剪切板和系统剪切板同步
set.clipboard="unnamed"
-- 在 copy 后高亮
vim.api.nvim_create_autocmd({ "TextYankPost" }, {
	pattern = { "*" },
	callback = function()
		vim.highlight.on_yank({
			timeout = 300,
		})
	end,
})

绑定一些快捷键:

-- 切换屏幕 ctrl + (l/h/j/k) 快捷键设置
local opt={noremap=true,silent=true}
vim.g.mapleader=" " -- Leader为空格
vim.keymap.set("n","<C-l>","<C-w>l",opt) -- ctrl+w+l --> 替换为ctrl+l ,移动到右侧的屏幕
vim.keymap.set("n","<C-h>","<C-w>h",opt) -- ctrl+w+h --> 替换为ctrl+h ,移动到右侧的屏幕
vim.keymap.set("n","<C-l>","<C-w>l",opt) -- ctrl+w+l --> 替换为ctrl+l ,移动到左侧的屏幕
vim.keymap.set("n","<C-j>","<C-w>j",opt) -- ctrl+w+j --> 替换为ctrl+j ,移动到下侧的屏幕
vim.keymap.set("n","<C-k>","<C-w>k",opt) -- ctrl+w+k --> 替换为ctrl+k ,移动到上侧的屏幕
vim.keymap.set("n","<Leader>v","<C-w>v",opt) -- ctrl+w+k --> 替换为Leader+v ,新开一个终端编辑器
vim.keymap.set("n","<Leader>s","<C-w>s",opt) -- ctrl+w+s --> 替换为Leader+s ,向下一个终端编辑器


-- https://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- 相对行号的跳转
vim.keymap.set("n", "j", [[v:count ? 'j' : 'gj']], { noremap = true, expr = true })
vim.keymap.set("n", "k", [[v:count ? 'k' : 'gk']], { noremap = true, expr = true })

LazyVim:

https://github.com/LazyVim/LazyVimopen in new window

https://github.com/folke/lazy.nvimopen in new window

https://github.com/RRethy/base16-nvimopen in new window

-- lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
	{
		"RRethy/nvim-base16",
		lazy = true,
	},
})

-- 更换主题 ashes snazzy  blueforest
vim.cmd.colorscheme("base16-blueforest")

插件:

  • ripgrep
  • telescope
  • lazy load

LSP code completion:

  • Mason
  • lspconfig
  • mason-lspconfig
  • nvim-cmp

ripgrep:https://github.com/BurntSushi/ripgrepopen in new window

telescopre:https://github.com/nvim-telescope/telescope.nvimopen in new window

用于文件搜索

vim.keymap.set("n", "<Leader>[", "<C-o>", opt) -- Ctrl+o --> 替换为Leader+[ ,返回上一页面
vim.keymap.set("n", "<Leader>]", "<C-i>", opt) -- Ctrl+i --> 替换为Leader+] ,返回下一页面


{
		 cmd="Telescope", -- 懒加载
		 keys= {
 			{ "<leader>p", ":Telescope find_files<CR>", desc = "find files" }, -- 搜索文件
			{ "<leader>P", ":Telescope live_grep<CR>", desc = "grep file" }, --搜索文本
			{ "<leader>rs", ":Telescope resume<CR>", desc = "resume" },
			{ "<leader>q", ":Telescope oldfiles<CR>", desc = "oldfiles" }, --旧文件
		 },
    		'nvim-telescope/telescope.nvim', tag = '0.1.8',
      		 dependencies = { 'nvim-lua/plenary.nvim' }
    	}

Mason:https://github.com/williamboman/mason.nvimopen in new window

pyright:https://github.com/microsoft/pyrightopen in new window

用Mason装pyright

MasonInstall pyright

nvim-lspconfig:https://github.com/neovim/nvim-lspconfigopen in new window

mason-lspconfig:https://github.com/williamboman/mason-lspconfig.nvimopen in new window

用Mason装Lua-language-server

MasonInstall Lua-language-server

null-ls-format:https://github.com/jose-elias-alvarez/null-ls.nvimopen in new window

nvim-cmp:https://github.com/hrsh7th/nvim-cmpopen in new window

vim-fugitive:https://github.com/tpope/vim-fugitiveopen in new window

gitsigns.vim:https://github.com/lewis6991/gitsigns.nvimopen in new window

vim-rhubarb

neovim与Tmux的联动:

https://github.com/numToStr/Navigator.nvimopen in new window

向右打开一个终端:ctrl+5

退出:control+d

移动:ctrl+l移动到右侧termial

nerd tree: https://github.com/preservim/nerdtreeopen in new window

https://mokacoding.com/open in new window

https://github.com/Xuyuanp/nerdtree-git-pluginopen in new window

https://github.com/ryanoasis/vim-deviconsopen in new window

https://github.com/folke/persistence.nvimopen in new window

https://github.com/nvim-treesitter/nvim-treesitteropen in new window

上次编辑于:
贡献者: yunfeidog