- 第一步必须是联网安装vim了
[sudo ] apt install vim
如果不是root用户需要加sudo,并且必须拥有sudo权限才可以 - 配置文件生成
[sudo] touch ~/.vimrc
注意vimrc前面有个点
一般配置文件创建在用户目录下,root用户在/root/.vimrc,其他用户在/home/xxx/.vimrc,xxx为用户名 - 修改配置文件
vim .vimrc
在此列举一些常见的配置,以下内容均须写入.vimrc文件中才有效
syntax on
开启语法高亮
set number
显示行号
set relativenumber
显示从当前行数的前后行数
set cursorline
高亮显示当前行
set wrap
自动换行
set showcmd
显示指令
set wildmenu
命令补全
set hlsearch
高亮显示搜索
set incsearch
动态高亮搜索
set ignorecase
不区分大小写搜索
set smartcase
智能大小写搜索
在vim普通模式中可以通过键入i进入输入模式,按v进行visual模式,按ESC返回普通模式。在进入普通模式后,就可以键入上述字符进行vim的配置,在普通模式输入:wq进行保存注意冒号是英文字符而不是中文的冒号。保存后再打开配置文件就可以看到
可以发现当前完成的配置都已经在vim中有所体现了,但是看起来貌似不太好看,相比ide来说差距还是太大。然后,vim的可扩展性给予了用于极大的自由度,github上有各种插件任你选择。 - vim插件管理器
linux命令行下输入git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
进行vundle插件管理包的安装,当然也可以选择其他的。
可参考vundle插件管理器进行环境的配置。
进入~/.vimrc文件在末尾添加
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
call vundle#end()
然后在begin和end这两行中间就可以配置插件了,以下是我所使用的插件的部分
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'mg979/vim-visual-multi'
Plugin 'preservim/nerdtree'
Plugin 'neoclide/coc.nvim', {'branch': 'release'}
Plugin 'connorholyday/vim-snazzy'
Plugin 'tpope/vim-fugitive'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
call vundle#end()
当然还需要进行安装,按ESC回到普通模式下,键入:PluginInstall
进行安装,也可以在终端窗口键入vim +PluginInstall +qall
进行安装,这样就可以实现插件的安装了。vim中可以在普通模式下输入:color xxx
或:colorscheme xxx
进行主题的配置,上述的插件connorholyday/vim-snazzy
就是一个我用的主题,通过:colorscheme snazzy
实现配置,最终可以实现效果如下
- 完整vim配置文件
let mapleader=" " " 将leader键(\键,类似于Windows键)换成空格(相当于空格键)
syntax on " 开启语法高亮
set number " 显示行号
set relativenumber " 显示从当前行数的前后行数
set cursorline " 高亮显示当前行
set wrap " 自动换行
set showcmd " 显示指令
set wildmenu " 命令补全
set hlsearch " 高亮显示搜索
set incsearch " 动态高亮搜索"
set ignorecase " 不区分大小写搜索
set smartcase " 智能大小写搜索
"noremap A 5b " 将 A 替换为 5b
noremap = nzz
noremap - Nzz
noremap <LEADER><CR> :nohlearch<CR>
map s <nop>
map S :w<CR>
map Q :q<CR>
map R :source $MYVIMRC<CR>
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'mg979/vim-visual-multi'
Plugin 'preservim/nerdtree'
Plugin 'neoclide/coc.nvim', {'branch': 'release'}
Plugin 'connorholyday/vim-snazzy'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
colorscheme snazzy
filetype plugin indent on " required
autocmd vimenter * NERDTree | wincmd p
可以直接更换到自己的vim配置文件