2

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 2

1

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.

2
  • But I want to use if statement to detect it?
    – Kindred
    Apr 22 at 11:41
  • @Kindred You can use :%s/^.\{30}//n That will count the number of matches.
    – user157
    Apr 22 at 11:45
0

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
1
  • 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 <= and or to and.)
    – B Layer
    Apr 23 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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