Skip to content

A Vim plugin that makes Vim's "gf" command work with Pixar's USD files

License

Notifications You must be signed in to change notification settings

ColinKennedy/vim-usd-goto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

17 Commits

Repository files navigation

vim-usd-goto lets you navigate Pixar's USD files with ease, even if those files aren't written as file paths.

In Vim, thegfcommand lets you open files on-disk if the path is under your cursor.gfdoesn't work with most USD Asset paths because pipelines don't write USD files as "/foo/bar/path.usd". It's usually some syntax like "my_cool_resolver:?database?asset?v10&extension=usda" or some other crazy syntax.

Example:

#usda 1.0
(
subLayers = [
@foo:/Some[Tokened]/and/weird/path?extension=.usd,.usdc@
]
)

This plugin lets you put your cursor in-between the @s and pressgf. Vim will navigate to the file on-disk as normal, assuming it actually exists.

Installation

Use your favorite plugin manager (examples below).

1. Get the plugin

vim-plug

Plug'ColinKennedy/vim-usd-goto'

Vundle

Plugin'ColinKennedy/vim-usd-goto'

2. Enable ftplugin support

Also make sure that your ~/.vimrc contains

filetypepluginon

so that the ftplugin folder is sourced whenever you load usd/usda files.

Reference

:help ftplugin
https://www.gilesorr.com/blog/vim-ftplugin.html

3. Define a filetype for USD files

If you haven't done this already, you need toset filetypefor*.usdfiles so that the files in the ftplugin folder will be sourced.

Add these lines in your~/.vimrc.

autocmd!BufRead,BufNewFile*.usdsetfiletype=usd
autocmd!BufRead,BufNewFile*.usdasetfiletype=usda

Requirements

  • Vim 8+ with+evalsupport
  • Pixar's USDmust be compiled and sourced

How the resolver works

This plugin comes with 2 methods for resolving paths.

Using Python pxr.Ar

  • If Vim actually has Pixar's Python packages sourced, this plugin attempts to run this code
frompxrimportAr
Ar.GetResolver().Resolve(path)

wherepathis whatever is under your cursor whengfis pressed.

Using command-line

  • If you don't have USD sourced but theusdresolvecommand-line executable is found, then it is run and its output will be used instead.

Help With Non-File-Paths

By default, Vim'sgfcommand assumes that the user is trying to select file paths. In USD, you might have some file resource that has a path like this:

@foo:/BAR(BAR)?version=3&something_else=this:.could:be:anything@

This plugin can't account for every possible syntax you might need. But if you wanted to support a path like the one above, you only need to add this to your~/.vimrc:

setisfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,:,?,&,(,)

(Hint: This is just Vim's defaultisfname+ some extra allowed symbols)

So if you're looking to use this plugin to resolve URIs, for example, your install process may look like this:

Plug'ColinKennedy/vim-usd-goto'
setisfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,:,?,&,(,)

Advanced Setup - Custom resolver function

Most people will be able to resolve USD files using the above 2 methods. But if you don't have Python sourced and you can't rely on the usdresolvecommand-line function, then the last option is to write your own resolver function and hook it into this plugin.

  • To do that, add a file to Vim's plugin folder.

e.g.~/.vim/plugin/usd_resolver.vim

pythonx<< EOF
from vim_usd_gotoimportusd_path_finder

defresolve(path):
return"/tmp/default_file.usda"

usd_path_finder.register_resolver(resolver)
EOF
  • Restart Vim
  • The next time you try to open a path withgf,if no other resolver method could be found and "/tmp/default_file.usda" then that file will be opened in Vim, instead.

Any function can be used for resolution but it must follow these rules:

  • Takes on argument (the USD Asset path that will be resolved)
  • Returns nothing if no path on-disk could be resolved
  • Raises no exceptions

As mentioned before though, most people will never have to use a custom resolver function. The default resolver functions that this plugin comes with will work for most people, assuming that their USD environment is set up correctly.

About

A Vim plugin that makes Vim's "gf" command work with Pixar's USD files

Resources

License

Stars

Watchers

Forks

Packages

No packages published