From: AJ ONeal Date: Mon, 22 Mar 2021 20:53:41 +0000 (+0000) Subject: add vim-nerdtree X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=9296d130c04078b63d1f6980be33b005cb3f33f5;p=webi-installers%2F.git add vim-nerdtree --- diff --git a/vim-nerdtree/README.md b/vim-nerdtree/README.md new file mode 100644 index 0000000..cca7f47 --- /dev/null +++ b/vim-nerdtree/README.md @@ -0,0 +1,89 @@ +--- +title: vim-nerdtree +homepage: https://github.com/preservim/nerdtree +tagline: | + NERDTree: A tree explorer plugin for vim. +--- + +To update (replacing the current version) run `webi vim-nerdtree`. + +## Cheat Sheet + +![](https://raw.githubusercontent.com/preservim/nerdtree/master/screenshot.png) + +> The NERDTree is a file system explorer for the Vim editor. Using this plugin, +> users can visually browse complex directory hierarchies, quickly open files +> for reading or editing, and perform basic file system operations. + +This installer also includes a few reasonable defaults from the project's +README: + +| Key | Action | +| ---------------------------- | -------------------------------------------------------------------- | +| **Global Key Bindings** | | +| `n` | Move cursor to NERDTree | +| `+t`
or ``t | Toggle NERDTree window on/off | +| `+f`
or ``f | Move to current file in NERDTree | +| **NERDTree Window Bindings** | | +| `o` | Open a directory to reveal children | +| `x` | Close directory and go to parent | +| `shift+o` | Open directory and all children dirs, recursively | +| `shift+x` | Close all child directories, recursively | +| `p` | Go to **p**arent directory | +| `gt` | Go to next Tab (`gT` for previous, naturally) | +| `/` | Search matches of visible files
(use `shift+o` first to see all) | +| **Normal Vim Stuff** | | +| `ctrl+w`, w | Rotate between open windows | +| `:e **/api.js` | Open and edit file matching api.js, in any subfolder | + +(if you've installed [`vim-leader`](../vim-leader) then `` is Space) + +### How to install and configure manually + +Place NerdTree into your `~/.vim/pack/plugins/start`: + +```bash +mkdir -p ~/.vim/pack/plugins/start/ +git clone --depth=1 https://github.com/preservim/nerdtree.git ~/.vim/pack/plugins/start/nerdtree +``` + +Create the file `~/.vim/plugins/nerdtree.vim`. Add the same contents as +. + +That will look something like this: + +`~/.vim/plugins/nerdtree.vim`: + +```vim +" default mappings for nerdtree +nnoremap n :NERDTreeFocus +nnoremap :NERDTree +nnoremap :NERDTreeToggle +nnoremap :NERDTreeFind + +" also map with Leader, since ctrl is hard to reach on Mac +nnoremap t :NERDTreeToggle +nnoremap f :NERDTreeFind + +" show hidden files +let NERDTreeShowHidden=1 + +" keep ignoring .git, node_modules, vendor, and dist +let NERDTreeIgnore=["\.git", "node_modules", "vendor", "dist"] + +" Start NERDTree when Vim is started without file arguments. +autocmd StdinReadPre * let s:std_in=1 +autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif + +" Exit Vim if NERDTree is the only window left. +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | + \ quit | endif + +``` + +You'll then need to update `~/.vimrc` to source that plugin: + +```vim +" nerdtree: reasonable defaults from webinstall.dev/vim-nerdtree +source ~/.vim/plugins/nerdtree.vim +``` diff --git a/vim-nerdtree/install.ps1 b/vim-nerdtree/install.ps1 new file mode 100644 index 0000000..2f0ab09 --- /dev/null +++ b/vim-nerdtree/install.ps1 @@ -0,0 +1,7 @@ +#!/usr/bin/env pwsh + +IF (!(Test-Path -Path "$Env:USERPROFILE\.vim\pack\plugins\start")) { + New-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start" -ItemType Directory -Force +} +Remove-Item -Path "$Env:USERPROFILE\.vim\pack\plugins\start\nerdtree" -Recurse -ErrorAction Ignore +& git clone --depth=1 https://github.com/preservim/nerdtree.git "$Env:USERPROFILE\.vim\pack\plugins\start\nerdtree.vim" diff --git a/vim-nerdtree/install.sh b/vim-nerdtree/install.sh new file mode 100644 index 0000000..a6ce3b6 --- /dev/null +++ b/vim-nerdtree/install.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +function __init_vim_nerdtree() { + set -e + set -u + + mkdir -p "$HOME/.vim/pack/plugins/start" + rm -rf "$HOME/.vim/pack/plugins/start/nerdtree.vim" + git clone --depth=1 https://github.com/preservim/nerdtree.git "$HOME/.vim/pack/plugins/start/nerdtree.vim" + + if [ ! -f "$HOME/.vimrc" ]; then + touch "$HOME/.vimrc" + fi + + mkdir -p ~/.vim/plugins + if ! [ -f "$HOME/.vim/plugins/nerdtree.vim" ]; then + WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"} + curl -fsSL -o ~/.vim/plugins/nerdtree.vim "$WEBI_HOST/packages/vim-nerdtree/nerdtree.vim" + fi + + if ! grep 'source.*plugins.nerdtree.vim' -r ~/.vimrc >/dev/null 2>/dev/null; then + set +e + mkdir -p ~/.vim/plugins + printf '\n" CtrlP: reasonable defaults from webinstall.dev/vim-nerdtree\n' >> ~/.vimrc + printf 'source ~/.vim/plugins/nerdtree.vim\n' >> ~/.vimrc + set -e + echo "" + echo "add ~/.vim/plugins/nerdtree.vim" + echo "updated ~/.vimrc with 'source ~/.vim/plugins/nerdtree.vim'" + fi + + echo "" + echo "vim-nerdtree enabled with reasonable defaults" + +} + +__init_vim_nerdtree diff --git a/vim-nerdtree/nerdtree.vim b/vim-nerdtree/nerdtree.vim new file mode 100644 index 0000000..8b12d88 --- /dev/null +++ b/vim-nerdtree/nerdtree.vim @@ -0,0 +1,27 @@ +" default mappings for nerdtree +nnoremap n :NERDTreeFocus +nnoremap :NERDTree +nnoremap :NERDTreeToggle +nnoremap :NERDTreeFind + +" also map with Leader, since ctrl is hard to reach on Mac +nnoremap t :NERDTreeToggle +nnoremap f :NERDTreeFind + +" show hidden files +let NERDTreeShowHidden=1 + +" keep ignoring .git, node_modules, vendor, and dist +let NERDTreeIgnore=["\.git", "node_modules", "vendor", "dist"] + +" Start NERDTree when Vim is started without file arguments. +autocmd StdinReadPre * let s:std_in=1 +autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif + +" Exit Vim if NERDTree is the only window left. +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | + \ quit | endif + +" if you want to change the default arrows +"let g:NERDTreeDirArrowExpandable = '▸' +"let g:NERDTreeDirArrowCollapsible = '▾'