Thanks,
Jorge
Start with them globally disabled. On a BufRead autocmd, set it to enabled (locally), if getfsize() on the file name is larger than your threshold value.
Regards, John Little
Oops, I guess You wanted to DISABLE for files larger than a certain size, not ENABLE them. You could do the same thing in reverse, or potentially enable by default and then disable locally in a BufReadPre. I'm not sure whether that works or not.
I'm actually considering uninstalling the LargeFile plugin myself. I have file associations set on my system to launch files in existing Vim with --remote-tab-silent when I double-click them, and when I view a large log file, suddenly all my undo history is lost for all my code files! I really wish 'undolevels' were not a global option, but it is, so LargeFile messing with it is not very good when using the same Vim for everything.
Oops, I guess You wanted to DISABLE for files larger than a certain size, not ENABLE them. You could do the same thing in reverse, or potentially enable by default and then disable locally in a BufReadPre. I'm not sure whether that works or not.
Woah, woah, woah!
Could one theoretically add to the autocmd that detects a large file, to (before setting undolevels) do something like:
bufdo let names[bufnr('%')] = tempname() | exe 'wundo' names[bufnr('%')]
And then when closing the file/undoing the largefile settings,
bufdo exe 'rundo' names[bufnr('%')]
(with error handling and all that added of course).
Probably would want to set 'nomodifiable' on all the buffers until the largefile settings were out of effect or something to prevent creating new changes not in the undo file.
Hi,
Here's something I use:
let g:BufSizeThresholdSmall = 500000 " No swap threshold (Set to 500 KB)
let g:BufSizeThresholdBig = 1000000000 " Minimal mode threshold (Set to 1 GB)
" For small files, switch all options on
autocmd BufEnter * if getfsize(expand("<afile>")) < g:BufSizeThresholdSmall | set incsearch | setlocal statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P | endif
" Don't use a swap file for big files
autocmd BufReadPre * if getfsize(expand("<afile>")) >= g:BufSizeThresholdSmall | setlocal noswapfile | setlocal statusline=%<%f\ %h%m%r\ No\ Swap\ File%=%-14.(%l,%c%V%)\ %P | endif
" Switch off other options for still bigger files
autocmd BufEnter * if getfsize(expand("<afile>")) >= g:BufSizeThresholdBig | set noincsearch | setlocal noswapfile | setlocal statusline=%<%f\ %h%m%r\ No\ Swap\ File.\ No\ Incsearch%=%-14.(%l,%c%V%)\ %P | endif
It allows two thresholds and disables more options for very large files. Moreover, the status line is updated to reflect the current state of options so that I know what to expect for the currently open file.
PS: I don't remember if I copied it from somewhere or built it over time. In either case, corrections and suggestions for improvement are welcome. Will help me learn something new. :)
Best Regards,
Abhishek