As title. I want to disable some plugins when the current file is a production file, i.e. it is compacted into < 10 lines but each line contains >1000 columns. I'm using NeoVim so I prefer script written in Lua, but VimScript is also welcome!
2 Answers
You can just use the search command to search for the beginning of a line followed by a number of characters. If you do
/^.\{30}
It will search for the beginning of a line followed by 30 characters, so for lines containing at least 30 characters. You can change the number to fit your needs.
-
-
@Kindred You can use :%s/^.\{30}//n That will count the number of matches.– user157Commented Apr 22, 2022 at 11:45
Finally, I use combination of strwidth
and getfsize
to achieve my goal:
is_supported = function ()
if vim.fn.strwidth(vim.fn.getline('.')) > 300
or vim.fn.getfsize(vim.fn.expand("%")) > 1024 * 1024 then
return false
else
return true
end
end
-
You don't need a function. In just about any programming language you can assign the result of an expression directly to a variable, e.g.
foo = bar or baz
. A boolean expression like this will assign either 'true' or 'false' (or '1' or '0' in some langauges). Since you want to assign 'false' if your expression evaluates to 'true', you can 'not' the whole thing:foo = not (bar or baz)
(Alternatively, you could invert the boolean logic by inverting the three operators: both>
to<=
andor
toand
.)– B LayerCommented Apr 23, 2022 at 9:40