How to use Vim like an IDE

2 篇文章 0 订阅
原文见:http://www.vim.org/tips/tip.php?tip_id=1119
created: February 3, 2006 20:51    complexity: intermediate
author: Matt Zyzik    as of Vim: 6.0
 
I personally use Vim for all text editing, even software development. At one point I stopped using IDEs. One major reason is that Vim can do all the major things I need from IDEs (tabs, file trees, greping, syntax highlighting, indentation, completion, "quickfix"ing, etc.). Vim 7 will be introducing one of the most critical features: completion (intellisense).

Still Vim needs plugins to do some IDE-like things that aren't built in.
One thing you might want is the vtreeexplorer (http://vim.org/scripts/script.php?script_id=184) plugin, which allows you to have a "file list" in a vertically split window. Another thing worth considering is the minibufexpl (http://vim.org/scripts/script.php?script_id=159) plugin, which will allow for tabs of all your files (works really well).

Yet another thing is in a former tip of mine (http://www.vim.org/tips/tip.php?tip_id=1078), which allows you to delete a buffer without actually closing the window. Also, below, I have a new, more complicated version of it. The below script will actually create a scratch buffer if there are no listed buffers left. The script, in addition, takes care of a small annoyance. Before, if you 1) open vim, 2) :e a file, 3) :bd, 4) :e the same file... then there will be two buffers listed (that file and a [no name] buffer). The following script ensures this doesn't happen.

(Everything in this tutorial and in most of my other tips/tutorials assumes the user does "set hidden".)
Using this Kwbd function (:call Kwbd(1)) will make Vim behave like an IDE; or maybe even better.

" here is a more exotic version of my original Kwbd script
"
delete the buffer; keep windows; create a scratch buffer if no buffers left
function Kwbd(kwbdStage)
    
if (a:kwbdStage  ==   1 )
        
if (!buflisted(winbufnr(0)))
            bd!
            
return
        endif
        let g:kwbdBufNum 
=  bufnr( " % " )
        let g:kwbdWinNum 
=  winnr()
        windo call Kwbd(
2 )
        execute 
" normal  "  . g:kwbdWinNum .  ""
        let g:buflistedLeft 
=  0
        let g:bufFinalJump 
=  0
        let l:nBufs 
=  bufnr( " $ " )
        let l:i 
=   1
        
while (l:i  <=  l:nBufs)
            
if (l:i  !=  g:kwbdBufNum)
                
if (buflisted(l:i))
                    let g:buflistedLeft 
=  g:buflistedLeft  +   1
                
else
                    
if (bufexists(l:i)  &&  !strlen(bufname(l:i))  &&  !g:bufFinalJump)
                        let g:bufFinalJump 
=  l:i
                    endif
                endif
            endif
            let l:i 
=  l:i  +   1
        endwhile
        
if (!g:buflistedLeft)
            
if (g:bufFinalJump)
                windo 
if (buflisted(winbufnr(0)))  |  execute  " b!  "  . g:bufFinalJump  |  endif
            
else
                enew
                let l:newBuf 
=  bufnr( " % " )
                windo 
if (buflisted(winbufnr(0)))  |  execute  " b!  "  . l:newBuf  |  endif
            endif
            execute 
" normal  "  . g:kwbdWinNum .  ""
        endif
        
if (buflisted(g:kwbdBufNum)  ||  g:kwbdBufNum  ==  bufnr( " % " ))
            execute 
" bd!  "  . g:kwbdBufNum
        endif
        
if (!g:buflistedLeft)
            set buflisted
            set bufhidden
= delete
            set buftype
= nofile
            setlocal noswapfile
            normal athis 
is  the scratch buffer
        endif
    
else
        
if (bufnr( " % " ==  g:kwbdBufNum)
            let prevbufvar 
=  bufnr( " # " )
            
if (prevbufvar  >  0  &&  buflisted(prevbufvar)  &&  prevbufvar  !=  g:kwbdBufNum)
                b 
#
             else
                bn
            endif
        endif
    endif
endfunction 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值