Skip to content

Additional configuration

niklas adam edited this page Mar 29, 2022 · 7 revisions

Syntax highlighting

Call :SCNvimTags after starting SuperCollider to generate a file used for syntax highlighting.

The command will also generate a file with snippet definitions for all object creation methods and also a tags file which can be used to navigate to references using the built-in vim command C-] (jump to definition).

If you write or install new classes you will need to run this command again to update the syntax/tags/snippets files.

An alternative to this approach is to use nvim-treesitter which comes with the SuperCollider treesitter grammar. This will enable intelligent syntax highlighting (and other things based on the treesitter code parser).

Snippets

Call :SCNvimTags to generate the snippet definitions.

You will also need a snippet engine like UltiSnips, LuaSnip or Snippets.nvim in order to use the snippets.

Configuring Ultisnips

To let UltiSnips know about the snippets, put the following line in your init.vim:

let g:scnvim_snippet_format = "ultisnips"
let g:UltiSnipsSnippetDirectories = ['UltiSnips', 'scnvim-data']

Configuring LuaSnip

To use LuaSnip as the snippet engine, first follow the LuaSnip guidelines for setting up the plugin.

Then to configure scnvim correctly to use luasnip as the snippet engine, add the following to your config file:

let g:scnvim_snippet_format = "luasnip"

And then add the scnvim snippets to the luasnip snippet dictionary in lua:

lua << EOF
require("luasnip").add_snippets("supercollider", require("scnvim/utils").get_snippets())
EOF

Completion

A lot of completion engines will pick up the tags that SCNvim generates when you have called the :SCNvimTags command to generate them.

Setting up nvim-cmp

nvim-cmp is a nice completion engine that integrates well with scnvim and is able to use both the tags generated as well as integrate the automatically generated scnvim snippets into the completion results.

nvim-cmp itself does not contain any sources. You need to install them seperately.

Install the tags and luasnip or ultisnip sources together with the nvim-cmp plugin itself. An example of doing so in vim-plug:

" Completion engine
Plug 'hrsh7th/nvim-cmp'

" Completion source for tags
Plug 'quangnguyen30192/cmp-nvim-tags'

" completion source for luasnip snippets
Plug 'saadparwaiz1/cmp_luasnip'

" completion source for ultisnips
"Plug 'quangnguyen30192/cmp-nvim-ultisnips'

Now, in your nvim-cmp setup, add the tags and luasnip sources to the list of sources in the setup function like so:

lua << EOF

local cmp = require'cmp'

cmp.setup({
snippet = {
	expand = function(args)
	require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
	-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
	end,
	},
sources = {
	{ name = 'tags' },
	{ name = 'luasnip' }, -- For luasnip users.
}
)}
EOF

Status line widgets

scnvim provides some functions suitable to use in your vim statusline.

  • scnvim#statusline#server_status

See the example configuration for a status line example.

Call :SCNvimStatusLine to get feedback in the status line.

If you always want to display the server status, put the following in your startup.scd.

// scnvim
if (\SCNvim.asClass.notNil) {
    Server.default.doWhenBooted {
        \SCNvim.asClass.updateStatusLine(1, \SCNvim.asClass.port);
    }
}

Plugin configuration

The following variables are used to configure scnvim. This plugin should work out-of-the-box so it is not necessary to set them if you are happy with the defaults.

Run :checkhealth scnvim to diagnose common problems with your config.

Post window

" vertical 'v' or horizontal 'h' split
let g:scnvim_postwin_orientation = 'v'

" position of the post window 'right' or 'left'
let g:scnvim_postwin_direction = 'right'

" default is half the terminal size for vertical and a third for horizontal
let g:scnvim_postwin_size = 25

" automatically open post window on a SuperCollider error
let g:scnvim_postwin_auto_toggle = 1

Eval flash

" duration of the highlight
let g:scnvim_eval_flash_duration = 100

" number of flashes. A value of 0 disables this feature.
let g:scnvim_eval_flash_repeats = 2

" configure the color
highlight SCNvimEval guifg=black guibg=white ctermfg=black ctermbg=white

Extras

" path to the sclang executable
" scnvim will look in some known locations for sclang, but if it can't find it use this variable instead
" (also improves startup time slightly)
let g:scnvim_sclang_executable = ''

" update rate for server info in status line (seconds)
" (don't set this to low or vim will get slow)
let g:scnvim_statusline_interval = 1

" set this variable if you don't want the "echo args" feature
let g:scnvim_echo_args = 0

" set this variable if you don't want any default mappings
let g:scnvim_no_mappings = 1

" set this variable to browse SuperCollider documentation in nvim (requires `pandoc`)
let g:scnvim_scdoc = 1

" pass flags directly to sclang - see help file for more details, caveats, and further examples
let g:scnvim_sclang_options = ['-u', 9999]

Example configuration

See :h scnvim for all available options.

" vim-plug

call plug#begin()
  Plug 'davidgranstrom/scnvim'
  " (optional) for snippets
  Plug 'SirVer/ultisnips'
call plug#end()

" scnvim

" horizontal post window
let g:scnvim_postwin_orientation = 'h'

" eval flash colors
highlight SCNvimEval guifg=black guibg=cyan ctermfg=black ctermbg=cyan
" this autocmd keeps the custom highlight when changing colorschemes
augroup scnvim_vimrc
  autocmd!
  autocmd ColorScheme *
        \ highlight SCNvimEval guifg=black guibg=cyan ctermfg=black ctermbg=cyan
augroup END

" hard coded path to sclang executable
let g:scnvim_sclang_executable = '~/bin/sclang'

" enable snippets support
let g:UltiSnipsSnippetDirectories = ['UltiSnips', 'scnvim-data']

" create a custom status line for supercollider buffers
function! s:set_sclang_statusline()
  setlocal stl=
  setlocal stl+=%f
  setlocal stl+=%=
  setlocal stl+=%(%l,%c%)
  setlocal stl+=\ \|
  setlocal stl+=%24.24{scnvim#statusline#server_status()}
endfunction

augroup scnvim_stl
  autocmd!
  autocmd FileType supercollider call <SID>set_sclang_statusline()
augroup END

" lightline.vim example

" let g:lightline = {}
" let g:lightline.component_function = {
"       \ 'server_status': 'scnvim#statusline#server_status',
"       \ }
" 
" let g:lightline.active = {
"       \ 'left':  [ [ 'mode', 'paste' ],
"       \          [ 'readonly', 'filename', 'modified' ] ],
"       \ 'right': [ [ 'lineinfo' ],
"       \            [ 'percent' ],
"       \            [ 'server_status'] ]
"       \ }