【Linux】Nvim

安装

下载包体

https://github.com/neovim/neovim/releases

安装

1
2
3
4
5
tar -zxvf neovim-0.8.0.tar.gz
# 解压后就可以直接用了,十分方便
./nvim-linux64/bin/nvim
# 可以将其放在/usr/local下,然后创建软链接
sudo ln -s /usr/local/nvim/bin/nvim /usr/bin/nvim

配置

创建配置文件

默认配置文件路径:
1
2
3
4
# 创建配置文件夹
mkdir ~/.config/nvim
# 创建配置文件
nvim ~/.config/nvim/init.vim
自定义配置文件的路径:
  1. 创建配置文件
1
2
3
4
5
cd /usr/local/nvim-linux64
mkdir ./config
mkdir ./config/nvim
# 创建配置文件
nvim ./config/nvim/init.vim

  1. nvim /etc/profile修改环境变量
1
2
3
# nvim配置文件
export XDG_CONFIG_HOME=/usr/local/nvim-linux64/config
export XDG_DATA_HOME=/usr/local/nvim-linux64/config

  1. 重载配置文件
1
source /etc/profile

基础配置

1
2
3
4
5
6
7
" 基础键位映射
imap jk <Esc>
nmap <space> :

" 显示相对行
set relativenumber
set number

安装vim-plug插件管理

前面不是命名了全局变量XDG_DATA_HOME吗,这个时候就用上了

plug.vim文件放在以下路径

windows: ./nvim-win64/config/nvim-data/site/autoload/

linux: ./nvim-linux64/config/nvim/site/autoload/

安装方法

  • 在nvim窗口下输入:PlugInstall
  • 在linux终端输入nvim +PlugInstall +qall

第一种安装方法可能会因为网络的原因安装失败,这时就可以使用第二种方法

如果出现Finishing … Done! 和 Already installed 就说明安装成功了

后面安装的插件位置会放在~/vim/plugged文件夹中

插件网站


我的配置

热键

imap 将输入模式的key1映射到key2(key1和key2都有key2的功能)
nmap 将命令模式的key1映射到key2上

特殊键位

alt + q
Ctrl + q
esc键
空格

其他设置

set number 显示行号(或者set nu)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
" 基础键位映射
imap jk <Esc>
nmap <space> :

" 显示相对行
set relativenumber
set number

" /的搜索忽略大小写
set ignorecase


call plug#begin()

Plug 'scrooloose/nerdtree'
Plug 'rkulla/pydiction'

call plug#end()




" nerdtree插件绑定
" 使用ctrl+e打开关闭
map <silent> <C-e> :NERDTreeToggle<CR>

" 将光标移动到NERDTree中
nnoremap <C-w> <C-w>w

" vim启动时自动显示NERDTree
"auto VimEnter * NERDTree

" 打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|endif

" 当NERTreed为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" 设定NERTree视窗大小
"let g:NERDTreeWinSize=30

" 修改树的显示图标
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'

" 隐藏文件
let NERDTreeIgnore = ['\.pyc$', '__pycache__']

" 是否显示行号
"let g:NERDTreeShowLineNumbers=1

" 是否显示隐藏文件 NERDTree自带的快捷键Ctrl+I,大写I
let g:NERDTreeHidden=0



" pydiction插件 python补全
filetype plugin on
let g:pydiction_location = '$XDG_CONFIG_HOME\\nvim-data\\plugged\\pydiction\\complete-dict'