NeoVim飞升过程

安装

Windows

macOS / OS X

Linux

Linux AppImage通用包

curl -LO https://github.com/neovim/neovim/releases/download/stable/nvim.appimage
chmod u+x nvim.appimage
./nvim.appimage

常见Linux发行版

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# python模块
yum install -y neovim python3-neovim
# 在较旧的版本上,可能需要python2-neovim
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt-get update
sudo apt-get install neovim

# python模块
sudo apt-get install python-dev python-pip python3-dev python3-pip
sudo apt-get install python-dev python-pip python3-dev
sudo apt-get install python3-setuptools
sudo easy_install3 pip

BSD (Unix)

更多产考官方wiki

美化飞升

若已经有vim的配置,可使用ln -s .vim/vimrc .config/nvim/init.vim与vim共用配置,可能有不兼容情况,尽量新建nvim ~/.config/nvim/init.vim

状态栏美化插件,需要安装powerline-fonts字体(https://github.com/powerline/fonts) pacman -S powerline-fonts

"                               _ ____    _   ___     ___           ____   ____
"   ___  ___  _ __  _   _ _ __ ( ) ___|  | \ | \ \   / (_)_ __ ___ |  _ \ / ___|
"  / _ \/ _ \| '_ \| | | | '_ \|/\___ \  |  \| |\ \ / /| | '_ ` _ \| |_) | |
" |  __/ (_) | | | | |_| | | | |  ___) | | |\  | \ V / | | | | | | |  _ <| |___
"  \___|\___/|_| |_|\__,_|_| |_| |____/  |_| \_|  \_/  |_|_| |_| |_|_| \_\\____|
"
"  =================================木He寸&eonun================================
"

" i 写入模式、i插入之前、I行首插入、a插入之后、A行尾插入、o下行插入、O上行插入、x 删除光标后一个字符
" <Operation(操作)> <Motion(动作)>
" d 剪切操作(剪切可看做删除), y 复制操作, p 粘贴操作, c 剪切后修改操作
" ← 左动作, → 右动作, 3← 3个左动作, b 选择光标开启到上一个词后的内容, i 指明光标在词中,当前词待操作, w 选择光标开始到下个词前的内容, iw 在当前词之间选择该, y3← 向右复制, f 查找动作

" ===
" >>>首次使用自动配置
" ===

" ==安装plug

if empty(glob('~/.config/nvim/autoload/plug.vim'))
	silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
		\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
	autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

" 保存vimrc时立即重新加载生效
autocmd BufWritePost $MYVIMRC source $MYVIMRC

" ===
" >>>基础配置
" ===START===


" 文件类型检测
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on

" 开启语法高亮
if !exists("g:syntax_on")
    syntax enable
endif

" txt文件按照wiki语法高亮
autocmd BufNewFile *.txt set ft=confluencewiki
autocmd BufEnter *.txt set ft=confluencewiki

" 恢复上次文件打开位置
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

" 打开是运行指令 取消上回搜索内容的高亮
exec "nohlsearch"

" ==
" >>Let
" ==START==

let mapleader=" "	" 将leader键(\键,类似于Windows键)换成空格(相当于空格键)
let &t_ut=''		" 矫正部分配色

" 不同模式下的光标样式
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"

" python解释器
"
"let g:python_host_prog='/usr/bin/python2'
"let g:python3_host_prog='/usr/bin/python3'

" ==END==
" >>let
" ==

" ==
" >>set
" ==START==
set nocompatible	" 不兼容 VI ,compatible为兼容(tab将不会变成空格)

set fileencodings=utf-8,gbk	" 写入文件时采用的编码类型
set termencoding=utf-8		" 输出到终端时采用的编码类型
set encoding=utf-8	" 缓存的文本、寄存器、Vim 脚本文件等

set number			" 显示行号	缩写: nu
set relativenumber	" 从当前行向前向后算行数
set cursorline		" 突出显示当前行	缩写: cul
"set cursorcolumn	" 突出显示当前列	缩写: cuc
set showmatch		" 显示括号匹配
set showcmd			" 显示指令
set laststatus=2	" 显示状态栏
set ruler			" 显示光标当前位置

set wrap			" 自动换行
set tw=0			" 防止自动分割行

"set expandtab		" 自动将制表符换成空格
set tabstop=4		" 制表符长度为4空格	缩写:ts
set shiftwidth=4	" 自动缩进长度为4空格
set autoindent		" 自动缩进
set cindent			" c格式自动缩进
set smartindent		" 遇右花括号 } 取消缩进的自动缩进

set wildmenu		" 命令补全
set autochdir       " 在当前目录下执行命令

set hlsearch		" 高亮显示搜索
set incsearch		" 动态高亮搜索"
set ignorecase		" 不区分大小写搜索
set smartcase		" 智能大小写搜索

set mouse=a			" 使用鼠标

set backspace=indent,eol,start	" 能退格到行尾

" ==END==
" >>>set
" ==

" ==
" >>键盘映射
" ==START==

" map 递归映射
" map a b
" map b c
" a映射为c

" nmap 普通模式下的递归映射"

" noremap 不递归映射
" noremap a b
" noremap b c
" a映射为b b映射为c 两个映射互不影响

" unmap 取消 map 的映射
" mapclear 取消所有 map 的映射

"noremap a b	" 将 a 映射为 b
"noremap A 5b	" 将 A 映射为 5b
"noremap = nzz	" 将 n 映射 =zz 	" 用 zz 将该行变成中心点
"noremap - Nzz	" 将 N 映射 -zz
noremap <LEADER><CR> :nohlsearch<CR>	" 将 <LEADER><CR> 映射为 :nohlsearch<CR> 用于快捷取消搜索高亮
noremap J 5j
noremap K 5k

" 复制到系统剪切板
"vnoremap Y :w !xclip -i -sel c<CR>	" 需要安装xclip  #sudo pacman -S xclip
vnoremap Y "+y		" 需要安装gvim   #sudo pacman -S gvim

" 打开vimrc文件
map MR :e $MYVIMRC<CR>

map s <nop>
map S :w<CR>	" 将 S 的指令映射为 :w<CR> 	 " <CR> 代表回车
map Q :q<CR>	" 将 Q 的指令映射为 :q<CR>
map <silent> <C-a> ggvG 	" Ctrl-A 选中所有内容
"map R :source $MYVIMRC<CR>		" 将 R 的指令映射成 重载vimrc配置
" 打开新文件
map <LEADER>s :e<Space>

map sk :set splitbelow<CR>:split<CR>		" 下分屏":e /文件路径 打开文件
map sj :set nosplitbelow<CR>:split<CR>		" 上分屏
map sl :set nosplitright<CR>:vsplit<CR>		" 右分屏
map sh :set splitright<CR>:vsplit<CR>		" 左分屏	

map sz <C-w>t<C-w>H 	" 竖向分屏换左右分屏
map ss <C-w>t<C-w>K		" 左右分屏换竖向分屏

map <LEADER>k <C-w>k	" 光标到上屏
map <LEADER>j <C-w>j	" 光标到下屏
map <LEADER>l <C-w>l	" 光标到右屏
map <LEADER>h <C-w>h	" 光标到左屏

map <up> :res +5<CR>				" 分屏线上移
map <down> :res -5<CR>				" 分屏线下移
map <left> :vertical resize+5<CR>	" 分屏线左移
map <right> :vertical resize-5<CR>	" 分屏线右移


map tn :tabe<CR>		" ta打开新选项卡
map th :-tabnext<CR>	" 到左边的选项卡
map tl :+tabnext<CR>	" 到右边的选项卡

" ==END==
" >>键盘映射
" ==

" ===END===
" >>>基础配置
" ===


" ===
" >>>插件安装
" ===START===

" 安装plug:
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

call plug#begin('~/.config/nvim/plugged')  " 启用plug安装
" 插件github项目地址为:https://github.com/ 加 '' 中的内容
" 如:https://github.com/vim-airline/vim-airline

" ===状态栏===
Plug 'vim-airline/vim-airline'	" 状态栏
Plug 'vim-airline/vim-airline-themes'	" 状态栏主题

" ===配色方案===
Plug 'lifepillar/vim-solarized8'		" solarized8主题
Plug 'ayu-theme/ayu-vim'				" ayu主题
Plug 'nathanaelkane/vim-indent-guides'	" 显示缩进级别

" ===目录树===
Plug 'scrooloose/nerdtree'				" 目录树,方便浏览当前目录下的文件
Plug 'Xuyuanp/nerdtree-git-plugin'      " 目录树git提示
Plug 'kien/ctrlp.vim'					" 适用于大规模项目文件的浏览

" ===自动化===
Plug 'neoclide/coc.nvim', {'branch': 'release'}		" 代码补全 需要vim >=8 或neovim
Plug 'vim-syntastic/syntastic'				" 错误语法提示

" ===历史===
Plug 'mbbill/undotree'					" 历史修改撤回

" ===文本===
Plug 'godlygeek/tabular'				" 文本过滤、对齐工具
Plug 'gcmt/wildfire.vim'				" 视图模式下快速选中符号中的内容
Plug 'scrooloose/nerdcommenter'			" 快速注释一行

" === JSON, CSS, PHP, JavaScript, HTML, etc.===
Plug 'elzr/vim-json'  " JSON关键字与值的突出显示,特定于JSON(非JS)的警告,引号隐藏
Plug 'hail2u/vim-css3-syntax', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }  " CSS3语法支持
Plug 'spf13/PIV', { 'for' :['php', 'vim-plug'] }  " PHP集成环境
Plug 'pangloss/vim-javascript', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }  " Javascript缩进和语法支持
Plug 'yuezk/vim-js', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }  "JavaScript和Flow.js的最准确的语法高亮
Plug 'MaxMEllon/vim-jsx-pretty', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }  " JSX 和 TSX 语法高亮
Plug 'jelera/vim-javascript-syntax', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }  " 增强JavaScript语法


" ===Go===
Plug 'fatih/vim-go' , { 'for': ['go', 'vim-plug'], 'tag': '*' }  " Go开发插件

" ===Python===
Plug 'tmhedberg/SimpylFold', { 'for' :['python', 'vim-plug'] }  " Python代码折叠
Plug 'Vimjas/vim-python-pep8-indent', { 'for' :['python', 'vim-plug'] }  " Python缩进
Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins', 'for' :['python', 'vim-plug'] }  " Python语法高亮
Plug 'tweekmonster/braceless.vim'  "用于Python和其他缩进语言的文本对象折叠

" ===Markdon===
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}  " markdowm预览
Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle' }	" 表格制作工具
Plug 'mzlogin/vim-markdown-toc', { 'for': ['gitignore', 'markdown'] }  " 目录生成
Plug 'theniceboy/bullets.vim'  " 自动添加项目列表符号

" ===Git===
Plug 'theniceboy/vim-gitignore', { 'for': ['gitignore', 'vim-plug'] }  " 为.gitignore文件提供语法高亮显示和最新代码片段
Plug 'fszymanski/fzf-gitignore', { 'do': ':UpdateRemotePlugins' }  " fzf接口,用于使用gitignore.io API创建.gitignore文件
"Plug 'mhinz/vim-signify'  "使用Vim的符号列显示差异
Plug 'airblade/vim-gitgutter'  " 显示git diff。 它显示了已添加,修改或删除的行

" ===编辑增强===
Plug 'jiangmiao/auto-pairs'  " 符号补全
Plug 'mg979/vim-visual-multi'  " 多光标支持
Plug 'tpope/vim-surround'  " 符号环境,轻松对符号内的内容进行修改
Plug 'junegunn/vim-after-object' " 指定内容操作 ,da=  删除=后的内容
Plug 'junegunn/vim-easy-align' " 对齐插件 , gaip=  使段落仲的 = 对齐


" ===其他===
"Plug 'yianwillis/vimcdoc'  " vim中文帮助
"Plug 'liuchengxu/vim-which-key'  " 显示被绑定的可用按键

" ==依赖==
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'kana/vim-textobj-user'
Plug 'fadein/vim-FIGlet'

call plug#end()		"结束plug安装
" 刷新vimrc后使用 :PlugInstall 安装插件

" ===END===
" >>>插件安装
" ===


" ===
" >>>插件配置
" ===START===

" ===状态栏===
" ==airline状态栏==
let g:airline#extensions#tabline#enabled = 1	" airline 显示选项卡和缓冲区
let g:airline_theme='jellybeans'
" 状态栏分隔美化  需要安装powerline-fonts字体(https://github.com/powerline/fonts) #sudo pacman -S powerline-fonts
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
  endif
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = '☰'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.dirty= '⚡'

" ==状态模式简洁显示==

let g:airline_mode_map = {
      \ '__'     : '-',
      \ 'c'      : 'C',
      \ 'i'      : 'I',
      \ 'ic'     : 'I',
      \ 'ix'     : 'I',
      \ 'n'      : 'N',
      \ 'multi'  : 'M',
      \ 'ni'     : 'N',
      \ 'no'     : 'N',
      \ 'R'      : 'R',
      \ 'Rv'     : 'R',
      \ 's'      : 'S',
      \ 'S'      : 'S',
      \ ''     : 'S',
      \ 't'      : 'T',
      \ 'v'      : 'V',
      \ 'V'      : 'V',
      \ ''     : 'V',
      \ }

" ===配色方案===
map <LEADER>c1 :set background=dark<CR>:colorscheme solarized8<CR>:AirlineTheme jellybeans<CR>	"配色1
map <LEADER>c2 :set background=light<CR>:let ayucolor='light'<CR>:colorscheme ayu<CR>:AirlineTheme ayu_light<CR>	" 配色2
set termguicolors	"开启真彩支持
set background=dark
let g:solarized_termtrans=1	" 透明背景
"colorscheme solarized8
"let ayucolor='light'	" light mirage dark
"colorscheme ayu


" ===目录树===
" ==NERDTreeToggle==
nmap <F3> :NERDTreeToggle<CR>	" 设置目录树快捷键

" ==NERDTree-git提示==
let g:NERDTreeIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ "Unknown"   : "?"
    \ }

" ==大规模项目文件浏览==
map <C-p> :CtrlP<CR>
let g:ctrlp_prompt_mappings = {
  \ 'PrtSelectMove("j")':   ['<c-e>', '<down>'],
  \ 'PrtSelectMove("k")':   ['<c-u>', '<up>'],
  \ }


" ===自动化===
" ==coc配置==
" 查看:https://github.com/neoclide/coc.nvim 中Extensions的列表
" 执行命令安装coc对相应语言的补全

" 若表中没有需要的,可参考 "Register custom language servers" 进行配置
" 参考教程:https://www.jianshu.com/p/231bfb066051
set timeoutlen=500 		" 设置按键超时为
set cmdheight=2 		" 设置命令行行数

inoremap <C-d> <Esc>:set cmdheight=2<CR>a
inoremap <C-t> <Esc>:set cmdheight=10<CR>a
nnoremap <C-d> :set cmdheight=2<CR>
nnoremap <C-t> :set cmdheight=10<CR>

set updatetime=1000
set shortmess+=c
set signcolumn=yes
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction
" 使用<cr>确认完成,`<C-g> u`表示在当前位置断开撤销链
" Coc仅在确认时执行片段和其他编辑
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" 使用K在预览窗口中显示文档
nnoremap ? :call <SID>show_documentation()<CR>
function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  else
    call CocAction('doHover')
  endif
endfunction

" 突出显示CursorHold上光标下的符号
autocmd CursorHold * silent call CocActionAsync('highlight')


" ===历史===
let g:undotree_DiffAutoOpen = 0
map <LEADER>l :UndotreeToggle<CR>


" ===文本===
" ==过滤对齐工具==
"使用 :Tabularize /|	使文本向 | 对齐,可是其他符号

" ==快速选中==
"视图模式下,使用 i' 快速选中 '' 中的内容,其他: i" i) i] i} ip

" ==快速注释==
"输入 <space>cc 对该行注释

" ===vim-go===

let g:go_def_mapping_enabled = 0
let g:go_template_autocreate = 0
let g:go_textobj_enabled = 0
let g:go_auto_type_info = 1
let g:go_def_mapping_enabled = 0
let g:go_highlight_array_whitespace_error = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_chan_whitespace_error = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_format_strings = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_function_parameters = 1
let g:go_highlight_functions = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_space_tab_error = 1
let g:go_highlight_string_spellcheck = 1
let g:go_highlight_structs = 1
let g:go_highlight_trailing_whitespace_error = 1
let g:go_highlight_types = 1
let g:go_highlight_variable_assignments = 0
let g:go_highlight_variable_declarations = 0


" ===vim-markdown-toc===
"let g:vmt_auto_update_on_save = 0
"let g:vmt_dont_insert_fence = 1
let g:vmt_cycle_list_item_markers = 1
let g:vmt_fence_text = 'TOC'
let g:vmt_fence_closing_text = '/TOC'

" ===Bullets.vim===
"let g:bullets_set_mappings = 0
let g:bullets_enabled_file_types = [
			\ 'markdown',
			\ 'text',
			\ 'gitcommit',
			\ 'scratch'
			\]


" ===Markdon===
" ==MarkdownPreview配置==
" 设置为1,nvim将在进入降价缓冲区后打开预览窗口,默认0
let g:mkdp_auto_start = 0

" 设置为1,当从降价缓冲区转换到另一个缓冲区时,nvim将自动关闭当前预览窗口,默认1
let g:mkdp_auto_close = 1

" 设置为1时,vim将在保存缓冲区时刷新markdown或从插入模式退出,默认0为自动刷新markdown,因为您编辑或移动光标,默认0
let g:mkdp_refresh_slow = 0

" 设置为1,MarkdownPreview命令可用于所有文件,默认情况下可用于markdown文件,默认0
let g:mkdp_command_for_global = 0

" 设置为1,默认情况下预览服务器可供网络中的其他人使用,服务器侦听localhost(127.0.0.1,默认0
let g:mkdp_open_to_the_world = 0

" 当您在远程vim中工作并在本地浏览器上预览时,使用自定义IP打开预览页面非常有用。详细信息请参阅:https://github.com/iamcco/markdown-preview.nvim/pull/9,默认空
let g:mkdp_open_ip = ''

" 指定浏览器打开预览页面,默认:'',firefox浏览器快熟关闭窗口需要设置:
" about:config > dom.allow_scripts_to_close_windows 将值设置为 true
let g:mkdp_browser = ''

" 设置为1,打开预览页面时,在命令行中回显预览页面url,默认0
let g:mkdp_echo_preview_url = 0

" 自定义vim函数名称打开预览页面此函数将接收url作为param,默认空
let g:mkdp_browserfunc = ''

" markdown渲染选项
" mkit: markdown-it选项
" katex: katex选项
" uml: markdown-it-plantuml选项
" maid: mermaid选项
" disable_sync_scroll: 禁用同步滚动,默认0
" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle'
"   middle: 表示光标位置总是显示在预览页面的中间
"   top: 表示预览页面顶部的vim顶部视口总是显示
"   relative: 表示光标位置总是显示在预览页面的相对位置
" hide_yaml_meta: 隐藏yaml元数据,默认1
" sequence_diagrams: js-sequence-diagrams 选项
let g:mkdp_preview_options = {
    \ 'mkit': {},
    \ 'katex': {},
    \ 'uml': {},
    \ 'maid': {},
    \ 'disable_sync_scroll': 0,
    \ 'sync_scroll_type': 'middle',
    \ 'hide_yaml_meta': 1,
    \ 'sequence_diagrams': {}
    \ }

" 使用自定义markdown样式必须是绝对路径
let g:mkdp_markdown_css = ''

" 使用自定义高亮样式必须绝对路径
let g:mkdp_highlight_css = ''

" 使用自定义端口启动服务器或使用随机空白
let g:mkdp_port = ''

" 预览页面标题,$ {name}将替换为文件名
let g:mkdp_page_title = '「${name}」'

nmap <F8> <Plug>MarkdownPreview
nmap <F9> <Plug>MarkdownPreviewStop
nmap <LEADER>mt <Plug>MarkdownPreviewToggle

" ==表格制作工具==
map <LEADER>tm :TableModeToggle<CR>


" ===fzf-gitignore===
noremap <LEADER>gi :FzfGitignore<CR>

" ===其他===
" ==中文帮组==
"set helplang=cn		" 启用英文的为en

" ==显示按键绑定==
"nnoremap <silent> <leader> :WhichKey '<Space>'<CR>


" ===END===
" >>>插件配置
" ===