Linux下 vim 的配置
为了能够复制粘贴到外面,需要下载gvim,可以自行下载。
我的插件管理是用vim-plug来管理的
下载命令
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
然后在vimrc中添加如下代码段
call plug#begin() """""中间放插件"""" call plug#end()
在中间放置需要的插件就可以了.
vim-plug管理插件时,只需要加入上面在代码段中加入需要的插件命(如下),然后打开终端输入vim,在按:输入,PlugInstall,就可以完成插件安装。
我自己在使用的一些插件。
neadtree 管理目录用,我把快捷键设置成F3,可以让它开启或关闭
Plug 'scrooloose/nerdtree'
nerdcommenter 代码多行注释用的,还是挺不错的,按住 \+c+space 就可以注释与反注释了
Plug 'ddollar/nerdcommenter'
airline、airline themes 美化 vim 底部状态栏
Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes'
airline使用前需要安装powerline字体
安装方法如下
# clone git clone https://github.com/powerline/fonts.git --depth=1 # install cd fonts ./install.sh # clean-up a bit cd .. rm -rf fonts
airline的主题目录如下,可以选择自己想要的主题
~/.vim/plugged/vim-airline-themes/autoload/airline/themes
以下是我的觉得比较好看的主题。
aurora.vim base16_eighties.vim dracula.vim onedark.vim silver.vim
badcat.vim base16_isotope.vim hybridline.vim papercolor.vim term.vim
badwolf.vim base16_pop.vim minimalist.vim peaksea.vim understated.vim
base16_colors.vim bubblegum.vim molokai.vim ravenpower.vim vice.vim
base16color.vim deus.vim night_owl.vim raven.vim wombat.vim
其他的主题就被我删了。
现在我再用的vice和tomorrow主题,我认为还是蛮好看的。
只要在.vimrc中添加
let g:airline_theme="vice"
就可以了。
最后是完整的.vimrc
" === " 设置快捷键 " === map Z ZZ map - $ map 0 ^ map S :w<CR> map ; : map tt :tabnew map tj :tabNext<CR> map tk :tabnext<CR> map to :terminal<CR> map gt <nop> map gT <nop> function! HideNumber() " <F2>开启/关闭行号显示 if(&relativenumber == &number) set relativenumber! number! elseif(&number) set number! else set relativenumber! endif set number? endfunc nnoremap <F2> :call HideNumber()<CR> "®编译 map ® :call CR()<CR> func! CR() exec "w" if &filetype == 'cpp' exec "!g++ -std=c++11 % -o %<" exec "!time ./%<" elseif &filetype == 'python' exec "!python3 %" endif endfunc " === " 设置编码 " === set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8 set fileencodings=ucs-bom,utf-8,cp936 set fileencoding=utf-8 " === " === 基本设置 " === set nocompatible " 不要使用vi的键盘模式,而是vim自己的 set clipboard =unnamed,unnamedplus " 共享剪贴板 syntax on " 语法高亮 set cursorline set whichwrap=<,>,[,],h,l " 允许backspace和光标键跨越行边界 set nu " 显示行号 set selection=exclusive set selectmode=mouse,key set listchars=tab:>-,trail:- set magic " 设置魔术 set guioptions-=T " 隐藏工具栏 set guioptions-=m " 隐藏菜单栏 set laststatus=2 " 总是显示状态栏 set showmatch " 高亮显示匹配的括号 "匹配括号高亮的时间(单位是十分之一秒) hi MatchParen ctermbg=blue guibg=lightblue set matchtime=5 set ruler " 显示光标当前位置 "我的状态行显示的内容(包括文件类型和解码) set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] set cmdheight=2 set autoindent " 自动缩进 set cindent " 以C语言的方式缩进 set shiftwidth=4 " 设置自动缩进的空格数量 set softtabstop=4 " tab键的实际占有空格数,统一缩进 set tabstop=4 " 设置tab键的空格数 set expandtab " 用空格替换tab set completeopt=preview,menu " 代码补全 set nobackup " 从不备份 filetype plugin indent on " 允许插件 filetype on " 侦测文件类型 filetype plugin on " 载入文件类型插件 set viminfo+=! " 保存全局变量 set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割 set linespace=0 " 字符间插入的像素行数目 set wildmenu " 增强模式中的命令行自动完成操作 set backspace=2 " 使回格键(backspace)正常处理indent, eol, start等 set report=0 " 通过使用: commands命令,告诉我们文件的哪一行被改变过 set fillchars=vert:\ ,stl:\ ,stlnc:\ " 在被分割的窗口间显示空白,便于阅读 set scrolloff=5 " 光标移动到buffer的顶部和底部时保持3行距离 set nobackup " 禁止生成临时文件 set noswapfile " 禁止生成交换文件 set autoread " 设置当文件被改动时自动载入 set autowrite " 自动保存 set history=1000 " 历史记录数 set confirm " 在处理未保存或只读文件的时候,弹出确认 set ignorecase " 搜索忽略大小写 set hlsearch " 搜索逐字符高亮 set incsearch set gdefault " 行内替换 set relativenumber number " 相对行号: 行号变成相对 " === " === 插入模式下用绝对行号, 普通模式下用相对 " === au FocusLost * :set norelativenumber number au FocusGained * :set relativenumber autocmd InsertEnter * :set norelativenumber number autocmd InsertLeave * :set relativenumber "复制选中区到系统剪切板中 vnoremap <leader>y "+y if has("autocmd") " 打开自动定位到最后编辑的位置, 需要确认 .viminfo 当前用户可写 au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif endif " === " === vimplug " === call plug#begin('~/.vim/plugged') Plug 'scrooloose/nerdtree' Plug 'ddollar/nerdcommenter' Plug 'jiangmiao/auto-pairs' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' call plug#end() " === " === NERDTree " === let NERDChristmasTree=1 " 显示增强 let NERDTreeAutoCenter=1 " 自动调整焦点 let NERDTreeShowFiles=1 " 显示文件 " let NERDTreeShowHidden=1 " 显示隐藏文件 let NERDTreeHightCursorline=1 " 高亮显示当前文件或目录 let NERDTreeShowLineNumbers=1 " 显示行号 let NERDTreeWinPos='left' " 窗口位置 let NERDTreeWinSize=40 " 窗口宽度 let g:NERDTreeCaseSensitiveSort = 1 let g:nerdtree_tabs_open_on_console_startup=1 let NERDTreeIgnore=['\.pyc','\~$','\.swp'] let g:NERDTreeIndicatorMapCustom = { \ "Modified" : "✹", \ "Staged" : "✚", \ "Untracked" : "✭", \ "Renamed" : "➜", \ "Unmerged" : "═", \ "Deleted" : "✖", \ "Dirty" : "✗", \ "Clean" : "✔︎", \ 'Ignored' : '☒', \ "Unknown" : "?" \ } " 快捷键 nnoremap <silent> <F3> :NERDTreeToggle<CR> autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif " === " === Airline Themes " === let g:airline_powerline_fonts = 1 let g:airline_theme='onedark' " === " === 新文件标题 " === autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" " 定义函数SetTitle,自动插入文件头 func SetTitle() let l = 0 if &filetype == 'sh' let l = l+1 | call setline(l, "\###############################################################") let l = l+1 | call setline(l, "\# File Name : ".expand("%")) let l = l+1 | call setline(l, "\# Author : Jiaaaaaaaqi") let l = l+1 | call setline(l, "\# Created Time : ".strftime("%c")) let l = l+1 | call setline(l, "\###############################################################") let l = l+1 | call setline(l, "\#!/bin/bash") let l = l+1 | call setline(l, "") else let l = l+1 | call setline(l, "/*************************************************************** ") let l = l+1 | call setline(l, " > File Name : ".expand("%")) let l = l+1 | call setline(l, " > Author : Jiaaaaaaaqi") let l = l+1 | call setline(l, " > Created Time : ".strftime("%c")) let l = l+1 | call setline(l, " ***************************************************************/") let l = l+1 | call setline(l, "") let l = l+1 | call setline(l, "\#include <stdio.h>") let l = l+1 | call setline(l, "\#include <algorithm>") let l = l+1 | call setline(l, "\#include <iostream>") let l = l+1 | call setline(l, "") let l = l+1 | call setline(l, "using namespace std;") let l = l+1 | call setline(l, "") let l = l+1 | call setline(l, "int main() {") let l = l+1 | call setline(l, " // freopen(\"in\", \"r\", stdin);") let l = l+1 | call setline(l, " // freopen(\"out\", \"w\", stdout);") let l = l+1 | call setline(l, "") let l = l+1 | call setline(l, " return 0;") let l = l+1 | call setline(l, "}") let l = l+1 | call setline(l, "") endif endfunc " 新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G