加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

LINUX教学:Vim配置详解

发布时间:2020-05-28 09:58:44 所属栏目:Linux 来源:互联网
导读:介绍《LINUX教学:Vim配置详解》开发教程,希望对您有用。

《LINUX教学:Vim配置详解》要点:
本文介绍了LINUX教学:Vim配置详解,希望对您有用。如果有疑问,可以联系我们。

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 " 开启256色显示
set scrolloff=3 " 滚动时坚持边距5行
set number " 开启行号显示
set mouse=a " 开启鼠标
set cmdheight=1
set nocompatible
set confirm " 在处理未保存或只读文件的时候,弹出确认
set autoindent " 自动缩进
set tabstop=4 " Tab键的宽度
set expandtab " 展开tab为空格
set softtabstop=4 " 统一缩进为4
set shiftwidth=4
filetype plugin indent on "打开文件类型检测,加了这句才可以用智能补全
set completeopt=longest,menu
set hlsearch " 高亮搜索
set laststatus=1 " 始终显示状态栏
set encoding=utf-8 "
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('.') - 1] == 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("$") == 1 && exists("b:NERDTree") ) | q | endif
function! NERDTree_Start()
exec 'NERDTree'
endfunction
function! NERDTree_IsValid()
return 1
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 = 1
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

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读