`

Vim配置大全

 
阅读更多
http://0nly.me/2013/11/vim-all/


Vim配置大全
Vim快捷键高清图

1.1、安装vim插件pathogen:

mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -Sso ~/.vim/autoload/pathogen.vim \    https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
1.2、添加下列配置至~/.vimrc中:

execute pathogen#infect()
syntax on
filetype plugin indent on
2.1、安装vim-flake8:

cd ~/.vim/bundle
git clone git://github.com/nvie/vim-flake8.git
当vim打开Python源码后,按F7就会执行Flake8对当前文件进行检查。

3.1、Vim调试和格式化Python代码

下载格式化工具

点击下载

改名为pyformat.py,放入~/.vim 目录下,并赋予可执行权限 ,Ubuntu下直接命令行:

sudo chmod 777 ~/.vim/pyformat.py
让Vim支持pyformat.py,在~/.vinrc中加入:

au FileType python set formatprg=~/.vim/pyformat.py
noremap <F11> gggqG
快捷键为F11,可自行设置。

直接在Vim中调试Python代码,在~/.vinrc中加入:

python << EOF
import time
import vim
def SetBreakpoint():
    nLine = int( vim.eval( 'line(".")'))
    strLine = vim.current.line
    i = 0
    strWhite = ""
    while strLine[i] == ' ' or strLine[i] == "\t":
        i += 1
        strWhite += strLine[i]
    vim.current.buffer.append(
       "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
         {'space':strWhite, 'mark': '#' * 30}, nLine - 1)
    for strLine in vim.current.buffer:
        if strLine == "import pdb":
            break
        else:
            vim.current.buffer.append( 'import pdb', 0)
            vim.command( 'normal j1')
            break
vim.command( 'map <F12> :py SetBreakpoint()<cr>') 
def RemoveBreakpoints():
    nCurrentLine = int( vim.eval( 'line(".")'))
    nLines = []
    nLine = 1
    for strLine in vim.current.buffer:
        if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':
            nLines.append( nLine)
        nLine += 1
    nLines.reverse()
    for nLine in nLines:
        vim.command( 'normal %dG' % nLine)
        vim.command( 'normal dd')
        if nLine < nCurrentLine:
            nCurrentLine -= 1
    vim.command( 'normal %dG' % nCurrentLine)
vim.command( 'map <C-F12> :py RemoveBreakpoints()<cr>')
vim.command( 'map <C-D> :!python %<cr>')
EOF
快捷键:F12设置断点,ctrl+F12移除断点,ctrl+d直接在Vim中运行Python代码。

4.1、安装目录树NERDTree:

cd ~/.vim/bundle
git clone https://github.com/scrooloose/nerdtree.git
在~/.vimrc中加入下面一句话,快捷键F3打开目录树:

map <F3> :NERDTreeToggle<CR>
4.2、NERDTree-Tabs目录树增强:

cd ~/.vim/bundle
git clone https://github.com/jistr/vim-nerdtree-tabs.git
在~/.vimrc中加入:

let g:nerdtree_tabs_open_on_console_startup=1 "设置打开vim的时候默认打开目录树
map <leader>n <plug>NERDTreeTabsToggle <CR>  "设置打开目录树的快捷键
5.1、Vim主题美化:

大量Vim主题

6.1、安装Taglist:

下载Taglist

安装它,解压到~/.vim文件夹中。在~/.vimrc中加入:

if MySys() == "windows"      "设定windows系统中ctags程序的位置
let Tlist_Ctags_Cmd = 'ctags'
elseif MySys() == "linux"       "设定linux系统中ctags程序的位置
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
endif
let Tlist_Show_One_File = 1    ""只显示当前文件的列表
let Tlist_Exit_OnlyWindow=1   ""退出当前文件的时候直接退出列表
let Tlist_Use_Right_Window = 1   "在右侧窗口中显示taglist窗口
7.1、为Vim安装Qt界面qVim

Vim的Qt界面

配图为suprsvn自用的Vim,在KDE下,界面已由GTK被Qt界面代替,美观。

QVim开源项目主页

Ubuntu下安装QVim:

sudo add-apt-repository ppa:equalsraf/ppa
sudo apt-get update
sudo apt-get install qvim
运行:

安装完成以后运行GVim,界面依旧是GTK,运行下面命令并注销或重启后,再次运行GVim,即可出现Qt界面的Gvim,如配图。

sudo ln -s vim qvim
8.1、让Vim支持Markdown

现在的博客是基于github+Jekyll构建的,感觉良好。所有文章均是由Markdown来书写的,再加上咱是一个Vimer,所以就必须配置Vim Markdown Mode了。

安装走起来:

cd ~/.vim/bundle
git clone https://github.com/plasticboy/vim-markdown.git
在~/.vimrc中加入:

let g:vim_markdown_folding_disabled=1    ""禁止折叠
9.1、安装HTML/CSS神器Emmet

相信做web开发的同学对这个Emmet都不陌生,就是之前大名鼎鼎的ZenCoding。在Vim中以插件的形式存在,叫做emmet-vim。

Ubuntu终端两条命令即可安装完成:

cd ~/.vim/bundle
git clone http://github.com/mattn/emmet-vim.git
配置,在~/.vimrc中加入:

情况1:在不同的模式下使用emmet。

let g:user_emmet_mode='n' "仅在常用函数时开启.
let g:user_emmet_mode='inv' "和下面的等效
let g:user_emmet_mode='a' "所有模式的所有函数均开启。
情况2:仅仅在HTML/CSS开发时开启。

let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall
10.1、插件xptemplate推荐,比snipmate更强的代码片段补全

#suprsvn:关于这个插件的特点就不在啰嗦了,用了你就觉悟了。我在html和php时用,有了它码的很很快。

安装是一如既往的简单:

cd ~/.vim/bundle/
git clone git://github.com/drmingdrmer/xptemplate-dist.git
插件首页 Wiki

11.1、让Vim更好的支持XML和HTML

安装依旧是如此简单,从未繁琐过。

cd ~/.vim/bundle/
git clone https://github.com/sukima/xmledit.git
插件首页

12.1、pythoncomplete : Python Omni Completion 支持python补全

安装:

下载pythoncomplete放入~/.vim/autoload/或者$VIMRUNTIME/autoload/目录下即可。

请确保ftplugins已打开,即~/.vimrc已加入filetype plugin on

13.1、Vim的全能代码片段补全插件:snipMate,TextMate-style snippets for Vim

安装过程:

下载snipMate解压至~/.vim/目录下即可。

请确保ftplugins已打开,即~/.vimrc已加入filetype plugin on

14.1、Django的代码片段补全:

在安装好snipMate的基础上安装。

下载django.snippets和django_template.snippets放入~/.vim/snippets/目录下即可。

在~/.vimrc中加入:

autocmd FileType python set ft=python.django
autocmd FileType html set ft=htmldjango.html
15.1、Vim更好的格式化HTML代码

#suprsvn:在Vim中编辑HTML时也需要顺手给它格式化一下,以提高代码的可读性;但是Vim自带的gg=G只能够缩进,不能够依照HTML的格式来排版已完全打乱的HTML代码。

Ubuntu下需要安装tidy:

sudo apt-get install tidy
在~/.vimrc中加入:

map <C-F11> :!tidy -m -i -utf8 %<cr>  ""快捷键是ctrl+F11,可自行设置。
16.1、未完待续

持续更新 :-) ... ...
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics