GithubHelp home page GithubHelp logo

andrewradev / andrews_nerdtree.vim Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 29 KB

My personal collection of NERDTree extensions

License: MIT License

Ruby 0.67% Vim Script 99.33%
vim-plugins nerdtree file-management

andrews_nerdtree.vim's Introduction

Andrew's NERDTree

This plugin extends the NERDTree Vim plugin with a few additions I've found useful myself. It's my personal bag of NERDTree tricks. Which is why it's very likely that you won't need every single of these plugins. You can enable or disable every one of them individually, or just enable them all at once.

The plugin requres NERDTree (https://github.com/scrooloose/nerdtree) to be installed. To enable all plugins, simply put the following in your .vimrc:

let g:andrews_nerdtree_all = 1

To enable only a selection of features, use a subset of these:

let g:andrews_nerdtree_buffer_fs_menu     = 1
let g:andrews_nerdtree_diff               = 1
let g:andrews_nerdtree_external_open      = 1
let g:andrews_nerdtree_interactive_edit   = 1
let g:andrews_nerdtree_startshell_mapping = 1
let g:andrews_nerdtree_git_filter         = 1

Setting any of these to 0 or simply omitting them will mean the particular plugin is not loaded.

It's important that this plugin is activated before NERDTree is activated. If you use a plugin manager, make sure they're correctly ordered, for example in vim-plug:

Plug 'AndrewRadev/andrews_nerdtree.vim'
Plug 'scrooloose/nerdtree'

If you manage plugins manually (with pathogen, or just extracting them in your ~/.vim directory), try this:

runtime! andrews_nerdtree/plugin.vim
runtime! nerdtree/plugin.vim

An explanation on all the separate plugins follows.

Buffer FS menu

Demo

This plugin adds a filesystem manipulation menu almost exactly like the default one. The difference is that operations that require entering a file path, namely "add", "move" and "copy", use a separate one-line buffer to receive the input, instead of the default vim dialog. This allows you to use vim keybindings to move around the file path.

Most of the code here is taken directly from Marty Grenfell's original fs_menu plugin that ships with the NERDTree. A few minor things have been reformatted, because I liked them better that way.

The custom mappings for the special buffer holding the filename are as follows:

  • o and O do nothing in normal mode, to avoid opening up a second line by accident
  • <esc> and <C-[> in normal mode close the buffer, cancelling the operation
  • <C-c> closes the buffer in both normal and insert mode, cancelling the operation
  • <enter> in both normal and insert mode executes the operation and closes the buffer

Note that the <enter> key works even when the completion menu is opened -- you can't use completion in this buffer (a bit of a problem). To that end, if you happen to be using the Acp plugin, it's automatically disabled for the buffer (yes, this is extremely very niche).

If you leave the buffer, it's automatically closed.

Diff

The diff plugin adds a keybinding that diffs the current node against the closest-open buffer. It's a simple shortcut to triggering :diffthis, opening the file and running :diffthis again.

The default key used is "D". You can change it by setting g:andrews_nerdtree_diff_key, for instance:

let g:andrews_nerdtree_diff_key = '<leader>d'

External open

This is similar to netrw's gx mapping -- it opens up the node in an external program. The mapping triggers netrw's callback function, so anything that netrw can handle, this should be able to as well.

However, if you want to set your own handling function (I've found that netrw seems to do different things than I'd like for directories), you can define a global function named OpenURL, which takes a single argument -- the full path of the file/directory. For example:

function! OpenURL(url)
  let url = shellescape(a:url)

  if executable('xdg-open')
    silent call system('xdg-open '.url.' 2>&1 > /dev/null &')
  else
    echoerr 'You need to install xdg-open to be able to open urls'
    return
  endif
endfunction

The default mapping used is gx. You can change it by setting g:andrews_nerdtree_external_open_key, for instance:

let g:andrews_nerdtree_external_open_key = 'gu'

Interactive Edit

This is a menu entry that only shows up on directories. It will appear as:

NERDTree Menu. Use j/k/enter and the shortcuts indicated
==========================================================
  (a)dd a childnode
  (m)ove the current node
  (d)elete the curent node
  (c)opy the current node
> (e)dit directory contents

Triggering that menu item will open up a new buffer that looks like this:

/path/to/dir
============

/path/to/dir/some_file  -> /path/to/dir/some_file
/path/to/dir/other_file -> /path/to/dir/other_file
/path/to/dir/third_file -> /path/to/dir/third_file

The filenames on the left side are the original filenames, while the ones on the right are the "output" filenames. If you change any of those, the plugin will perform a rename from the left filename to the right one. If you delete everything from the arrow onward on a row, that file will be deleted.

Note that the plugin is not particularly sophisticated. If you have any suggestions for improvements, please open a github issue.

Startshell Mapping

This adds a mapping to the NERDTree that starts a :shell in the directory of the current node.

The default mapping used is S. You can change it by setting g:andrews_nerdtree_startshell_mapping_key, for instance:

let g:andrews_nerdtree_startshell_mapping_key = '<leader>s'

This plugin was originally created by the author of NERDTree, Marty Grenfell, himself. The original should be here: https://gist.github.com/scrooloose/203928

Git Filter

When this plugin is enabled, a command is defined, called :NERDTreeGitFilterToggle. Executing this command will make the NERDTree only show files that have been modified by git in some way. This can be useful for reviewing code before committing. Executing it again will turn the filtering off.

What's with the stupid name?

It's just a bag of scripts I've built over the years. There's no common thread connecting them, other than that they're for my own NERDTree. Plus, I figure andrews_nerdtree should be unique enough. If you're named Andrew and would have liked to create a NERDTree plugin with that name, I'm sorry. Do open an issue to complain, we might figure something out.

Contributing

Pull requests are welcome, but bear in mind these are my own personal scripts. I might turn them down if I don't find them useful myself, but who knows.

andrews_nerdtree.vim's People

Contributors

andrewradev avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

andrews_nerdtree.vim's Issues

create nerdtree filter for js files

Hey Andrew,

i am using some of your nerdtree plugins.
i like the git filter for example.
now i am searching for a way to implement that feature to filter out javascript files on demand.

currently i am using

"let NERDTreeIgnore = ['\.js$', '\.js.map$']

but if i need to see this type of files too, i have to disable that option in my vimrc and restart vim.

can you give me a hint how i can implement a feature that allows me to toggle a javascript file filter without restarting vim, like the git-diff file filter?

thx for your open source work

Issue with "add a childnode"

Hey Andrew!

I've noticed that adding a childnode doesn't seem to be working. I can reproduce this every time: I open NERDTree, hit ma wanting to add a new child node, then I see this:

NERDTree Menu. Use j/k/enter, or the shortcuts indicated
=========================================================
> (a)dd a childnode
  (m)ove the current node
  (d)elete the curent node
  (c)opy the current node
  (e)dit directory contents
  e(x)ecute

Error detected while processing function nerdtree#ui_glue#invokeKeyMap[1]..76[33]..75[3]..<SNR>73_showMenu[2]..49[29]..66[9]..andrews_nerdtree#buffer_fs_menu#AddNode:
line    2:
E716: Key not present in Dictionary: Slash()
line    4:
E121: Undefined variable: path
E116: Invalid arguments for function andrews_nerdtree#buffer_fs_menu#InputBufferSetup
Press ENTER or type command to continue

I have let g:andrews_nerdtree_all = 1 set, and disabling it "solves" the problem.

Am I doing something wrong? Can I help debug this better?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.