neovim使用
neovim使用
安装
教程:https://www.mintimate.cn/2023/01/10/guideForLunarvim/
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.nvim
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,需要安装:ripgrep
LSP:
mason:https://github.com/williamboman/mason.nvim
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/LazyVim
https://github.com/folke/lazy.nvim
https://github.com/RRethy/base16-nvim
-- 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/ripgrep
telescopre:https://github.com/nvim-telescope/telescope.nvim
用于文件搜索
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.nvim
pyright:https://github.com/microsoft/pyright
用Mason装pyright
MasonInstall pyright
nvim-lspconfig:https://github.com/neovim/nvim-lspconfig
mason-lspconfig:https://github.com/williamboman/mason-lspconfig.nvim
用Mason装Lua-language-server
MasonInstall Lua-language-server
null-ls-format:https://github.com/jose-elias-alvarez/null-ls.nvim
nvim-cmp:https://github.com/hrsh7th/nvim-cmp
vim-fugitive:https://github.com/tpope/vim-fugitive
gitsigns.vim:https://github.com/lewis6991/gitsigns.nvim
vim-rhubarb
neovim与Tmux的联动:
https://github.com/numToStr/Navigator.nvim
向右打开一个终端:ctrl+5
退出:control+d
移动:ctrl+l
移动到右侧termial
nerd tree: https://github.com/preservim/nerdtree
https://github.com/Xuyuanp/nerdtree-git-plugin
https://github.com/ryanoasis/vim-devicons