Coding in Maya is starting to become a necessity for me. It's so much better to script little tools you will use all the time that will take longer if you memorize steps to do it. This is especially true when rigging, where you will need to add lots of controls and shapes and ribbons to objects to make your characters move. Once you learn to make some basic scripts, the power of Maya’s rigging tools really gets unlocked. The thing though is that Maya has a pretty bare bones and frankly bad script editor. Yes it has syntax highlighting and a console that tracks what you are doing in the program but it is not enough, especially if you are learning. Definitely a relic of the IRIX past, and not a cool one.
We do have newer script editors that people have gravitated to, those being Sublime and Visual Studio Code. Sublime has some good tools to get Maya working with it, and VS Code is even better with some pretty awesome Maya plugins. As for me though, I wanted to see if Neovim was up to the task for Maya development. Ever since I learned vim motions for taking notes in class, I realized how much better a modal line editor is for jotting notes, and especially writing code. That is why when working on game projects for companies, I have the vim plugin for VS Code ready to go. Now for using Neovim in Maya there are some things to keep track of, and I will cover them in this article.
Maya uses Python as its language and neovim is pretty well suited for Python. Right now I do not know how to get proper MEL support up and running in Neovim unfortunately. There are plugins like vim-mel which load up in normal vim, but I haven’t gotten them to work in Neovim yet. I bet they work with just a few tweaks though. So there are just a few Neovim and Python plugins we will need to get Neovim to communicate with Maya. Those plugins are as follows :
Pyright LSP (can be uncommented in a kickstart.nvim file)
These are mostly python pip packages that will need to be installed and will communicate with Neovim. After installing pynvim, you will need to install mayaScriptEditor.nvim by git cloning or copying the py file on the github into the rplugin directory in your neovim config. You will most likley have to make those directories on your own. Next the toughy is getting Pymel installed. Before we install pymel into our Python environment, we must install it in Maya. Maya has its own Python interpreter called mayapy in /usr/autodesk/maya2024/bin, and for me at least, its quite buggy and doesn’t want to use pip.
pip on mayapy is busted for me, but I found a work around.
So to get around this, we must download the pymel .whl file on their pip page, bring it to the bin directory where mayapy is and install it using pip locally. Now we can use Pymel in Maya. For our Neovim environment its much easier, all we have to do is install it using normal pip. Pymel is great because it offers more of a pythonic style of syntax for Maya, so python developers can jump into using Maya, and also have more freedom in writing their scripts. Plus, Pymel has better stubs than the next item on our list, the pip package maya-stubs. Maya-stubs is a good addition to our neovim setup but the problem is that the stubs are not the best. They only include stubs for full keywords rather than the nice abbreviated versions that people may be used to.
The bottom line of code will work, but it will throw you an error regardless.
Now it may be better to include the full words for your commands, but some are used to the other way of doing things which may throw some people off. Maya-stubs also has issues when using literals or other random silliness. Granted, my python skills are just fine so maybe I am learning some bad habits but the strange errors being thrown on code that works is annoying. Pymel tends to work more consistently with its stubs so if you do not mind the tiny hit to performance of your scripts, and you need your neovim to look as clean as possible, Pymel may be your best bet. But its good to have maya-stubs regardless because using maya.cmds is so much more common than Pymel, so I would say it’s worth it to keep it around. Now we have working stubs in Maya.
Working maya-stubs for cmds. As you can see, we cannot use e or q for arguments for polysphere, just the full words.
Next we have to add a tiny Python script to get Maya to communicate with NeoVim. In the script editor, copy and paste this and add it to the shelf as an icon for convenience :
#Import a script from NeoVim
from maya import cmds
cmds.commandPort(name=":54321", prefix='python', sourceType="mel")
print("Hello to NeoVim!")
My custom shelf so far. The SGI logo was fun to draw.
As the tool tip says be sure to have neovim open and ready before we hit the button. Now we can start writing our scripts and getting to work. Just use :SendToMaya in Neovim’s command mode to send your code over to Maya and it should execute right away if everything is set up right. It’s a bit of setup but using Neovim for Maya is much more fun than using the default script editor and more fun than using VS Code or Sublime frankly. I just prefer the more minimalist style of Neovim along with the fast modal editing, even if it is harder to set up at least at first.
I was talking to a CGI Veteran friend of mine about the older days of Unix and SGI when CGI was just starting out, and he told me that for editing text and making scripts, he would use the original Vi editor, the precursor to Vim to make these scripts really fast. He got really good at it, and thought that modern editors were slower because of the lack of a Vi mode. It’s funny how Vim for some is seen as this relic of the old Unix days, where the mouse was not as ubiquitous as it is today, but with Vim gaining popularity with younger coders again, I think its only fitting that Maya users return to our roots of Unix tooling, like good old Vi, or Vim.