Loading ...
Sorry, an error occurred while loading the content.

Re: Disable swap file for large files?

Expand Messages
  • Jorge Rodrigues
    ... Thanks for the suggestions Ben and John, I went with the following: try to disable swapfiles for large files augroup disable_swap_large_files autocmd! 5
    Message 1 of 14 , Aug 21, 2013
    • 0 Attachment



      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.
       
       
      Thanks for the suggestions Ben and John, I went with the following:
        "try to disable swapfiles for large files                                                                            
        augroup disable_swap_large_files                                                                                     
          autocmd!                                                                                                           
          "5 megs                                                                                                            
          autocmd BufRead * if getfsize(expand('%:p')) > 5242880 |                                                           
                \ setlocal noswapfile noundofile | endif                                                                     
        augroup END             
       
      It seems that the backup option is a global one so I didn't change that one.
       
      Regards,
      Jorge
       
       
       

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
       
      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Christian Brabandt
      ... There is a patch pending, making undolevels buffer-local. Unfortunately, Bram hasn t included it yet. ... No. There are only two ways handling this. If
      Message 2 of 14 , Aug 21, 2013
      • 0 Attachment
        On Wed, August 21, 2013 19:29, Charles Campbell wrote:
        >> On Tuesday, August 20, 2013 5:36:00 PM UTC-5, John Little wrote:
        >> 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

        There is a patch pending, making 'undolevels' buffer-local. Unfortunately,
        Bram hasn't included it yet.

        > I think I can get a copy of the undo situation with undotree(). Is
        > there a way to restore it? I'm thinking of doing a save-undo ... work
        > with large file ... restore undo scenario.

        No. There are only two ways handling this. If you don't really change
        the buffer, you can disable the undo and later :rundo the
        existing undofiles. Or you can work with a copy of the buffer and only
        write the changed copy back. The NrrwRgn plugin might be helpful with
        this. Both ways are usually not really workable in practice.

        regards,
        Christian

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Ben Fritz
        ... Woah, woah, woah! Could one theoretically add to the autocmd that detects a large file, to (before setting undolevels) do something like: bufdo let
        Message 3 of 14 , Aug 22, 2013
        • 0 Attachment
          On Thursday, August 22, 2013 1:25:29 AM UTC-5, Christian Brabandt wrote:
          >
          > No. There are only two ways handling this. If you don't really change
          >
          > the buffer, you can disable the undo and later :rundo the
          >
          > existing undofiles.

          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.

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Christian Brabandt
          ... Might work. Not sure, one wants to use several tempname() calls at all, since tempname() is only guaranteed to give distinct names for 26 calls and some
          Message 4 of 14 , Aug 22, 2013
          • 0 Attachment
            On Thu, August 22, 2013 16:37, Ben Fritz wrote:
            > On Thursday, August 22, 2013 1:25:29 AM UTC-5, Christian Brabandt wrote:
            >>
            >> No. There are only two ways handling this. If you don't really change
            >>
            >> the buffer, you can disable the undo and later :rundo the
            >>
            >> existing undofiles.
            >
            > 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.
            >

            Might work. Not sure, one wants to use several tempname() calls at all,
            since tempname() is only guaranteed to give distinct names for 26 calls
            and some plugins make use of tempname() themselves (so it could happen,
            that plugins overwrite the undofile).

            regards,
            Christian

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Charles Campbell
            ... I ve been trying it out, but I m going to have to put this mod down for now. I ve got BufLeave events firing when they shouldn t. Regards, Chip Campbell
            Message 5 of 14 , Aug 22, 2013
            • 0 Attachment
              Christian Brabandt wrote:
              > On Thu, August 22, 2013 16:37, Ben Fritz wrote:
              >> On Thursday, August 22, 2013 1:25:29 AM UTC-5, Christian Brabandt wrote:
              >>> No. There are only two ways handling this. If you don't really change
              >>>
              >>> the buffer, you can disable the undo and later :rundo the
              >>>
              >>> existing undofiles.
              >> 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.
              >>
              > Might work. Not sure, one wants to use several tempname() calls at all,
              > since tempname() is only guaranteed to give distinct names for 26 calls
              > and some plugins make use of tempname() themselves (so it could happen,
              > that plugins overwrite the undofile).

              I've been trying it out, but I'm going to have to put this mod down for
              now. I've got BufLeave events firing when they shouldn't.

              Regards,
              Chip Campbell

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Christian Brabandt
              Hi Charles! ... Well, we should convince Bram then to include the undolevels local patch then. regards, Christian -- Der Tourist am Seeufer: Er sieht einen
              Message 6 of 14 , Aug 22, 2013
              • 0 Attachment
                Hi Charles!

                On Do, 22 Aug 2013, Charles Campbell wrote:

                > Christian Brabandt wrote:
                > >On Thu, August 22, 2013 16:37, Ben Fritz wrote:
                > >>On Thursday, August 22, 2013 1:25:29 AM UTC-5, Christian Brabandt wrote:
                > >>>No. There are only two ways handling this. If you don't really change
                > >>>
                > >>>the buffer, you can disable the undo and later :rundo the
                > >>>
                > >>>existing undofiles.
                > >>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.
                > >>
                > >Might work. Not sure, one wants to use several tempname() calls at all,
                > >since tempname() is only guaranteed to give distinct names for 26 calls
                > >and some plugins make use of tempname() themselves (so it could happen,
                > >that plugins overwrite the undofile).
                >
                > I've been trying it out, but I'm going to have to put this mod down
                > for now. I've got BufLeave events firing when they shouldn't.

                Well, we should convince Bram then to include the undolevels local patch
                then.

                regards,
                Christian
                --
                Der Tourist am Seeufer: Er sieht einen Tafel: "MÖVEN ZU VERKAUFEN".
                Was kostet eine Möve?
                DEM 2,60 das Stück.
                Dann nehme ich gleich fünf.
                Sehen sie sie, die Möven dort links oben, sie gehören nun ihnen.

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Abhishek
                ... Hi, Here s something I use: let g:BufSizeThresholdSmall = 500000 No swap threshold (Set to 500 KB) let g:BufSizeThresholdBig =
                Message 7 of 14 , Aug 23, 2013
                • 0 Attachment
                  On Wednesday, August 21, 2013 2:57:51 AM UTC+5:30, skeept wrote:
                  > Is there a way of enabling swap files for files say less than 10Mb but disabling swap files for files or larger sizes?
                  >
                  > Thanks,
                  >
                  > Jorge

                  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

                  --
                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Ben Fritz
                  It would be nice, if somebody took some of the suggestions in this thread and incorporated them into: http://vim.wikia.com/wiki/Faster_loading_of_large_files
                  Message 8 of 14 , Aug 23, 2013
                  • 0 Attachment
                    It would be nice, if somebody took some of the suggestions in this thread and incorporated them into:

                    http://vim.wikia.com/wiki/Faster_loading_of_large_files

                    --
                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php

                    ---
                    You received this message because you are subscribed to the Google Groups "vim_use" group.
                    To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                  Your message has been successfully submitted and would be delivered to recipients shortly.