Linux下的编辑器以vim和emacs为主流,一个编辑器之神,一个是神的编辑器。

本文以主要介绍如何在linux下以vim为基础搭建一个比较顺手的代码编辑器。

  • 有两种比较流行的方式:

自动安装
手动安装

  • 自动安装

  这种是方法是比较省事的方法,只要一个.vimrc配置文件就可以搞定所有的事情,一次配好即可。以后只要有这个配置文件,就可以走遍天下。
这种方式需要使用一个VIM插件管理工具来自动管理VIM插件的安装与卸载,笔者使用的Vundle来管理VIM插件,Vundle的全称是Vim Bundle,它是一款Vim插件管理工具。Vundle让你可以非常轻松地安装、更新、搜索和清理Vim插件。它还能管理你的运行时环境,并帮助标记。

    • 可以在Github上下载Vundle: https://github.com/VundleVim/Vundle.vim

下载完成后,解压到用户根目录的.vim目录下即可

    • 在终端(命令行)中使用git clone获取: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

clone完成后, 会在用户根目录下多出来一个bundle目录,此时Vundle已经安装完成。安装好Vundle以后,就可以根据自己的需要安装插件了。Vundle提供了几种不同的插件安装方式,一般我们用到的插件在github都可以找到,因此最常用的一般就是直接找github上插件对应的仓名,添加到.vimrc中即可。然后打开vim,执行:PluginInstall命令,即可自动安装,等待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 "============================ my plugins start =============================
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'majutsushi/tagbar'
Plugin 'tacahiroy/ctrlp-funky'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'easymotion/vim-easymotion'
Plugin 'haya14busa/incsearch.vim'
Plugin 'dkprice/vim-easygrep'
Plugin 'dyng/ctrlsf.vim'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'hfts/Porsche'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'vim-scripts/AutoComplPop'
Plugin 'scrooloose/nerdcommenter' "============================ my plugins end =============================== 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 "========== for vim ==============
syntax enable " 开启语法高亮
set t_Co= " 开启256色显示
set scrolloff= " 滚动时保持边距5行
set number " 开启行号显示
set mouse=a " 开启鼠标
set cmdheight=
set nocompatible
set confirm " 在处理未保存或只读文件的时候,弹出确认
set autoindent " 自动缩进
set tabstop= " Tab键的宽度
set expandtab " 展开tab为空格
set softtabstop= " 统一缩进为4
set shiftwidth=
filetype plugin indent on "打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu
set hlsearch " 高亮搜索
set laststatus= " 始终显示状态栏
set encoding=utf- "
set ignorecase " 搜索忽略大小写
set nopaste " 切换到正常模式
set list lcs=tab:\¦\ " 显示对齐线 | ¦ ┆ │ colorscheme Porsche set cursorline
"hi cursorline cterm=none term=none
"autocmd WinEnter * setlocal cursorline
"autocmd WinLeave * setlocal nocursorline
"highlight CursorLine guibg=#30F010 ctermbg=189 "自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - ] == a:char
return "\<Right>"
else
return a:char
endif
endfunction" "========== for quick key =======
" F11默认时全屏
nmap <F2> :NERDTreeToggle<cr>
nmap <F3> :TagbarToggle<CR>
nmap <F4> :ToggleBufExplorer<cr>
nmap <F5> :CtrlPFunky<cr>
nmap <F10> :set paste<cr> " 切换到粘贴模式
nmap <F12> :source ~/.vimrc<cr>
nmap <silent> <leader>ll :colorscheme Porsche<cr>
nmap <silent> <leader>jj :colorscheme space-vim-dark<cr>
nmap <silent> <leader>nm :set nonumber<cr>
nmap <silent> <leader>mn :set number<cr>
nmap <silent> <leader>ag :Ag<cr>
nmap <silent> <leader>ff ::shell<cr> "========== for NERDTree ==============
"let g:NERDTree_title='NERD Tree'
"let g:winManagerWindowLayout='NERDTree|TagList,Tarbar'
autocmd vimenter * NERDTree
nmap wm :NERDTreeToggle<cr>
autocmd bufenter * if (winnr("$") == && exists("b:NERDTree") ) | q | endif
function! NERDTree_Start()
exec 'NERDTree'
endfunction
function! NERDTree_IsValid()
return
endfunction
nmap <silent> mt :if IsWinManagerVisible() <BAR> WMToggle<CR> <BAR> else <BAR> WMToggle<CR>:q<CR> endif "<CR> "========== for CtrlP ===================
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'r'
let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:15,results:100'
let g:ctrlp_tabpage_position = 'al'
let g:ctrlp_working_path_mode = 'r'
let g:ctrlp_reuse_window = 'netrw\|help\|quickfix'
let g:ctrlp_open_new_file = 't'
let g:ctrlp_open_multiple_files = 'tjr'
let g:ctrlp_arg_map =
let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
\ 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.png,*.jpg,*.jpeg,*.gif " MacOSX/Linux
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$' if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files.
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" Ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif "========== for CtrlPFunky ==============
nnoremap <Leader>u :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
let g:ctrlp_extensions = ['funky']
let g:ctrlp_funky_syntax_highlight = 1
let g:ctrlp_funky_matchtype = 'path'
let g:ctrlp_funky_nerdtree_include_files = 1 "========== for vim-airline ==============
let g:airline_theme="light" "light
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|' "========== for EasyMotion ==============
" <Leader>f{char} to move to {char}
map <Leader>f <Plug>(easymotion-bd-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)
" s{char}{char} to move to {char}{char}
nmap s <Plug>(easymotion-overwin-f2)
" Move to line
map <Leader>L <Plug>(easymotion-bd-jk)
nmap <Leader>L <Plug>(easymotion-overwin-line)
" Move to word
map <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-overwin-w) "========== for insearch ==============
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
nnoremap <Esc><Esc> :<C-u>nohlsearch<CR>
"set incsearch
set hlsearch
let g:incsearch#auto_nohlsearch = 0
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl-*)
map # <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#) "=========== for NERDTREE-GIT-PLUGIN =====
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ "Unknown" : "?"
\ } "=========== cscope ===============
if has("cscope")
set csprg=/usr/local/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR> "=========== omnicppcomplete ===============
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_NamespaceSearch = 2
let OmniCpp_DisplayMode = 1
let OmniCpp_ShowScopeInAbbr = 1
let OmniCpp_ShowPrototypeInAbbr = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_SelectFirstItem = 1
let OmniCpp_DefaultNamespace=["std"]
let OmniCpp_SelectFirstItem = 2 "===============NERD Commenter=========================
let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
let g:NERDCompactSexyComs = 1 " Use compact syntax for prettified multi-line comments
let g:NERDDefaultAlign = 'left' " Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDAltDelims_java = 1 " Set a language to use its alternate delimiters by default
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } } " Add your own custom formats or override the defaults
let g:NERDCommentEmptyLines = " Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDTrimTrailingWhitespace = " Enable trimming of trailing whitespace when uncommenting
"===============================================================================================
  • 手动安装

手动安装,当然是要自己一个一个地安装插件了。这种方式的特点是需要自己一个一下下载vim插件,然后手动进行安装。虽然比较费事,但如果之前有vim插件安装包的备份文件,那就可以不依赖于网络。所以还是推荐在自己的本地留一份常用插件的安装包备份。手动安装的过程比较简单,基本上就是“下载-解压”,先从网卡下载好插件的压缩包,一般来说直接解压到.vim目录中即可。

笔者常用的几个插件如下,一般都可以在github上找到,其实从上面的配置文件中就可以找到笔者使用了哪些vim插件。
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'majutsushi/tagbar'
Plugin 'tacahiroy/ctrlp-funky'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'easymotion/vim-easymotion'
Plugin 'haya14busa/incsearch.vim'
Plugin 'dkprice/vim-easygrep'
Plugin 'dyng/ctrlsf.vim'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'hfts/Porsche'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'vim-scripts/AutoComplPop'
Plugin 'scrooloose/nerdcommenter'

最后,附上笔者vim的两张截图:

VIM配置的更多相关文章

  1. acm的ubuntu (ubuntu16.04 安装指南,chrome安装,vim配置,git设置和github,装QQ)

    日常手贱把ubuntu14.04更新到了16.04,然后就game over了.mdzz,不然泥萌也看不到这篇博客了=.= 然后花了些时间重装了一个16.04版的,原来那个14.04的用可以用,就是动 ...

  2. 简单快捷好用的vim配置和终端配置推荐

    vim 配置实用spf13-vim,安装方便简单快捷,极力推荐. 另外oh-my-zsh 终端配置很好,与之搭配使用效果更佳. 安装都很简单,一个脚本搞定, 都是在gitHub上开源的,自行搜索,这里 ...

  3. 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础

    上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...

  4. centos vim配置高亮语法和格式化粘贴

    centos vim配置高亮语法和格式化粘贴 设置vim别名和高亮grep词语 echo -e "\nalias vi=vim\nalias grep='grep --color'\n&qu ...

  5. vim配置方法

    /etc/vimrc (公共的) ~/.vimrc (私人的) rpm -qa|grep vim 这个命令,如何vim已经正确安装,则会显示上面三个包的名称 全部安装 yum -y install v ...

  6. VIM配置相关记录

    把一直使用中的vim配置做个GIT入库管理,也把之前积累在机器上的文档,做个汇总. https://github.com/wujuguang/kyvim 1. 安装完整版vim vi和vim的区别?在 ...

  7. Vim配置及说明——IDE编程环境

    Vim配置及说明——IDE编程环境 Vim配置及说明——IDE编程环境 1.基本及字体 2.插件管理 3.主题风格 4.窗口设置 5.目录树导航 6.标签导航 7.taglist 8.多文档编辑 9. ...

  8. Env:VIM配置

    注:文章来自于http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html 花了很长时间整理的,感觉用起来很方便,共享一下. 我的vim配 ...

  9. vim配置python开发环境

    vim配置python开发环境 一.安装vim sudo apt-get install vim 二.vim基础配置 #Centos6.5 /usr/share/vim/vim72 vi /etc/v ...

  10. Vim配置IDE开发环境

    我的vim IDE界面: 1.安装Vim和Vim基本插件首先安装好Vim和Vim的基本插件.这些使用apt-get安装即可:lingd@ubuntu:~/arm$sudo apt-get instal ...

随机推荐

  1. ajax+php+mysql 实现点赞、局部刷新,每个IP只能对一篇文章点赞一次

    主要流程: 点赞—>判断当前设备IP是否对当前文章有过点赞记录—>若有记录,弹出提示“已经赞过了”; 若无记录,当前文章点赞数+1,并在记录设备IP点赞记录的表中插入信息. 文章表 art ...

  2. java方法强制传递引用参数(做为返回值),改变被传递参数值。

    Java传递参数分为2种: 值类型,Java里面也叫简单类型,这种参数类型的传递的是它的副本拷贝: 引用类型,传递的是对象引用地址,如果在方法内改变该参数对象属性即是对原引用对象的改变:如果不想这样传 ...

  3. django学习记录

    1.参考资料问题: 现在django发布了1.11版本,离线文档下载引擎地址 文档下载地址 在线文档:https://docs.djangoproject.com/en/1.10/intro/tuto ...

  4. python之面向对象

    首先我们应该知道,python在设计之初就已经是一门面向对象的语言,所以说python中创建一个类和对象是很容易的. 面向对象的技术简介 类(class):用来描述具有相同的属性和方法的对象的集合.它 ...

  5. 将DataReader转换为DataTable

    public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader) { ///定义DataTable Data ...

  6. tp框架之模板继承

    模板继承是一项更加灵活的模板布局方式,模板继承不同于模板布局,甚至来说,应该在模板布局的上层.模板继承其实并不难理解,就好比类的继承一样,模板也可以定义一个基础模板(或者是布局),并且其中定义相关的区 ...

  7. Java中的URL类

    Java的网络类可以让你通过网络或者远程连接来实现应用.而且,这个平台现在已经可 以对国际互联网以及URL资源进行访问了.Java的URL类可以让访问网络资源就像是访问你本地的文件夹一样方便快捷.我们 ...

  8. Ext.js的store里放model,还是field?

    按别人的经验, 一般来说,如果通用性强的应用,STORE里存放MODEL,便于重用代码. 如果通用性较弱的(报告,图表),则考虑使用field进行定制.

  9. FTP上传文件到服务器

    一.初始化上传控件. 1.我们这里用dropzone.js作为上传控件,下载地址http://www.dropzonejs.com/ 2.这里我们使用一个div元素作为dropzone载体. < ...

  10. HashMap两种遍历方式的深入研究

    转自:http://swiftlet.net/archives/1259 HashMap的遍历有两种方式,如下所示:第一种利用entrySet的方式:   1 2 3 4 5 6 7 Map map ...