• vim---打造Python IDE


    1.文法高亮

      为了能在Vim中支持Python文法需要用到插件python.vim,该插件默认位于(/usr/share/vim/vim72/)<Vim安装目录>/<$VIMRUNTIME>/syntax/下,如果你在该路径下没有找到这个插件,需要到python.vim : Enhanced version of the python syntax highlighting script下载。然后为了能让Vim识别Python文法需要在vimrc中添加:

    set filetype=python
    au BufNewFile,BufRead
    *.py,*.pyw setf python

    2.缩进

      在vimrc(/etc/)中添加如下缩进相关的代码:

    set autoindent " same level indent
    set smartindent " next level indent
    set expandtab
    set tabstop
    =4
    set shiftwidth
    =4
    set softtabstop
    =4

    3.项目视图

      像Visual Studio或Eclipse之类的IDE都会提供项目视图(位于左侧或右侧),程序员利用该视图在文件间或类间跳转。利用Ctags和插件Tasklist可以在vim中实现此功能。

    • 首先下载Exuberant Ctags
    • 然后解压Ctags,并进入解压后的目录,利用如下命令编译安装Ctags:
    ./configure && sudo make install
    • 通过这种方式,Ctags被安装在/usr/local/bin下。接下来在vimrc中添加如下命令告诉Vim Ctags的安装路径:
       
     """"""""""""""""""""""""""""""
       " Tag list (ctags)
       """"""""""""""""""""""""""""""
       if MySys() == "windows"                "设定windows系统中ctags程序的位置
         let Tlist_Ctags_Cmd = 'ctags'
       elseif MySys() == "linux"              "设定windows系统中ctags程序的位置
         let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
       endif
       let Tlist_Show_One_File = 1            "不同时显示多个文件的tag,只显示当前文件的
       let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口,则退出vim
       let Tlist_Use_Right_Window = 1         "在右侧窗口中显示taglist窗口

    在taglist窗口中,可以使用下面的快捷键:

    <CR>          跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
    o             在一个新打开的窗口中显示光标下tag
    <Space>       显示光标下tag的原型定义
    u             更新taglist窗口中的tag
    s             更改排序方式,在按名字排序和按出现顺序排序间切换
    x             taglist窗口放大和缩小,方便查看较长的tag
    +             打开一个折叠,同zo
    -             将tag折叠起来,同zc
    *             打开所有的折叠,同zR
    =             将所有tag折叠起来,同zM
    [[            跳到前一个文件
    ]]            跳到后一个文件
    q             关闭taglist窗口
    <F1>          显示帮助 

    可以用”:TlistOpen“打开taglist窗口,用”:TlistClose“关闭taglist窗口。或者使用”:TlistToggle“在打开和关闭间切换。

    • 接着安装Tasklist插件:下载TaskList.vim,然后把它放入plugin目录下
    • 最后使用命令:TlistToggle打开taglist窗口,下图展示了该窗口。4.MiniBufExplorer
    •   在Visual Studio或Eclipse中你打开的缓存会以tab的形式列在窗口的顶端或底部,在Vim中插件MiniBufExplorer来实现此功能。下载minibufexpl.vim并将其放在plugin目录下。接着在vimrc中添加如下命令:

      let g:miniBufExplMapWindowNavVim =1
      let g:miniBufExplMapWindowNavArrows
      =1
      let g:miniBufExplMapCTabSwitchBufs
      =1
      let g:miniBufExplModSelTarget
      =1

        下图展示了MiniBufExplorer的使用效果:

      5.Omnicompletion

        Vim7中添加了对文法提示和自动完成的支持,对于python来说需下载pythoncomplete.vim并将其放在<Vim安装目录>/<$VIMRUNTIME>/autoload/目录下,接着在vimrc中添加如下命令:

      filetype plugin on
      set ofu
      =syntaxcomplete#Complete
      autocmd FileType python set
      omnifunc
      =pythoncomplete#Complete
      autocmd FileType python runtime! autoload/pythoncomplete.vim

        最后在编写代码时通过ctrl-x ctrl-o来打开文法提示上下文菜单,如下图所示:

      参考文献

      1.http://www.swaroopch.com/notes/Vim

      2.http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/

      3.http://www.phacks.net/macvim-code-completion-syntax-highlighting-for-python-pyqt4-twisted-on-mac-osx-snow-leopard/

      4.http://vim.wikia.com/wiki/Omni_completion

  • 相关阅读:
    KMP算法中next数组的构建
    vijos 1243 生产产品
    codeforces 557E Ann and Half-Palindrome
    codeforces 557D Vitaly and Cycle
    vijos 1054 牛场围栏 【想法题】
    oracle数据库基本操作
    一位90后程序员的自述:如何从年薪3w到30w
    Oracle 树操作(select…start with…connect by…prior)
    oracle中的条件语句
    重置按钮_reset
  • 原文地址:https://www.cnblogs.com/WayneZeng/p/3141795.html
Copyright © 2020-2023  润新知