vim常用插件

来源:互联网 发布:导出数据库命令plsql 编辑:程序博客网 时间:2024/04/29 22:38

vim有超过一千多个插件,并且可以按download及rating排序,所以fans也是很多的。用过其他的editplus,notpad++,感觉主题样式做的不如vim,所以决定还是用vim,参考一些cheet sheet来使用。

 

  官方网址是http://www.vim.org/scripts/script_search_results.php ;

 

1.ColorSamplerPack

这里一百个主题,其中有仿textmate的 molokai

 

2. Taglist

安装完成后登录时提示错误信息, Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded,解决办法如下


https://bugzilla.redhat.com/show_bug.cgi?id=429200

 

3.在_vimrc中配置初使化

 

 

"Set mapleader

let g:mapleader = ","

 

"显示行号

set nu

 

"打开语法高亮

syntax on

 

"设置字体

set guifont=DejaVu/ Sans/ Mono/ 12

 

"设置缩进

set softtabstop=8

set shiftwidth=8

set expandtab

 

"关闭toolbar

set guioptions-=T

 

"关闭自动备份

set nobackup

 

"自动格式化

set formatoptions=tcrqn

 

"在行和段开始处使用制表符

set smarttab

 

"在normal模式下使用系统剪贴板

"set clipboard+=unnamed

 

"自动缩进设置

set cindent

set smartindent

set incsearch

set autoindent

 

"Show matching bracets

set showmatch

 

"Get out of VI's compatible mode

set nocompatible

 

"Have the mouse enabled all the time

set mouse=a

 

"Set to auto read when a file is changed from the outside

set autoread

 

"Enable filetype plugin

filetype plugin indent on

"Set mapleader

let g:mapleader = ","

 

"显示行号

set nu

 

"打开语法高亮

syntax on

 

"设置字体

set guifont=DejaVu/ Sans/ Mono/ 12

 

"设置缩进

set softtabstop=8

set shiftwidth=8

set expandtab

 

"关闭toolbar

set guioptions-=T

 

"关闭自动备份

set nobackup

 

"自动格式化

set formatoptions=tcrqn

 

"在行和段开始处使用制表符

set smarttab

 

"在normal模式下使用系统剪贴板

"set clipboard+=unnamed

 

"自动缩进设置

set cindent

set smartindent

set incsearch

set autoindent

 

"Show matching bracets

set showmatch

 

"Get out of VI's compatible mode

set nocompatible

 

"Have the mouse enabled all the time

set mouse=a

 

"Set to auto read when a file is changed from the outside

set autoread

 

"Enable filetype plugin

filetype plugin indent on

 

"设置配色方案为torte

"colo torte

"colo desert

colo Molokai

 

"设置支持的文件编码类项,目前设置为utf-8和gbk两种类型

set fileencodings=utf-8,chinese,latin1

 

"设置断词

set linebreak

 

"设置搜索结果高亮显示

set hlsearch

 

"设置记录的历史操作列表

set history=200

 

"设置折叠

set foldenable

set foldcolumn=2

set foldlevel=3

 

"打开目录时不显示隐藏目录和文件

let g:netrw_hide= 1

let g:netrw_list_hide= '^/..*'

 

"AutoCommand

"新建.c,.h.cpp,.sh,.java,.php,.py文件自动打开Taglist

autocmd BufNewFile *.[ch],*.cpp,*.sh,*.java,*.php,*.py exec ":call SetTitle()"

"读入.c,.h.cpp,.sh,.java,.php,.py文件自动打开Taglist

"autocmd BufRead *.[ch],*.cpp,*.sh,*.java,*.php,*.py exec ":Tlist"

"新建文件后,自动定位到文件末尾

autocmd BufNewFile * normal G

"如果是新建的php文件,则自动定位到最后第二行

autocmd BufNewFile *.php normal k

 

"读入python文件,设置缩进格式

autocmd BufNewFile,BufRead *.py set cinwords=if,elif,else,for,while,try,expect,finally,def,class

 

"读入C文件,设置折叠方式为syntax

autocmd BufNewFile,BufRead *.[ch],*.cpp set foldmethod=syntax

 

"读入其它文件,设置折叠方式为indent

autocmd BufNewFile,BufRead *.py,*.sh,*.java,*.php set foldmethod=indent

 

"设置Java代码的自动补全

autocmd FileType java setlocal omnifunc=javacomplete#Complete

"autocmd FileType java set tags=./tags,./../tags,./../../tags

 

"设置输入代码的自动补全

"autocmd BufEnter * call DoWordComplete()

 

"绑定自动补全的快捷键<C-X><C-O>到<leader>;

imap <leader>; <C-X><C-O>

 

"绑定复制到系统剪贴板快捷键

vmap <leader>c "+y

nmap <leader>c "+y

 

"绑定粘贴系统剪贴板内容快捷键

"imap <leader>v <ESC>"+p "不设置insert模式下的快捷键,因为会造成无法输入,v

vmap <leader>v <ESC>"+p

nmap <leader>v "+p

 

"设定开关Taglist插件的快捷键为F4,可以在VIM的左侧栏列出函数列表等

map <F4> :Tlist<CR>

 

"设置程序的运行和调试的快捷键F5和Ctrl-F5

map <F5> :call CompileRun()<CR>

map <C-F5> :call Debug()<CR>

 

"设置tab操作的快捷键,绑定:tabnew到<leader>t,绑定:tabn, :tabp到<leader>n,

"<leader>p

map <leader>t :tabnew<CR>

map <leader>n :tabn<CR>

map <leader>p :tabp<CR>

 

"设置空格键开关折叠

nmap <SPACE> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

 

"使用<leader>r打开上次运行的命令

nmap <leader>r :<UP>

 

"用cscope支持

set csprg=/usr/bin/cscope

let Tlist_Ctags_Cmd='/usr/bin/ctags'

let Tlist_Show_One_File=1

let Tlist_Exit_OnlyWindow=1

let Tlist_Use_Right_Window=1

"默认打开Taglist

"let Tlist_Auto_Open=1

 

"设置搜索的tags文件范围

"set tags=./tags,./../tags,./../../tags

 

"使用<leader>e打开当前文件同目录中的文件

if has("unix")

        map <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>

else

        map <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>

endif

 

"定义CompileRun函数,用来调用进行编译和运行

func CompileRun()

        exec "w"

        "C程序

        if &filetype == 'c'

                exec "!gcc % -g -o %<"

                exec "!./%<"

                "Java程序

        elseif &filetype == 'java'

                exec "!javac %"

                exec "!java %<"

                "php程序

        elseif &filetype == 'php'

                exec "!php %"

                "bash程序

        elseif &filetype == 'sh'

                exec "!bash %"

                "python程序

        elseif &filetype == "python"

                exec "!python %"

        endif

endfunc

"结束定义CompileRun

 

"定义Debug函数,用来调试程序

func Debug()

        exec "w"

        "C程序

        if &filetype == 'c'

                exec "!gcc % -g -o %<"

                exec "!gdb %<"

                "Java程序

        elseif &filetype == 'java'

                exec "!javac %"

                exec "!jdb %<"

                "Php程序

        elseif &filetype == 'php'

                exec "!php %"

                "bash程序

        elseif &filetype == 'sh'

                exec "!bash -x %"

                "python程序

        elseif &filetype == 'python'

                exec "!pdb %"

        endif

endfunc

"结束定义Debug

 

"定义函数SetTitle,自动插入文件头

func SetTitle()

        "如果文件类型为.sh文件

        if &filetype == 'sh' || &filetype == 'python'

                call setline(1, "/#========================================================================")

                call append(line("."), "/# Author: Charlse.Zhang")

                call append(line(".")+1, "/# Email: feiyuw@gmail.com")

                call append(line(".")+2, "/# File Name: ".expand("%"))

                call append(line(".")+3, "/# Description: ")

                call append(line(".")+4, "/#   ")

                call append(line(".")+5, "/# Edit History: ")

                call append(line(".")+6, "/#   ".strftime("%Y-%m-%d")."    File created.")

                call append(line(".")+7, "/#========================================================================")

                call append(line(".")+8, "")

                "其它程序文件

        else

                call setline(1, "/**")

                call append(line("."), "=========================================================================")

                call append(line(".")+1, " Author: Charlse.Zhang")

                call append(line(".")+2, " Email: feiyuw@gmail.com")

                call append(line(".")+3, " File Name: ".expand("%"))

                call append(line(".")+4, " Description: ")

                call append(line(".")+5, "   ")

                call append(line(".")+6, " Edit History: ")

                call append(line(".")+7, "   ".strftime("%Y-%m-%d")."    File created.")

                call append(line(".")+8, "=========================================================================")

                call append(line(".")+9, "**/")

                call append(line(".")+10, "")

        endif

        "如果为php文件,添加相应头和尾

        if &filetype == 'php'

                call append(0, "<?php")

                call append(line("$"), "?>")

        endif

        "如果为sh文件,添加相应的头

        if &filetype == 'sh'

                call append(0, "/#!/bin/bash")

                "如果为python文件,添加相应的头和编码设定

        elseif &filetype == 'python'

                call append(0, "/#!/usr/bin/python")

                call append(1, "/# -*- coding: utf-8 -*-")

        endif

endfunc

 

 

 

 

原创粉丝点击