Fixed vim and zsh

This commit is contained in:
2018-04-05 13:06:54 +02:00
parent f9db886bd3
commit 0331f6518a
2009 changed files with 256303 additions and 0 deletions

View File

@ -0,0 +1 @@
doc/tags

View File

@ -0,0 +1,113 @@
# vim-nerdtree-tabs changelog
## v1.4.7
* Add smart auto NERDTree open.
## v1.4.6
* Add NERDTreeTabsFind function.
## v1.4.5
* Add NERDTreeFocusToggle function. (Thanks orthez.)
* More general refactoring and cleanup. (Thanks techlivezheng.)
## v1.4.4
* Option to always focus file window after startup. (Thanks rr-.)
## v1.4.3
* Partial fix for #32. When directory is given as an argument, two nerdtrees
are open, but both now point into the correct directory. (Thanks szajbus.)
## v1.4.2
* Friendlier when using together with MiniBufExplorer. (Thanks techlivezheng.)
* Do not open NERDTree by default when starting Vim in diff mode. (Thanks
techlivezheng.)
## v1.4.1
* Fix "cd into" feature for paths that include spaces. (Thanks nybblr.)
## v1.4.0
* When synchronizing NERDTree scroll and cursor position, synchronize also
NERDTree window width. (Thanks EinfachToll.)
* When Vim is given a directory as a parameter, `:cd` into it. (Thanks DAddYE.)
* New commands `NERDTreeTabsOpen`, `NERDTreeTabsClose` and
`NERDTreeMirrorOpen`. They are not a new functionality, just externalize
stuff that was previously accessible only inside the plugin.
* New commands `NERDTreeSteppedOpen` and `NERDTreeSteppedClose` for combined
opening/closing of a NERDTree and focus switching. Works locally for a tab.
(Thanks ereOn.)
* Fixed an error when restoring a session caused by accessing an undefined
variable. (Thanks ereOn.)
* Fixed opening two NERDTrees when `NERDTreeHijackNetrw = 1` and launching
with a directory name as a parameter.
## v1.3.0
* Focus synchronization - ability to have focus on NERDTree after tab switch
if and only if it was focused before tab switch. Switched on by default.
## v1.2.1
* Smart startup focus fixed.
## v1.2.0
* Loading process refactoring (should fix some glitches and hopefully not
break anything else). Directory structure has changed in this release,
a new pull of the repository is required for the plugin to work properly.
## v1.1.2
* Smart focus - on startup, focus NERDTree if opening a directory, focus the
file when opening a file.
## v1.1.1
* About 50% speedup when toggling NERDTree on across all tabs.
## v1.1.0
* Meaningful tab names feature doesn't collide with opening new tabs silently.
To accomplish that, tab switching now preserves window focus. The original
behavior that always kept focus in the window with file being edited can be
restored by `let g:nerdtree_tabs_focus_on_files = 1`.
* Removed glitches when sourcing the plugin more than once.
## v1.0.1
* Plugin is usable with vundle.
## v1.0.0
* NERDTree view synchronization (cursor position and scroll) across tabs
* Fix: focus is now on NERDTree when opening it in all tabs.
* If you create more NERDTree instances, nerdtree-tabs now tries hard to sync
all tabs to the last opened one.
## v0.2.0
* Better solution for opening NERDTree on tab creation (fixes wrong behavior in
improbable situations)
* Global variables for configuration
* Tab autoclose
* Option to open NERDTree on console vim startup, stays false by default
* Readme
## v0.1.0
* New mappings and a command, otherwise original functionality preserved while making it namespaced

View File

@ -0,0 +1,175 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

View File

@ -0,0 +1,146 @@
# NERDTree and tabs together in Vim, painlessly
## Features
This plugin aims at making NERDTree feel like a true panel, independent of tabs.
* **Just one NERDTree**, always and ever. It will always look the same in
all tabs, including expanded/collapsed nodes, scroll position etc.
* Open in all tabs / close in all tabs. Do this via `:NERDTreeTabsToggle`
* Meaningful tab captions for inactive tabs. No more captions like 'NERD_tree_1'.
* When you close a file, the tab closes with it. No NERDTree hanging open.
* Autoopen NERDTree on GVim / MacVim startup.
Many of these features can be switched off. See section Configuration.
## Installation
1. If you haven't already, install NERDTree (see https://github.com/scrooloose/nerdtree)
2. Install the plugin **through Pathogen**:
cd ~/.vim/bundle
git clone https://github.com/jistr/vim-nerdtree-tabs.git
Or **through Vundle**:
Bundle 'jistr/vim-nerdtree-tabs'
Or **through Janus**:
cd ~/.janus
git clone https://github.com/jistr/vim-nerdtree-tabs.git
3. Map :NERDTreeTabsToggle command to some combo so you don't have to type it.
Alternatively, you can use plug-mapping instead of a command, like this:
map <Leader>n <plug>NERDTreeTabsToggle<CR>
4. Celebrate.
## Commands and Mappings
Vim-nerdtree-tabs provides these commands:
* `:NERDTreeTabsOpen` switches NERDTree on for all tabs.
* `:NERDTreeTabsClose` switches NERDTree off for all tabs.
* `:NERDTreeTabsToggle` toggles NERDTree on/off for all tabs.
* `:NERDTreeTabsFind` find currently opened file and select it
* `:NERDTreeMirrorOpen` acts as `:NERDTreeMirror`, but smarter: When opening,
it first tries to use an existing tree (i.e. previously closed in this tab or
perform a mirror of another tab's tree). If all this fails, a new tree is
created. It is recommended that you use this command instead of
`:NERDTreeMirror`.
* `:NERDTreeMirrorToggle` toggles NERDTree on/off in current tab, using
the same behavior as `:NERDTreeMirrorOpen`.
* `:NERDTreeSteppedOpen` focuses the NERDTree, opening one first if none is present.
* `:NERDTreeSteppedClose` unfocuses the NERDTree, or closes/hides it if it was
not focused.
* `:NERDTreeFocusToggle` focus the NERDTree or create it if focus is
on a file, unfocus NERDTree if focus is on NERDTree
There are also plug-mappings available with the same functionality:
* `<plug>NERDTreeTabsOpen`
* `<plug>NERDTreeTabsClose`
* `<plug>NERDTreeTabsToggle`
* `<plug>NERDTreeTabsFind`
* `<plug>NERDTreeMirrorOpen`
* `<plug>NERDTreeMirrorToggle`
* `<plug>NERDTreeSteppedOpen`
* `<plug>NERDTreeSteppedClose`
## Configuration
You can switch on/off some features of the plugin by setting global vars to 1
(for on) or 0 (for off) in your vimrc. Here are the options and their default
values:
* `g:nerdtree_tabs_open_on_gui_startup` (default: `1`)
Open NERDTree on gvim/macvim startup. (When set to `2`,
open only if directory was given as startup argument).
* `g:nerdtree_tabs_open_on_console_startup` (default: `0`)
Open NERDTree on console vim startup. (When set to `2`,
open only if directory was given as startup argument).
* `g:nerdtree_tabs_no_startup_for_diff` (default: `1`)
Do not open NERDTree if vim starts in diff mode
* `g:nerdtree_tabs_smart_startup_focus` (default: `1`)
On startup, focus NERDTree if opening a directory, focus file if opening
a file. (When set to `2`, always focus file window after startup).
* `g:nerdtree_tabs_open_on_new_tab` (default: `1`)
Open NERDTree on new tab creation (if NERDTree was globally opened by
:NERDTreeTabsToggle)
* `g:nerdtree_tabs_meaningful_tab_names` (default: `1`)
Unfocus NERDTree when leaving a tab for descriptive tab names
* `g:nerdtree_tabs_autoclose` (default: `1`)
Close current tab if there is only one window in it and it's NERDTree
* `g:nerdtree_tabs_synchronize_view` (default: `1`)
Synchronize view of all NERDTree windows (scroll and cursor position)
* `g:nerdtree_tabs_synchronize_focus` (default: `1`)
Synchronize focus when switching windows (focus NERDTree after tab switch
if and only if it was focused before tab switch)
* `g:nerdtree_tabs_focus_on_files` (default: `0`)
When switching into a tab, make sure that focus is on the file window,
not in the NERDTree window. (Note that this can get annoying if you use
NERDTree's feature "open in new tab silently", as you will lose focus on the
NERDTree.)
* `g:nerdtree_tabs_startup_cd` (default: `1`)
When given a directory name as a command line parameter when launching Vim,
`:cd` into it.
* `g:nerdtree_tabs_autofind` (default: `0`)
Automatically find and select currently opened file in NERDTree.
### Example
To run NERDTreeTabs on console vim startup, put into your .vimrc:
let g:nerdtree_tabs_open_on_console_startup=1
## Credits
The tab autoclose feature is stolen from Carl Lerche & Yehuda Katz's
[Janus](https://github.com/carlhuda/janus). Thanks, guys!

View File

@ -0,0 +1,123 @@
# NERDTree and tabs together in Vim, painlessly *vim-nerdtree-tabs*
*nerdtree-tabs*
## Installation
1. Copy the plugin to your vim config dir (via pathogen or any way you want).
2. Map :NERDTreeTabsToggle command to some combo so you don't have to type it.
Alternatively, you can use plug-mapping instead of a command, like this:
map <Leader>n <plug>NERDTreeTabsToggle<CR>
3. Celebrate.
## Features
In short, this vim plugin aims at making **NERDTree feel like a true panel**,
independent of tabs. That is done by keeping NERDTree synchronized between
tabs as much as possible. Read on for details.
### One command, open everywhere, close everywhere
You'll get a new command: `:NERDTreeTabsToggle`
For the needs of most of us, this will be the only command needed to operate
NERDTree. Press it once, NERDTree opens in all tabs (even in new tabs created
from now on); press it again, NERDTree closes in all tabs.
### Just one NERDTree
Tired of having a fully collapsed NERDTree every time you open a new tab?
Vim-nerdtree-tabs will keep them all synchronized. You will get just one
NERDTree buffer for all your tabs.
### Sync to the max
All NERDTree windows will always have the same scroll and cursor position.
### Meaningful tab captions
You know the feeling when you want to switch to *that file* and you have 8 tabs
open and they are all named 'NERD_tree_1'? Won't happen again. When leaving
a tab, vim-nerdtree-tabs moves focus out of NERDTree so that the tab caption is
the name of the file you are editing.
### Close the file = close the tab
A tab with NERDTree and a file won't hang open when you close the file window.
NERDTree will close automatically and so will the tab.
### Autoopen on startup
NERDTree will open automatically on GVim/MacVim startup. You can configure it
to open on console Vim as well, but this is disabled by default.
## Commands and mappings
Vim-nerdtree-tabs defines two commands:
*:NERDTreeTabsToggle*
* `:NERDTreeTabsToggle` switches NERDTree on/off for all tabs.
*:NERDTreeMirrorToggle*
* `:NERDTreeMirrorToggle` acts as `:NERDTreeToggle`, but smarter: When opening,
it first tries to use an existing tree (i.e. previously closed in this tab or
perform a mirror of another tab's tree). If all this fails, a new tree is
created. **It is recommended that you always use this command instead of
`:NERDTreeToggle`.**
There are also plug-mappings available with the same functionality:
* `<plug>NERDTreeTabsToggle`
* `<plug>NERDTreeMirrorToggle`
## Configuration
You can switch on/off some features of the plugin by setting global vars to 1
(for on) or 0 (for off) in your vimrc. Here are the options and their default
values:
* `let g:nerdtree_tabs_open_on_gui_startup = 1`
Open NERDTree on gvim/macvim startup
* `let g:nerdtree_tabs_open_on_console_startup = 0`
Open NERDTree on console vim startup
* `let g:nerdtree_tabs_no_startup_for_diff = 1`
Do not open NERDTree if vim starts in diff mode
* `let g:nerdtree_tabs_smart_startup_focus = 1`
On startup - focus NERDTree when opening a directory, focus the file if
editing a specified file. When set to `2`, always focus file after startup.
* `let g:nerdtree_tabs_open_on_new_tab = 1`
Open NERDTree on new tab creation (if NERDTree was globally opened by
:NERDTreeTabsToggle)
* `let g:nerdtree_tabs_meaningful_tab_names = 1`
Unfocus NERDTree when leaving a tab for descriptive tab names
* `let g:nerdtree_tabs_autoclose = 1`
Close current tab if there is only one window in it and it's NERDTree
* `let g:nerdtree_tabs_synchronize_view = 1`
Synchronize view of all NERDTree windows (scroll and cursor position)
* `let g:nerdtree_tabs_synchronize_focus = 1`
Synchronize focus when switching tabs (focus NERDTree after tab switch
if and only if it was focused before tab switch)
* `let g:nerdtree_tabs_focus_on_files = 0`
When switching into a tab, make sure that focus is on the file window,
not in the NERDTree window. (Note that this can get annoying if you use
NERDTree's feature "open in new tab silently", as you will lose focus on the
NERDTree.)
* `g:nerdtree_tabs_startup_cd = 1`
When starting up with a directory name as a parameter, cd into it
## Credits
* The tab autoclose feature is stolen from Carl Lerche & Yehuda Katz's
[Janus](https://github.com/carlhuda/janus). Thanks, guys!

View File

@ -0,0 +1,631 @@
" === plugin configuration variables === {{{
"
" Open NERDTree on gvim/macvim startup. When set to `2`,
" open only if directory was given as startup argument.
if !exists('g:nerdtree_tabs_open_on_gui_startup')
let g:nerdtree_tabs_open_on_gui_startup = 1
endif
" Open NERDTree on console vim startup (off by default). When set to `2`,
" open only if directory was given as startup argument.
if !exists('g:nerdtree_tabs_open_on_console_startup')
let g:nerdtree_tabs_open_on_console_startup = 0
endif
" do not open NERDTree if vim starts in diff mode
if !exists('g:nerdtree_tabs_no_startup_for_diff')
let g:nerdtree_tabs_no_startup_for_diff = 1
endif
" On startup - focus NERDTree when opening a directory, focus the file if
" editing a specified file. When set to `2`, always focus file after startup.
if !exists('g:nerdtree_tabs_smart_startup_focus')
let g:nerdtree_tabs_smart_startup_focus = 1
endif
" Open NERDTree on new tab creation if NERDTree was globally opened
" by :NERDTreeTabsToggle
if !exists('g:nerdtree_tabs_open_on_new_tab')
let g:nerdtree_tabs_open_on_new_tab = 1
endif
" unfocus NERDTree when leaving a tab so that you have descriptive tab names
" and not names like 'NERD_tree_1'
if !exists('g:nerdtree_tabs_meaningful_tab_names')
let g:nerdtree_tabs_meaningful_tab_names = 1
endif
" close current tab if there is only one window in it and it's NERDTree
if !exists('g:nerdtree_tabs_autoclose')
let g:nerdtree_tabs_autoclose = 1
endif
" synchronize view of all NERDTree windows (scroll and cursor position)
if !exists('g:nerdtree_tabs_synchronize_view')
let g:nerdtree_tabs_synchronize_view = 1
endif
" synchronize focus when switching tabs (focus NERDTree after tab switch
" if and only if it was focused before tab switch)
if !exists('g:nerdtree_tabs_synchronize_focus')
let g:nerdtree_tabs_synchronize_focus = 1
endif
" when switching into a tab, make sure that focus will always be in file
" editing window, not in NERDTree window (off by default)
if !exists('g:nerdtree_tabs_focus_on_files')
let g:nerdtree_tabs_focus_on_files = 0
endif
" when starting up with a directory name as a parameter, cd into it
if !exists('g:nerdtree_tabs_startup_cd')
let g:nerdtree_tabs_startup_cd = 1
endif
" automatically find and select currently opened file
if !exists('g:nerdtree_tabs_autofind')
let g:nerdtree_tabs_autofind = 0
endif
"
" }}}
" === plugin mappings === {{{
"
noremap <silent> <script> <Plug>NERDTreeTabsOpen :call <SID>NERDTreeOpenAllTabs()
noremap <silent> <script> <Plug>NERDTreeTabsClose :call <SID>NERDTreeCloseAllTabs()
noremap <silent> <script> <Plug>NERDTreeTabsToggle :call <SID>NERDTreeToggleAllTabs()
noremap <silent> <script> <Plug>NERDTreeTabsFind :call <SID>NERDTreeFindFile()
noremap <silent> <script> <Plug>NERDTreeMirrorOpen :call <SID>NERDTreeMirrorOrCreate()
noremap <silent> <script> <Plug>NERDTreeMirrorToggle :call <SID>NERDTreeMirrorToggle()
noremap <silent> <script> <Plug>NERDTreeSteppedOpen :call <SID>NERDTreeSteppedOpen()
noremap <silent> <script> <Plug>NERDTreeSteppedClose :call <SID>NERDTreeSteppedClose()
noremap <silent> <script> <Plug>NERDTreeFocusToggle :call <SID>NERDTreeFocusToggle()
"
" }}}
" === plugin commands === {{{
"
command! NERDTreeTabsOpen call <SID>NERDTreeOpenAllTabs()
command! NERDTreeTabsClose call <SID>NERDTreeCloseAllTabs()
command! NERDTreeTabsToggle call <SID>NERDTreeToggleAllTabs()
command! NERDTreeTabsFind call <SID>NERDTreeFindFile()
command! NERDTreeMirrorOpen call <SID>NERDTreeMirrorOrCreate()
command! NERDTreeMirrorToggle call <SID>NERDTreeMirrorToggle()
command! NERDTreeSteppedOpen call <SID>NERDTreeSteppedOpen()
command! NERDTreeSteppedClose call <SID>NERDTreeSteppedClose()
command! NERDTreeFocusToggle call <SID>NERDTreeFocusToggle()
"
" }}}
" === plugin functions === {{{
"
" === NERDTree manipulation (opening, closing etc.) === {{{
"
" s:NERDTreeMirrorOrCreate() {{{
"
" switch NERDTree on for current tab -- mirror it if possible, otherwise create it
fun! s:NERDTreeMirrorOrCreate()
let l:nerdtree_open = s:IsNERDTreeOpenInCurrentTab()
" if NERDTree is not active in the current tab, try to mirror it
if !l:nerdtree_open
let l:previous_winnr = winnr("$")
silent NERDTreeMirror
" if the window count of current tab didn't increase after NERDTreeMirror,
" it means NERDTreeMirror was unsuccessful and a new NERDTree has to be created
if l:previous_winnr == winnr("$")
silent NERDTreeToggle
endif
endif
endfun
" }}}
" s:NERDTreeMirrorToggle() {{{
"
" toggle NERDTree in current tab, use mirror if possible
fun! s:NERDTreeMirrorToggle()
let l:nerdtree_open = s:IsNERDTreeOpenInCurrentTab()
if l:nerdtree_open
silent NERDTreeClose
else
call s:NERDTreeMirrorOrCreate()
endif
endfun
" }}}
" s:NERDTreeOpenAllTabs() {{{
"
" switch NERDTree on for all tabs while making sure there is only one NERDTree buffer
fun! s:NERDTreeOpenAllTabs()
let s:nerdtree_globally_active = 1
" tabdo doesn't preserve current tab - save it and restore it afterwards
let l:current_tab = tabpagenr()
tabdo call s:NERDTreeMirrorOrCreate()
exe 'tabn ' . l:current_tab
endfun
" }}}
" s:NERDTreeCloseAllTabs() {{{
"
" close NERDTree across all tabs
fun! s:NERDTreeCloseAllTabs()
let s:nerdtree_globally_active = 0
" tabdo doesn't preserve current tab - save it and restore it afterwards
let l:current_tab = tabpagenr()
tabdo silent NERDTreeClose
exe 'tabn ' . l:current_tab
endfun
" }}}
" s:NERDTreeToggleAllTabs() {{{
"
" toggle NERDTree in current tab and match the state in all other tabs
fun! s:NERDTreeToggleAllTabs()
let l:nerdtree_open = s:IsNERDTreeOpenInCurrentTab()
let s:disable_handlers_for_tabdo = 1
if l:nerdtree_open
call s:NERDTreeCloseAllTabs()
else
call s:NERDTreeOpenAllTabs()
" force focus to NERDTree in current tab
if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1
exe bufwinnr(t:NERDTreeBufName) . "wincmd w"
endif
endif
let s:disable_handlers_for_tabdo = 0
endfun
" }}}
" s:NERDTreeSteppedOpen() {{{
"
" focus the NERDTree view, creating one first if none is present
fun! s:NERDTreeSteppedOpen()
if !s:IsCurrentWindowNERDTree()
if s:IsNERDTreeOpenInCurrentTab()
call s:NERDTreeFocus()
else
call s:NERDTreeMirrorOrCreate()
endif
endif
endfun
" }}}
" s:NERDTreeSteppedClose{() {{{
"
" unfocus the NERDTree view or closes it if it hadn't had focus at the time of
" the call
fun! s:NERDTreeSteppedClose()
if s:IsCurrentWindowNERDTree()
call s:NERDTreeUnfocus()
else
let l:nerdtree_open = s:IsNERDTreeOpenInCurrentTab()
if l:nerdtree_open
silent NERDTreeClose
endif
endif
endfun
" }}}
" s:NERDTreeFocusToggle() {{{
"
" focus the NERDTree view or creates it if in a file,
" or unfocus NERDTree view if in NERDTree
fun! s:NERDTreeFocusToggle()
let s:disable_handlers_for_tabdo = 1
if s:IsCurrentWindowNERDTree()
call s:NERDTreeUnfocus()
else
if !s:IsNERDTreeOpenInCurrentTab()
call s:NERDTreeOpenAllTabs()
endif
call s:NERDTreeFocus()
endif
let s:disable_handlers_for_tabdo = 0
endfun
" }}}
"
" === NERDTree manipulation (opening, closing etc.) === }}}
" === focus functions === {{{
"
" s:NERDTreeFocus() {{{
"
" if the current window is NERDTree, move focus to the next window
fun! s:NERDTreeFocus()
if !s:IsCurrentWindowNERDTree() && exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1
exe bufwinnr(t:NERDTreeBufName) . "wincmd w"
endif
endfun
" }}}
" s:NERDTreeUnfocus() {{{
"
" if the current window is NERDTree, move focus to the next window
fun! s:NERDTreeUnfocus()
" save current window so that it's focus can be restored after switching
" back to this tab
let t:NERDTreeTabLastWindow = winnr()
if s:IsCurrentWindowNERDTree()
let l:winNum = s:NextNormalWindow()
if l:winNum != -1
exec l:winNum.'wincmd w'
else
wincmd w
endif
endif
endfun
" }}}
" s:NERDTreeRestoreFocus() {{{
"
" restore focus to the window that was focused before leaving current tab
fun! s:NERDTreeRestoreFocus()
if g:nerdtree_tabs_synchronize_focus
if s:is_nerdtree_globally_focused
call s:NERDTreeFocus()
elseif exists("t:NERDTreeTabLastWindow") && exists("t:NERDTreeBufName") && t:NERDTreeTabLastWindow != bufwinnr(t:NERDTreeBufName)
exe t:NERDTreeTabLastWindow . "wincmd w"
endif
elseif exists("t:NERDTreeTabLastWindow")
exe t:NERDTreeTabLastWindow . "wincmd w"
endif
endfun
" }}}
" s:SaveGlobalFocus() {{{
"
fun! s:SaveGlobalFocus()
let s:is_nerdtree_globally_focused = s:IsCurrentWindowNERDTree()
endfun
" }}}
" s:IfFocusOnStartup() {{{
"
fun! s:IfFocusOnStartup()
return strlen(bufname('$')) == 0 || !getbufvar('$', '&modifiable')
endfun
" }}}
"
" === focus functions === }}}
" === utility functions === {{{
"
" s:NextNormalWindow() {{{
"
" find next window with a normal buffer
fun! s:NextNormalWindow()
let l:i = 1
while(l:i <= winnr('$'))
let l:buf = winbufnr(l:i)
" skip unlisted buffers
if buflisted(l:buf) == 0
let l:i = l:i + 1
continue
endif
" skip un-modifiable buffers
if getbufvar(l:buf, '&modifiable') != 1
let l:i = l:i + 1
continue
endif
" skip temporary buffers with buftype set
if empty(getbufvar(l:buf, "&buftype")) != 1
let l:i = l:i + 1
continue
endif
return l:i
endwhile
return -1
endfun
" }}}
" s:CloseIfOnlyNerdTreeLeft() {{{
"
" Close all open buffers on entering a window if the only
" buffer that's left is the NERDTree buffer
fun! s:CloseIfOnlyNerdTreeLeft()
if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1 && winnr("$") == 1
q
endif
endfun
" }}}
" s:IsCurrentWindowNERDTree() {{{
"
" returns 1 if current window is NERDTree, false otherwise
fun! s:IsCurrentWindowNERDTree()
return exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) == winnr()
endfun
" }}}
" s:IsNERDTreeOpenInCurrentTab() {{{
"
" check if NERDTree is open in current tab
fun! s:IsNERDTreeOpenInCurrentTab()
return exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1
endfun
" }}}
" s:IsNERDTreePresentInCurrentTab() {{{
"
" check if NERDTree is present in current tab (not necessarily visible)
fun! s:IsNERDTreePresentInCurrentTab()
return exists("t:NERDTreeBufName")
endfun
" }}}
"
" === utility functions === }}}
" === NERDTree view manipulation (scroll and cursor positions) === {{{
"
" s:SaveNERDTreeViewIfPossible() {{{
"
fun! s:SaveNERDTreeViewIfPossible()
if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) == winnr()
" save scroll and cursor etc.
let s:nerdtree_view = winsaveview()
" save NERDTree window width
let s:nerdtree_width = winwidth(winnr())
" save buffer name (to be able to correct desync by commands spawning
" a new NERDTree instance)
let s:nerdtree_buffer = bufname("%")
endif
endfun
" }}}
" s:RestoreNERDTreeViewIfPossible() {{{
"
fun! s:RestoreNERDTreeViewIfPossible()
" if nerdtree exists in current tab, it is the current window and if saved
" state is available, restore it
let l:view_state_saved = exists('s:nerdtree_view') && exists('s:nerdtree_width')
if s:IsNERDTreeOpenInCurrentTab() && l:view_state_saved
let l:current_winnr = winnr()
let l:nerdtree_winnr = bufwinnr(t:NERDTreeBufName)
" switch to NERDTree window
exe l:nerdtree_winnr . "wincmd w"
" load the correct NERDTree buffer if not already loaded
if exists('s:nerdtree_buffer') && t:NERDTreeBufName != s:nerdtree_buffer
silent NERDTreeClose
silent NERDTreeMirror
endif
" restore cursor, scroll and window width
call winrestview(s:nerdtree_view)
exe "vertical resize " . s:nerdtree_width
" switch back to whatever window was focused before
exe l:current_winnr . "wincmd w"
endif
endfun
" }}}
" s:NERDTreeFindFile() {{{
"
fun! s:NERDTreeFindFile()
if s:IsNERDTreeOpenInCurrentTab()
silent NERDTreeFind
endif
endfun
" }}}
"
" === NERDTree view manipulation (scroll and cursor positions) === }}}
"
" === plugin functions === }}}
" === plugin event handlers === {{{
"
" s:LoadPlugin() {{{
"
fun! s:LoadPlugin()
if exists('g:nerdtree_tabs_loaded')
return
endif
let g:NERDTreeHijackNetrw = 0
let s:disable_handlers_for_tabdo = 0
" global on/off NERDTree state
" the exists check is to enable script reloading without resetting the state
if !exists('s:nerdtree_globally_active')
let s:nerdtree_globally_active = 0
endif
" global focused/unfocused NERDTree state
" the exists check is to enable script reloading without resetting the state
if !exists('s:is_nerdtree_globally_focused')
call s:SaveGlobalFocus()
end
augroup NERDTreeTabs
autocmd!
autocmd VimEnter * call <SID>VimEnterHandler()
autocmd TabEnter * call <SID>TabEnterHandler()
autocmd TabLeave * call <SID>TabLeaveHandler()
autocmd WinEnter * call <SID>WinEnterHandler()
autocmd WinLeave * call <SID>WinLeaveHandler()
autocmd BufWinEnter * call <SID>BufWinEnterHandler()
autocmd BufRead * call <SID>BufReadHandler()
augroup END
let g:nerdtree_tabs_loaded = 1
endfun
" }}}
" s:VimEnterHandler() {{{
"
fun! s:VimEnterHandler()
let l:open_nerd_tree_on_startup = (g:nerdtree_tabs_open_on_console_startup == 1 && !has('gui_running')) ||
\ (g:nerdtree_tabs_open_on_gui_startup == 1 && has('gui_running'))
let l:open_directory_on_startup = isdirectory(argv(0)) &&
\ ((g:nerdtree_tabs_open_on_console_startup == 2 && !has('gui_running')) ||
\ (g:nerdtree_tabs_open_on_gui_startup == 2 && has('gui_running')))
if g:nerdtree_tabs_no_startup_for_diff && &diff
let l:open_nerd_tree_on_startup = 0
endif
" this makes sure that globally_active is true when using 'gvim .'
let s:nerdtree_globally_active = l:open_nerd_tree_on_startup
" if the argument to vim is a directory, cd into it
if l:open_directory_on_startup || g:nerdtree_tabs_startup_cd && isdirectory(argv(0))
exe 'cd ' . escape(argv(0), '\ ')
endif
if l:open_nerd_tree_on_startup || l:open_directory_on_startup
let l:focus_file = !s:IfFocusOnStartup()
let l:main_bufnr = bufnr('%')
if !s:IsNERDTreePresentInCurrentTab()
call s:NERDTreeOpenAllTabs()
endif
if (l:focus_file && g:nerdtree_tabs_smart_startup_focus == 1) ||
\ g:nerdtree_tabs_smart_startup_focus == 2 ||
\ l:open_directory_on_startup
exe bufwinnr(l:main_bufnr) . "wincmd w"
endif
if l:open_directory_on_startup
" close buffer not connected to NERDTree and open connected one
new
exe bufwinnr(l:main_bufnr) . "wincmd w"
quit
if g:nerdtree_tabs_smart_startup_focus != 2
NERDTreeFocus
endif
endif
if g:nerdtree_tabs_autofind
call s:NERDTreeFindFile()
call s:NERDTreeUnfocus()
endif
endif
endfun
" }}} s:NewTabCreated {{{
"
" A flag to indicate that a new tab has just been created.
"
" We will handle the remaining work for this newly created tab separately in
" BufWinEnter event.
"
let s:NewTabCreated = 0
" }}}
" s:TabEnterHandler() {{{
"
fun! s:TabEnterHandler()
if s:disable_handlers_for_tabdo
return
endif
if g:nerdtree_tabs_open_on_new_tab && s:nerdtree_globally_active && !s:IsNERDTreeOpenInCurrentTab()
call s:NERDTreeMirrorOrCreate()
" move focus to the previous window
wincmd p
" Turn on the 'NewTabCreated' flag
let s:NewTabCreated = 1
endif
if g:nerdtree_tabs_synchronize_view
call s:RestoreNERDTreeViewIfPossible()
endif
if g:nerdtree_tabs_focus_on_files
call s:NERDTreeUnfocus()
" Do not restore focus on newly created tab here
elseif !s:NewTabCreated
call s:NERDTreeRestoreFocus()
endif
endfun
" }}}
" s:TabLeaveHandler() {{{
"
fun! s:TabLeaveHandler()
if g:nerdtree_tabs_meaningful_tab_names
call s:SaveGlobalFocus()
call s:NERDTreeUnfocus()
endif
endfun
" }}}
" s:WinEnterHandler() {{{
"
fun! s:WinEnterHandler()
if s:disable_handlers_for_tabdo
return
endif
if g:nerdtree_tabs_autoclose
call s:CloseIfOnlyNerdTreeLeft()
endif
endfun
" }}}
" s:WinLeaveHandler() {{{
"
fun! s:WinLeaveHandler()
if s:disable_handlers_for_tabdo
return
endif
if g:nerdtree_tabs_synchronize_view
call s:SaveNERDTreeViewIfPossible()
endif
endfun
" }}}
" s:BufWinEnterHandler() {{{
"
" BufWinEnter event only gets triggered after a new buffer has been
" successfully loaded, it is a proper time to finish the remaining
" work for newly opened tab.
"
fun! s:BufWinEnterHandler()
if s:NewTabCreated
" Turn off the 'NewTabCreated' flag
let s:NewTabCreated = 0
" Restore focus to NERDTree if necessary
if !g:nerdtree_tabs_focus_on_files
call s:NERDTreeRestoreFocus()
endif
endif
endfun
" }}}
" s:BufReadHandler() {{{
"
" BufRead event gets triggered after a new buffer has been
" successfully read from file.
"
fun! s:BufReadHandler()
" Refresh NERDTree to show currently opened file
if g:nerdtree_tabs_autofind
call s:NERDTreeFindFile()
call s:NERDTreeUnfocus()
endif
endfun
" }}}
"
" === plugin event handlers === }}}
call s:LoadPlugin()