sponsor Vim development Vim logo Vim Book Ad

nerdtree-harvest : Yank modified file paths from NERD Tree

 script karma  Rating 0/0, Downloaded by 211  Comments, bugs, improvements  Vim wiki

created by
Trevor Stone
 
script type
utility
 
description
This is a Vim plugin that adds several ways to “harvest” file paths from the NERD Tree directory browser.

Harvest creates four mappings in the NERD Tree window: y, Y, ;, and !. Each mapping reads one or more additional characters to pick a path modifier and then performs an operation with the modified path. For example, yh yanks the path to the file's parent directory, much as :cd %:h changes the current directory to the parent of the file in the current buffer. See :help filename-modifiers for details on how these transform a file path.

NERD Tree only shows these four mappings in the help list; you can hit ? after starting a mapping to see a summary of available modifiers, or consult the tables below. If the vim window is wide enough, ? will print names after each modifier key, otherwise just keys shown. Pressing ? a second time will show the full explanation, wrapping the echo line.

Modifier Name Path Modification
. relative :. File path from current working directory
~ home :~ File path from home directory, or absolute
p absolute :p Absolute path from filesystem root
h head :h Path without the last component (parent directory)
H rel+head :.:h Relative path to parent directory
t tail :t Final path component (file name)
r root :r Path with last extension removed (/a/b.c → /a/b)
R tail+root :t:r Tail with last extension removed (/a/b.c → b)
e extension :e Last extension of the file name (/a/b.c → c)
: modifier : Arbitrary modifier, type enter to end e.g. :~:h<CR>
? help Echo a list of modifiers, continue reading next one
A doubled mapping (yy, YY, ;;, or !!) reuses the previous modifier for the given type (yank, Ex, shell).

The : modifier type reads additional keys until you press enter (<CR>). The full input is used as a modifier of arbitrary length. Example uses of : are shown in the following table, read :help filename-modifiers for a full list.

Command Effect
y:~:h Yank the parent directory of a file, relative to your home directory
y:h:h Yank the path to the parent’s parent
y:t:S Yank the shell-quoted/escaped file name, without leading path
y:8 (Windows-only) Yanks the “8.3” DOS form of a path
y:.:gs#/#.#:r Yank the relative path with / replaced by . and file extension removed
The final example could be useful to reference a fully-qualified Java class.

More documentation and latest version at https://github.com/flwyd/nerdtree-harvest
 
install details
Point your favorite plugin manager at https://github.com/flwyd/nerdtree-harvest or unpack the zip file somewhere and add the directory to your runtimepath.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
nerdtree-harvest-1_0.zip 1.0 2021-02-03 7.3 Trevor Stone Initial upload
ip used for rating: 54.234.233.157

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github