2

I'm using the Indent Blankline plugin to show indent guides.

My Jupyter Notebook/.ipynb files have 1 space indents. Vim identifies them as JSON files.

One way to tell Neovim that Jupyter Notebook files have 1 space indents, is to just create ~/.config/nvim/ftplugin/json.lua.

But I still want JSON files to have 2 space indents.

How do I accomplish this?

1 Answer 1

0

You could introduce a new file type for the *.ipynb file (jupyter) by introducing a ~/.config/nvim/ftdetect/jupyter.vim or ~/.config/nvim/ftdetect/jupyter.lua file:

ftdetect/jupyter.vim:

autocmd BufReaf,BufNew *.ipynb setfiletype jupyter

Or in ftdetect/jupyter.lua:

vim.api.nvim_create_autocmd({'BufRead', 'BufNew'}, {
  pattern = '*.ipynb',
  command = 'setfiletype jupyter'
})

With that new filetype you could have your specific jupyter configuration in: ftplugin/jupyter.lua

vim.o.tabstop = 1
vim.o.shiftwidth = 1

With this solution you have full control but you lose some of the configuration settings you have with the python file type.

Another solution is to override the configuration by adding in your init.lua some autocmd to set settings you want for that file pattern:

vim.api.nvim_create_autocmd({'BufRead', 'BufNew'}, {
  pattern = '*.ipynb',
  command = ":set expandtab tabstop=1 shiftwidth=1"
})
2
  • 1
    Thanks. I got it working with some slight modifications. I renamed autocmd() to vim.api.nvim_create_autocmd(), as the former wasn't recognized. I couldn't manage to create a new file type based on the JSON type using Lua. I use Tree-sitter, if that matters. Do you mind expanding on that?
    – simonzack
    Sep 25, 2023 at 9:43
  • Thanks for the feedback (and sorry for the wrong shortcut). I have expanded the new filetype section. Let me know if you need more information. Sep 25, 2023 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.