打造适合自己的vim编辑器方法总结

vim使用方法总结

说明:这是打造适合自己的vim编辑器的进阶方法,关于vim基础知识,请自行百度。也可参考文章末尾推荐blog网址
如果觉得自己打造vim编辑器麻烦,可以从github上面克隆一个,推荐:vimplus

vim简介

在windows系统下使用vim请下载gVim,linux自带Vim

  • Vim是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。 VIM是自由软件。Vim是从 vi 发展出来的一个文本编辑器。代码补完、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。简单的来说, vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方。 vim 则可以说是程序开发者的一项很好用的工具。

配置Vundle

  • Vundle 是一个很方便的vim插件管理器。Vundle本身也是一个vim插件,只需要在vimrc里面配置号就课方便的安装、更新、删除插件,非常好用。关于其他插件的使用,请自行Google
  • 请确保安装好 vim git 这两个包
  • 如果没有
sudo apt-get install vim git 
  • 下载Vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  • 创建 ~/.vimrc 文件,以通知 Vim 使用新的插件管理器。安装、更新、配置和移除插件需要这个文件。
vim ~/.vimrc
  • 在文件中加入以下内容,之后:wq保存退出
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
  • 打开vim,键入命令安装插件,加在.vimrc文件中的所有插件都会自动安装
:PluginInstall
  • 安装完毕之后,键入下列命令,可以删除高速缓存区并关闭窗口
:bdelete
  • 在vim命令行模式下使用Vundele
  • 搜索插件:可以指定插件名搜索,如:PluginSearch taglist (查看编程函数列表)
:PluginSearch
:PluginSearch! (从vimscripts网站刷新本地列表)
  • 更新插件
:PluginUpdate
:PluginInstall! (重新安装所有插件)
  • 卸载插件,首先列出已安装的插件,之后将光标置于插件行上,按下shift+d 组合键。然后编辑./vimrc文件(删除插件入口),最后键入:wq 保存退出。另外一种方法,先删除插件入口,在使用命令:PluginClean
:PluginList
:e ~/.vimrc
  • 使用Vundle的帮助文档
:h vundle

配置.vimrc文件

  • 打开.vimrc文件,有两种方式。第一次编辑/.vimrc 新文件,建议使用第二种,用leafpad打开。因为vim不支持从其他地方直接复制内容。需要安装 vim-gnome
sudo vim ~/.vimrc
leafpad ~/.vimrc
  • 补充:安装vim-gnome,
sudo apt-get install vim-gnome

操作方式:都是在normal模式下使用的

y 表示从vim复制到系统剪切版  
p 表示从外部文件(系统剪切版)粘贴到vim  
d 表示剪切  
gp 粘贴并且移动光标到粘贴内容后,gP同理  
yy 复制一行  
dd 删除一行  
p 在当前光标后粘贴  
P 在当前光标前粘贴
  • 在/.vimrc中添加插件入口,写上入口后,再去vim命令行安装
Plugin 'xxxx'
  • 设置其他,可以参考如下。在/.vimrc文件的最下方,添加命令。
set backspace=2
color desert 

set encoding=utf-8
let &termencoding=&encoding
set fileencodings=utf-8,gbk    "解决中文乱码

set number
syntax on
set cindent
set incsearch       "增量式搜索
set hlsearch        "高亮搜索

更多vim进阶,可以参考如下blog

原文地址:https://www.cnblogs.com/hudunkey/p/10012644.html