From 100d8d2a47299172bf4b6d7e7d4cf398c19ceaa9 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Wed, 7 Jan 2009 21:43:15 +1300 Subject: [PATCH] add s and gs for vsplitting the current node --- plugin/NERD_tree.vim | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 360e5bc..2306bba 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -844,7 +844,7 @@ function! s:TreeFileNode.openSplit() " Attempt to go to adjacent window call s:exec(back) - let onlyOneWin = (winnr() == s:getTreeWinNum()) + let onlyOneWin = (winnr("$") == 1) " If no adjacent window, set splitright and splitbelow appropriately if onlyOneWin @@ -880,7 +880,21 @@ function! s:TreeFileNode.openSplit() let &splitbelow=savesplitbelow let &splitright=savesplitright endfunction +"FUNCTION: TreeFileNode.openVSplit() {{{3 +"Open this node in a new vertical window +function! s:TreeFileNode.openVSplit() + let winwidth = winwidth(".") + if winnr("$")==1 + let winwidth = g:NERDTreeWinSize + endif + exec "vsplit " . self.path.strForEditCmd() + + "resize the nerd tree back to the original size + call s:exec("wincmd p") + exec("silent vertical resize ". winwidth) + call s:exec('wincmd p') +endfunction "FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{3 "Places the cursor on the line number this node is rendered on " @@ -3022,12 +3036,16 @@ function! s:bindMappings() nnoremap <2-leftmouse> :call activateNode(0) exec "nnoremap ". g:NERDTreeMapActivateNode . " :call activateNode(0)" - exec "nnoremap ". g:NERDTreeMapOpenSplit ." :call openEntrySplit(0)" + exec "nnoremap ". g:NERDTreeMapOpenSplit ." :call openEntrySplit(0,0)" + + exec "nnoremap ". "s" ." :call openEntrySplit(1,0)" + exec "nnoremap ". "gs" ." :call previewNode(2)" exec "nnoremap ". g:NERDTreeMapPreview ." :call previewNode(0)" exec "nnoremap ". g:NERDTreeMapPreviewSplit ." :call previewNode(1)" + exec "nnoremap ". g:NERDTreeMapExecute ." :call executeNode()" exec "nnoremap ". g:NERDTreeMapOpenRecursively ." :call openNodeRecursively()" @@ -3363,7 +3381,7 @@ function! s:handleMiddleMouse() if curNode.path.isDirectory call s:openExplorer() else - call s:openEntrySplit(0) + call s:openEntrySplit(0,0) endif endfunction @@ -3475,16 +3493,20 @@ function! s:openBookmark(name) call targetNode.open() endif endfunction -" FUNCTION: s:openEntrySplit(forceKeepWindowOpen) {{{2 +" FUNCTION: s:openEntrySplit(vertical, forceKeepWindowOpen) {{{2 "Opens the currently selected file from the explorer in a "new window " "args: "forceKeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set -function! s:openEntrySplit(forceKeepWindowOpen) +function! s:openEntrySplit(vertical, forceKeepWindowOpen) let treenode = s:TreeFileNode.GetSelected() if treenode != {} - call treenode.openSplit() + if a:vertical + call treenode.openVSplit() + else + call treenode.openSplit() + endif if !a:forceKeepWindowOpen call s:closeTreeIfQuitOnOpen() endif @@ -3551,10 +3573,13 @@ function! s:openNodeRecursively() endfunction "FUNCTION: s:previewNode() {{{2 +"Args: +" openNewWin: if 0, use the previous window, if 1 open in new split, if 2 +" open in a vsplit function! s:previewNode(openNewWin) let currentBuf = bufnr("") - if a:openNewWin - call s:openEntrySplit(1) + if a:openNewWin > 0 + call s:openEntrySplit(a:openNewWin == 2,1) else call s:activateNode(1) end