Vim

neovim

更现代化的vim https://github.com/neovim/neovim

安装

# apt安装的版本太低了,最好去官网下载 https://github.com/neovim/neovim

配置

lunarvim

一个基于neovim的IDE层,是独立于安装好的neovim的,一个工具 https://github.com/LunarVim/LunarVim 安装:

# linux
LV_BRANCH='release-1.4/neovim-0.9' bash <(curl -s https://raw.githubusercontent.com/LunarVim/LunarVim/release-1.4/neovim-0.9/utils/installer/install.sh)
# windows 首先需要安装powershell7+
# https://github.com/PowerShell/PowerShell/releases/download/v7.5.0/PowerShell-7.5.0-win-x64.msi 
# 随后执行
pwsh -c "`$LV_BRANCH='release-1.4/neovim-0.9'; iwr https://raw.githubusercontent.com/LunarVim/LunarVim/release-1.4/neovim-0.9/utils/installer/install.ps1 -UseBasicParsing | iex"

安装带icon的字体:

# 地址:https://github.com/ryanoasis/nerd-fonts
# 找到想要的字体,然后修改你使用的terminal软件的字体就行了。

卸载:

bash ~/.local/share/lunarvim/lvim/utils/installer/uninstall.sh

使用:

lvim .

配置剪贴板

# Linux下:
sudo apt install xclip
# 随后配置~/.config/lvim/config.luar
vim.opt.clipboard:append { 'unnamedplus' }
vim.g.clipboard = {
  name = 'xclip',
  copy = {
    ['+'] = 'xclip -selection clipboard',
    ['*'] = 'xclip -selection primary',
  },
  paste = {
    ['+'] = 'xclip -selection clipboard -o',
    ['*'] = 'xclip -selection primary -o',
  },
  cache_enabled = 1,
}

# Windows WSL中
# 下载win32yank https://github.com/equalsraf/win32yank
# 移动到/usr/local/bin 然后配置
vim.opt.clipboard:append { 'unnamedplus' }
vim.g.clipboard = {
  name = 'win32-clipboard',
  copy = {
    ['+'] = 'win32yank.exe -i',
    ['*'] = 'win32yank.exe -i',
  },
  paste = {
    ['+'] = 'win32yank.exe -o',
    ['*'] = 'win32yank.exe -o',
  },
  cache_enabled = 1,
}

覆盖vim

  1. 常规用户可以直接:
    # 常规用户可以直接
    alias vim=lvim
  2. 对于sudo,在/usr/local/bin/vim中增加脚本
    #!/bin/bash
    # 检查当前用户是否为 root
    if [ "$EUID" -eq 0 ]; then
        # 如果是 root (比如 sudo 调用的),则执行 lvim
        exec /root/.local/bin/lvim "$@"
    else
        # 如果是普通用户,执行系统自带的 vim
        # 这里写系统 vim 的绝对路径,通常是 /usr/bin/vim
        exec /usr/bin/vim "$@"
    fi

快捷键

# 移动行: alt-j alt-k
# 移动窗口:ctrl+w hjkl

# nvim-tree快捷键见:https://github.com/nvim-tree/nvim-tree.lua/blob/master/doc/nvim-tree-lua.txt