1

Can I tell Neovim not to load a bundled indentation file? For example, when I edit a .tex file, "share/nvim/runtime/indent/tex.vim" loads automatically. I don't want those settings. Do I have to override them, or can I just put something in my local "indent/tex.lua" to stop the defaults from loading? (If so, what?)

Edit: If I replace my local indent/tex.lua with indent/tex.vim and say let b:did_indent = 1 that works fine. But I want to know how to do this using Lua. A pointer to documentation of how to access the appropriate namespace is all I really need.

Edit 2: Commenters say that having vim.b.did_indent = 1 in my local indent/tex.lua (not under after) should have the same effect as putting let b:did_indent = 1 in indent/tex.vim. I have tried these two approaches (one at a time), and they do not have the same effect. (The files contain only one line, as just stated.) In particular, when I use the tex.vim file, the value of indentexpr is the empty string (as I wish and expect). But when I use the tex.lua file, the value of indentexpr is GetTeXIndent(), which is what I am trying to avoid.

3
  • Is the following answer of any help? Commented Sep 20, 2023 at 4:30
  • @VivianDeSmedt I have Neovim 0.9.1. If I put vim.b.did_indent = 1 in my local indent/tex.lua (not after) it does not turn off the default indenting. If I instead create indent/tex.vim with the content let b:did_indent = 1, it does turn off the default indenting. I think (?) the two shd have the same effect. Thanks!
    – Alan
    Commented Sep 20, 2023 at 13:24
  • Do you still have something open in your question? How can we help further? Otherwise maybe could you accept one of the answers using the v button next to the arrow voting buttons. It allows the question to rest :-) Commented Sep 23, 2023 at 6:06

2 Answers 2

1

You can do: ~/.config/nvim/indent/tex.lua as:

vim.o.indentexpr=""

Remark on version prior to 9.3:

  • ~/.config/indent/tex.lua is executed after $VIMRUNTIME/indent/tex.vim
  • Where ~/.config/indent/tex.lua is executed before $VIMRUNTIME/indent/tex.vim

This is the reason the following translation of the tex.vim trick is not working:

~/.config/nvim/indent/tex.lua

vim.b.did_indent = 1

Remark: It seems that from version 9.3 the trick should work

8
  • Have you actually tried this? I have Neovim 0.9.1. If I put vim.b.did_indent = 1 in my local indent/tex.lua it does not turn off the default indenting. If I instead create indent/tex.vim with the content let b:did_indent = 1, it does turn off the default indenting.
    – Alan
    Commented Sep 20, 2023 at 13:22
  • I'm using Neovim 0.9.1 and b:did_indent is 1 for tex files. I don't know enough about the autoindenting you try to avoid (an example would be nice) so I couldn't test that. But the variable is correctly set for tex buffers. Commented Sep 20, 2023 at 14:22
  • With the configuration you describe above (a tex.lua but not a tex.vim in your indent folder), go to a .tex document. Create an empty equation environment on two lines, unindented. Put your cursor in indent mode at the end of the first of these two lines (which should be right after a closing brace) and press Enter. Do you see any indentation? Also, what is the value of indentexpr? Thanks!
    – Alan
    Commented Sep 20, 2023 at 14:47
  • Could you provide me the text (I don't recall our to do an empty equation :-|)? Maybe you could add the example to the question. Commented Sep 20, 2023 at 15:27
  • 1
    I have installed [vimtex]() to reproduce your problem and I notice that ~/.config/indent/tex.lua is executed after $VIMRUNTIME/indent/tex.vim which makes that the trick isn't working. Commented Sep 21, 2023 at 5:33
0
  1. Type :help user-manual
  2. Type /indenting
  3. See section 30.3 Automatic indenting
  4. Press K to follow the link
  5. Read the text
  6. Find the commands filetype indent off, let b:did_indent=1 etc.etc.

Upd. As for vim.b.did_indent=1 not working (executing only after standard tex.vim) that turns out to be a bug in older nvim runtime (indent.vim). This was already fixed in the current (v10) branch. This is why one must update the installation to the latest build before trying to reproduce any supposed bugs.

1

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.