配置nvim

配置文件位置~/.config/nvim/init.lua,如果是Windows系统~/Appdata/Local/nvim/init.lua

├── init.lua
└── lua
    ├── map.lua
    ├── options.lua
    └── plugins.lua

init.lua只需要用require即可,剩下的都在lua目录下

# kun @ DESKTOP-CH7NVN2 in /c/Users/kun/AppData/Local/nvim [15:46:39]
$ cat init.lua
require('map')
require('options')
require('plugins')

安装lazy.nvim

用于管理插件,在lua目录下创建如下文件

# kun @ DESKTOP-CH7NVN2 in /c/Users/kun/AppData/Local/nvim/lua [15:44:46]
$ cat plugins.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or 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({
    "Yggdroot/LeaderF"
})

在nvim界面输入:Lazy能看到下载完成就行了

Leaderf插件

实际上面已经在lazy中添加了,这里只讲一下Windows上安装过程
需要python3支持,msys2环境安装mingw-w64-x86_64-python-pynvim
因为msys2用的是msys2环境,而不是mingw64,所以这里导入mingw64的路径才能让leaderf找到python3
export PATH="/mingw64/bin":$PATH
需要为Leaderf安装ctags,pacman -S ctags
快捷键vim.keymap.set("n", "<C-p>", ":LeaderfFile<enter>", {noremap = true, silent = true})

快捷键配置

# kun @ DESKTOP-CH7NVN2 in /c/Users/kun/AppData/Local/nvim/lua [15:49:12]
$ cat map.lua
vim.g.mapleader = ","
vim.keymap.set("n", "<C-p>", ":LeaderfFile<enter>", {noremap = true, silent = true})
vim.keymap.set("n", "<leader>f", ":LeaderfFunction<enter>", {noremap = true, silent = true})
vim.keymap.set("n", "<leader>o", ":LeaderfBufTag<enter>", {noremap = true, silent = true})
vim.keymap.set("n", "<F2>", ":NERDTreeToggle<enter>", {noremap = true, silent = true}

vim自身配置

# kun @ DESKTOP-CH7NVN2 in /c/Users/kun/AppData/Local/nvim/lua [15:48:50]
$ cat 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 = false -- add numbers to each line on the left side
vim.opt.cursorline = false -- 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.paste = true
vim.opt.wrap = false

-- Searching
vim.opt.incsearch = true -- search as characters are entered
vim.opt.hlsearch = true -- 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

-- 打开log文件和txt文件使用c语言的高亮模式
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
    pattern = {"*.log", "*.txt"},
    command = "set syn=c",
})

-- nerdtree退出后关闭
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
    pattern = {"*"},
    command = 'if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif',
})
posted @ 2024-05-13 15:52  feipeng8848  阅读(69)  评论(0编辑  收藏  举报