Skip to content

Instantly share code, notes, and snippets.

@sbeckeriv
Created September 7, 2022 15:55
Show Gist options
  • Save sbeckeriv/d737ca6334bfcd1bf07c393716421880 to your computer and use it in GitHub Desktop.
Save sbeckeriv/d737ca6334bfcd1bf07c393716421880 to your computer and use it in GitHub Desktop.
disable plugins on big files.
" disable syntax highlighting in big files found on reddit
" https://www.reddit.com/r/neovim/comments/pz3wyc/comment/heyy4qf/?utm_source=reddit&utm_medium=web2x&context=3
" https://www.reddit.com/r/neovim/comments/s9kdsm/disable_treesitter_for_files_larger_than_x_lines/ lua version?
function DisableSyntaxTreesitter()
echo("Big file, disabling syntax, treesitter and folding")
if exists(':TSBufDisable')
exec 'TSBufDisable autotag'
exec 'TSBufDisable highlight'
" etc...
endif
set foldmethod=manual
syntax clear
syntax off " hmmm, which one to use?
filetype off
set noundofile
set noswapfile
set noloadplugins
endfunction
augroup BigFileDisable
autocmd!
" autocmd BufWinEnter * if getfsize(expand("%")) > 512 * 1024 | exec DisableSyntaxTreesitter() | endif
autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | exec DisableSyntaxTreesitter() | endif
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment