SCNVim - A NeoVim frontend for SuperCollider

hello

I realized that scnvim does not have it’s own thread and it rightly deserves one so here it is!

scnvim is a neovim plugin that integrates SuperCollider into the editor including post window, status line, automatic snippet generation and loads of other handy things.

Features

  • Post window is displayed in a regular vim buffer
    • Use vim key bindings to navigate/move/copy etc.
    • Toggles back if hidden on a SuperCollider error
  • Automatic display of method arguments
  • Status line widgets
    • Display SuperCollider server status in the status line.
  • Snippet generator
    • Generates snippets for creation methods in SCClassLibrary.
  • Can be used with Neovim GUI frontends
  • Supports on-demand loading
  • Context aware evaluation (like Cmd-Enter in ScIDE)
  • Flashy eval flash (configurable)
  • Partial Document support (e.g. thisProcess.nowExecutingPath, .load etc.)
  • Display SuperCollider documentation inside nvim
    • Be able to evaluate examples
13 Likes

the project also has a wiki which is brimming with nice info.

Recently added was a section on fuzzy searching scdoc files and supercollider tags and a section on how to use the api that scnvim exposes to write editor hacks in lua (!!!)

2 Likes

I’ve recently considered moving on from scide… from this, I’m finally trying vim… legends have it the true jedi’s use vim.

To help out mads, nvim has packaged releases for all platforms, just like sc:

…download scnvim automatically:

… then after saving the two zip’s:

nvim how-to-install:

scnvim how-to-install:

And from there:

Hey mads, is there any chance someone could somehow inherit a killer init.lua… instead of having to learn lua.

4 Likes

I’ve been using SCNVim for a long time and I never encountered any problem or any missing feature. Congratulations to the people who worked on this extension. Be sure to read the documentation after installation if you are interested, I have missed a few very convenient features for a long time by not doing so.

I especially like working with SCNVim when using tiling window managers, by surrounding my main editor with s.meter, s.plotTree, s.scope and so on. Everything can fit nicely on the same screen.

1 Like

hi Rainer

Feel free to peruse my dotfiles here: madskjeldgaard/dotfiles: dot dot dot - dotfiles - Codeberg.org

A word of warning: It is pretty chaotic!

2 Likes

I’m a Master’s in chaos… pursuing my doctorate by using SC was the obvious choice.

…also stealing all of your synths while I’m at it.

3 Likes

Haha go ahead and do so !

Also feel free to study what I piled together nvim/init.lua · main · Kenneth Flak / dots · GitLab. A word of advice, though, for anyone on the nvim path: try to learn doing stuff as much as possible with native vim keybindings and as few plugins as possible. Only add plugs when they really add benefits that are not readily available. I have been through periods of piling up plugs, removing most of them, and I feel like I have found a kind of decent balance for my workflow. However, as this is vim-land, this is my workflow, and tailored to how I do things. The best way to approach this is to expand organically, figuring out how to do things as you go along, tweaking things one step at the time until it fits you like a snugly tailored dress/suit. And then tear it all down and start afresh :wink:

3 Likes

Couldn’t agree more. The crux of vim is its orientation around the home row and the “grammar” you use to compose editing commands, and the important thing is to keep that front and center instead of trying to make it into something else. Plus, there’s a LOT of stuff in there already and it usually pays to ask yourself before installing a plugin, “do I really need this or am I not using some built in feature to its full potential?”

In my experience, vim supports a particular kind of connection between thought process and muscle memory that feels a lot more like “playing an instrument” than “using a computer program”, which is one of the reasons that I often evangelize it to SC people. As a musician, vim completely changed my relationship to the computer as a tool for serious music making.

(To be clear, all of this applies equally to neovim, and scnvim is what I’d recommend to anyone looking to use vim for SC these days.)

4 Likes

I couldn’t agree more. This is also why I love neovim so much: IT makes it easy to extend the instrument that is SuperCollider into the editor itself (See wiki post above) and thus into key strokes, mappings and stuff. (I took this to the extreme by also making a plugin to allow me to control my daw, REAPER, from nvim, hahaha: https://github.com/madskjeldgaard/reaper-nvim)

6 Likes

Reaper-nvim looks amazing, must try it out one day!

This got me thinking

Piano keymap

Using scnvim / nvim as an instrument got me thinking: Can we directly map synth spawns to keymaps in a way sort of like ableton’s ability to preview a synth by pressing the computer’s keyboard as if they were piano notes?

The answer is: yes, of course.

-- Name of synth being played by key map
vim.g.sc_synth_for_keymap = "default"

-- Keymap, midi note number
local keys_for_scsynth = {
	["<A-1>"] = 58,
	["<A-2>"] = 59,
	["<A-3>"] = 60,
	["<A-4>"] = 61,
	["<A-5>"] = 62,
	["<A-6>"] = 63,
	["<A-7>"] = 64,
	["<A-8>"] = 65,
	["<A-9>"] = 66,
	["<A-0>"] = 67,
}

function map_key_to_midinote(synthName, lhs, midinote, noteDur)
	local noteOnTime = noteDur or 0.5
	local synthName = synthName or 'default'
	local midinote = midinote or 58
	local sc_code = [[r{var synth=Synth(\'%s\', [\'freq\', %s.midicps]); %s.wait; synth.set(\'gate\', 0)}.play]]
	sc_code = string.format(sc_code, synthName, midinote, noteOnTime)

	-- Normal mode mapping
	local opts = { nowait = true, noremap = true, silent = true }
	local mode = "n"

	-- The thing that will be executed by said key:
	local rhs = string.format("<cmd> lua require'scnvim'.send_silent('%s')<cr>", sc_code)
	vim.api.nvim_buf_set_keymap(0, mode, lhs, rhs, opts)

end

for keymap, midinote in pairs(keys_for_scsynth) do
	map_key_to_midinote(vim.g.sc_synth_for_keymap, keymap, midinote)
end

This maps Alt+[number key] to playing ‘default’ using midinotes 58-67. Pretty cool!

5 Likes

Oh wow Mads that is just excellent!

I also need to chime in here and say that I am very much in love with scnvim.
The feel of using it is most exquisite.
It really does remind me a whole lot of playing guitar.
Some of my fav “fast frets” type things to do in nvim is incrementing and decrementing values using c+a & c+x with super fast key repeat rate:

defaults write -g InitialKeyRepeat -int 15
defaults write -g KeyRepeat -int 1

Also navigating by blocks with { & } really slicks my hair back.
Saving stuff in registers, macros and working with marks all have a very pronounced wind tunnel feel to them.

Also the overall aesthetics of scnvim are spot on for my fantasy of living and working in the terminal.
Reading the help is way more fun inside scnvim. That is a huge feature for me because I shy away from reading the help far too often.
The way the post window can be hidden and will pop back up when it has an error to report. Sheer elegance thoroughout. I hold it in the highest of regard and can wholeheartedly recommend everyone to use it.

I am sorry for being too much here, I could go on, but I won’t.
You should try it, is all I’m saying.

Oh and hey here my init.vim file is in my dotfiles in case you’d like to take a gander.
I think if I had to choose just one idea from there to turn a new nvim user on to it would have to be turning of the arrow keys:

" Disable Arrow keys in Escape mode
 map <up> <nop>
 map <down> <nop>
 map <left> <nop>
 map <right> <nop>
"
" " Disable Arrow keys in Insert mode
 imap <up> <nop>
 imap <down> <nop>
 imap <left> <nop>
 imap <right> <nop>
1 Like

I couldn’t help myself, so I turned this into a little plugin:

This might serve as a nice inspiration for others who want to hack something together as well - the code is very simple and short.

2 Likes

its cool that you can map keys to send text to the sclang interpreter eg

map <leader>tr :call scnvim#sclang#send("s.plotTree")<CR> 
1 Like

I’m not making an independent topic for this but another small plugin utilizing the api of scnvim to create magic: fzf-sc. This one uses the fzf.vim plugin to allow fuzzy searching basically anything in SuperCollider and executing SuperCollider code with the result of that search.

4 Likes

So cool can’t wait to play with this

I’ve never had time to dig deeply into SCNVim, but even using it a bit has majorly increased my user experience. One issue I haven’t solved yet is running multiple SC files at the same time. I used to have pieces composed in two files - one with the SynthDefs, one with controls for them. I’ve found ways around this and it’s not a big deal, but I’m wondering how I can use multiple files (buffers?) at the same time without booting the server twice. This is a pretty serious noob question I think but maybe someone has the answer?

Newbie questions are more than welcome! When you run the :SCnvimStart command you get an sclang which receives code every time you evaluate code in your files. If you want to have multiple files open you can for example open a new tab using :tabnew other-file.scd or you can start nvim with all the files you want to edit like this: nvim firstfile.scd secondfile.scd -p. Does that make sense ?

If you open a separate nvim instance with supercollider files you get a separate sclang for that one.

This article series on vim is absolutely brilliant. The first article is aimed at beginners and then it gets progressively more advanced as you go. Highly recommended

3 Likes