vim配置之一

在linux系统上,我们经常需要对一些配置文件进行更改,这时我们都会用到vim,下面我们就来说下,在linux上对vim做一些简单的配置,让其更好用,效率更高

我们平时在敲代码的时候都会用到IDE或者编辑器,会有一些设置,其实这些配置都是有对应的配置文件的,现在我们来说下vim的配置文件:
在linux中的/etc/vimrc这个文件就是vim的系统的全局配置文件,由于linux是多用户,所以不同的用户可以有相应的配置文件来覆盖全局的配置,根据用户的偏好来进行配置,首先我们来给它加上一些简单的配置

我们可以在当前用户的home目录下新建一个.vimrc的配置文件,然后将下面的配置信息复制进去

let mapleader = ","
set number   " 设置行号
set tabstop=2  " 缩进
set encoding=utf-8
set nobackup
syntax enable
syntax on  " 语法高亮
set incsearch
set hlsearch
set showmatch
nnoremap ,<space> :nohlsearch<cr>
inoremap jk <esc>  " 用jk键来代替esc键
nnoremap ,ev :tabedit $MYVIMRC<cr> " 绑定快捷键来打开vim的配置文件
nnoremap ,sv :source $MYVIMRC<cr> " 让配置文件立马生效

保存之后,我们重新打开vim,会发现此时已经有一些效果了,当然,这还不够,因为我们要让它更方便,快捷,此时也许你想到了,对,vim也是有插件的,现在我们来聊聊vim的插件是怎么安装和管理的

我们先来安装一个vim的插件插件管理的插件bundle

我们先cd ~进入到当前用户home目录,然后创建.vim文件(如果没有的话),在.vim文件里创建一个bundle文件,然后将Vundle插件克隆到里面

git clone https://github.com/gmarik/Vundle.vim.git  ~/.vim/bundle/Vundle.vim

然后将下面的配置信息拷贝到.vimrc里面

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'

" 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
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

这样,我们的插件管理的插件就已经完成了,接着我们用它来安装一个插件

我们在.vimrc文件的 call vundle#begin()call vundle#end()之间加入Plugin 'scrooloose/nerdtree'这个插件,然后执行:

:PluginInstall

稍等片刻,我们的目录管理插件就完成了,其它插件以此类推,插件的配置可以根据相应的文档说明即可

总结:

今天介绍了vim的配置文件,以及一些简单的配置项的说明,插件安装
参考配置资料 imdia-vim

猜你喜欢

转载自blog.csdn.net/weixin_43671282/article/details/84032263