这是一份没有插件的 neovim 配置。
init.vim
source $HOME/.config/nvim/general/settings.vim
source $HOME/.config/nvim/general/appearance.vim
source $HOME/.config/nvim/general/keyshortcuts.vim
source $HOME/.config/nvim/general/plugins.vim
下属四个子配置文件:
(一)settings.vim
set nocompatible " 关闭 vi 兼容模式
set modelines=0 " 禁用模式行(安全措施)
set nobackup " 不进行备份设置
set nowritebackup
set noswapfile " 禁止产生交换文件
set autoread " 自动检测文件外部更改
" === 中文显示
set langmenu=zh_CN.UTF-8
set helplang=cn
set termencoding=utf-8
set encoding=utf8
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030
" === 环境变量
let g:python3_host_prog = expand("/usr/bin/python3")
let g:markdown_fenced_languages =['c', 'cpp', 'python', 'javascript']
" === 智能提示相关
syntax enable " 语法高亮
filetype on " 文件类型检测
filetype plugin indent on " 根据文件类型自动缩进
" === 显示相关
set termguicolors
set background=dark
" colorscheme desert
set showtabline=2 " 始终显示顶部tabline
set number " 显示绝对行号
" set relativenumber " 显示相对行号(和绝对行号的设置冲突)
set ruler " 显示标尺:右下角显示光标位置
" set cursorline " 高亮显示当前行(256色是一条横线,真彩显示才是高亮)
" set nowrap " 不自动折行显示
set pumheight=10 " 弹出菜单的高度
set splitbelow " 左右分割窗口时,新窗口默认出现在右侧
set splitright " 水平分割窗口时,新窗口默认出现在底部
set ambiwidth=double " 中文标点显示一致
set sidescroll=10 " 移动到看不见的字符时,自动向右滚动10个字符
set sm! " 高亮显示匹配括号
set novisualbell " 不要闪烁
set showcmd " select 模式下显示选中的行数
set vb t_vb= " 不要响铃
" === 光标样式
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" set virtualedit=block,onemore " 允许光标出现在最后一个字符的后面
" === 禁止显示滚动条
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
" 禁止显示菜单和工具条
set guioptions-=m
set guioptions-=T
" === 操作相关
set mouse="" " 不使用鼠标
" set mouse=a " 使用鼠标
" set mousehide " 输入时隐藏光标
set hidden " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
set iskeyword+=- " 将 - 分隔的单词作为一个单词文本对象
set backspace=2 " 允许退格键Backspace删除 indent,eol,start
set conceallevel=0 " 在 markdonw 文件中可以看到 `` 符号
autocmd BufWritePost $MYVIMRC source $MYVIMRC " 修改配置时,自动加载文件
" =(start)= 跨会话撤销,即新打开的文件依然能够撤销之前的 undo
set undofile
set undodir=~/.cache/nvim/undodir
if !isdirectory(&undodir)
call mkdir(&undodir, "p", 0700)
endif
" =(end)=
" set autochdir " 自动切换工作目录
" == 搜索查找相关
set ignorecase " 搜索忽略大小写
set smartcase " 智能匹配大小写
set hlsearch " 高亮查找匹配
set incsearch " 开始实时搜索功能
" === 缩进相关
set autoindent " 开始新行时处理缩进
set smartindent " 智能缩进
set smarttab " 在行和段开始处使用制表符
set tabstop=4 " 编辑时制表符占用空格数
set shiftwidth=4 " 格式化时,制表符占用的空格数
set softtabstop=4 " 设置 4 个空格为制表符
set expandtab " 将制表符Tab展开为空格, 这对于Python尤其有用
" === 代码补全
set completeopt=longest,menu " 让Vim补全菜单行为跟IDE一致
set wildmenu " vim自身命名行模式智能补全
set completeopt=menuone,preview,noselect " 补全时不显示窗口,只显示补全列表
set omnifunc=syntaxcomplete#Complete " 设置全能补全
set shortmess+=c " 设置补全静默
set cpt+=kspell " 设置补全单词
(二)keyshortcuts.vim
let mapleader=' '
" 模式切换
inoremap jk <ESC>
" Window
noremap <Leader>wn <C-w>w
noremap <Leader>wh <C-w><left>
noremap <Leader>wl <C-w><right>
noremap <Leader>wk <C-w><up>
noremap <Leader>wj <C-w><down>
noremap <Leader>wv :vs<CR>
noremap <Leader>ws :sp<CR>
noremap <Leader>w= <C-w>=
noremap <Leader>w+ <C-w>5>
noremap <Leader>w- <C-w>5<
" Buffer
noremap <Leader>bp :bp<CR>
noremap <Leader>bn :bn<CR>
" Tab
noremap <Leader>tn :tabnew<CR>
noremap <Leader>tn :tabnext<CR>
noremap <Leader>tp :tabprevious<CR>
noremap <Leader>tc :tabc<CR>
" 使用 \ + s 保存, \ + q 退出
noremap <Leader>fs :w<CR>
noremap <Leader>qq :q<CR>
" 打开或关闭目录树
nnoremap <leader>fe :Lexplore<CR>
(三)appearance.vim
" ===== 状态行 =====
set laststatus=2 " 始终显示状态栏
set cmdheight=2 " 命令行区的高度
" %F 完整文件路径名;%m 当前缓冲被修改标记;%r 当前缓冲只读标记
" %h 帮助缓冲标记;%w 预览缓冲标记
set statusline=%1*%F%m%r%h%w%=\
" %Y 文件类型
set statusline+=%2*\ %Y\ \|\
" %{...} 评估表达式的值,并用值代替
" %{"[fenc=".(&fenc==""?&enc:&fenc).((exists("+bomb") && &bomb)?"+":"")."]"} 显示文件编码
set statusline+=%3*%{\"\".(\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\"+\":\"\").\"\"}\
" %l 行数;%v 列数
set statusline+=%4*[%l:%v]\
" %p 当前行数占总行数的的百分比
set statusline+=%5*%p%%\ \|\
" %L 总行数
set statusline+=%6*%LL\
" 其他可用配置:%b ASCII值;%B 十六进制值;%{&ff} 显示文件类型
" 颜色
hi User1 cterm=none ctermfg=gray ctermbg=darkgray
hi User2 cterm=none ctermfg=darkgrey ctermbg=darkgray
hi User3 cterm=bold ctermfg=darkgrey ctermbg=gray
hi User4 cterm=bold ctermfg=yellow ctermbg=gray
hi User5 cterm=none ctermfg=darkgrey ctermbg=gray
hi User6 cterm=none ctermfg=darkgrey ctermbg=gray
" ===== Tabline 文件选项卡 =====
" Tabline 背景色
hi TabLineFill term=reverse ctermfg=5 ctermbg=7 guibg=#6c6c6c
" 设置 tab 选中状态时的颜色
hi SelectTabLine term=Bold cterm=Bold ctermfg=DarkYellow ctermbg=LightGray
hi SelectPageNum cterm=None ctermfg=DarkRed ctermbg=LightGray
hi SelectWindowsNum cterm=None ctermfg=DarkCyan ctermbg=LightGray
" 设置 tab 未选中状态时的颜色
hi NormalTabLine cterm=None ctermfg=Gray ctermbg=DarkGray
hi NormalPageNum cterm=None ctermfg=Gray ctermbg=DarkGray
hi NormalWindowsNum cterm=None ctermfg=Gray ctermbg=DarkGray
" 设置每个 tab 的显示样式,比如使用「」包裹
function MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
" select the highlighting
let hlTab = ''
let select = 0
if i + 1 == tabpagenr()
let hlTab = '%#SelectTabLine#'
let s ..= hlTab . '⎡%#SelectPageNum#%T' . (i + 1) . hlTab
let select = 1
else
let hlTab = '%#NormalTabLine#'
let s ..= hlTab . "⎡%#NormalTabLine#%T" . (i + 1) . hlTab
endif
" the label is made by MyTabLabel()
let s .= ' %<%{MyTabLabel(' . (i + 1) . ', ' . select . ')} '
"追加窗口数量
let wincount = tabpagewinnr(i + 1, '$')
if wincount > 1
if select == 1
let s .= "%#SelectWindowsNum#" . wincount
else
let s .= "%#NormalWindowsNum#" . wincount
endif
endif
let s .= hlTab . "⎦"
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let s ..= '%#TabLineFill#%T'
" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s ..= '%=%#TabLine#%999X░❨X❩'
endif
return s
endfunction
" Now the MyTabLabel() function is called for each tab page to get its label. >
function MyTabLabel(n, select)
let label = ''
let buflist = tabpagebuflist(a:n)
for bufnr in buflist
if getbufvar(bufnr, "&modified")
let label = '+'
break
endif
endfor
let winnr = tabpagewinnr(a:n)
let name = bufname(buflist[winnr - 1])
if name == ''
if &buftype == 'quickfix'
let name = '[Quickfix List]'
else
let name = '[No Name]'
endif
else
let name = fnamemodify(name, ':t')
endif
let label .= name
return label
endfunction
set tabline=%!MyTabLine()
" ===== netrw 文件资源管理器 =====
let g:netrw_banner = 0 " 设置是否显示横幅
let g:netrw_liststyle = 3 " 设置目录列表样式:树形
let g:netrw_browse_split = 4 " 在之前的窗口编辑文件
let g:netrw_altv = 1 " 水平分割时,文件浏览器始终显示在左边
let g:netrw_winsize = 25 " 设置文件浏览器窗口宽度为25%
let g:netrw_list_hide= '^\..*' " 不显示隐藏文件 用 a 键就可以显示所有文件、 隐藏匹配文件或只显示匹配文件
(四)plugins.vim
call plug#begin("~/.config/nvim/plugged")
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" - Vim (Windows): '~/vimfiles/plugged'
" - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
" - e.g. `call plug#begin('~/.vim/plugged')`
" - Avoid using standard Vim directory names like 'plugin'
" 这里只添加了 coc 一个插件
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Initialize plugin system
" - Automatically executes `filetype plugin indent on` and `syntax enable`.
call plug#end()
标签:set,配置文件,noremap,vim,ctermbg,let,ctermfg,nvim
From: https://www.cnblogs.com/7ytr5/p/18239504