Thursday, November 22, 2018

Re: Noswap and Nobackup when editing python on a specific device (mounted) on Linux

On 2018-11-22, tuxic@posteo.de wrote:
> Hi,
>
> from time to time I have to edit a python file, which
> is stored on the 2M flash memory on a microcontroller
> board.
>
> To avoid unneccassary write cycles to the flash (flash wear out)
> I want to disable backup and swapfile in such a case.
>
> And to ensure both are switched off even if I have forgotten
> to do so, vim should do that automatically.
>
> I am working under Linux.
>
> The mountpoint for the flash (the microcontroller represents
> itsself as "USBstick" with 2M memory space...) is
> /home/user/flash and I am always editing python code.
>
> I tried
> autocmd FileType python setlocal nobackup
> autocmd FileType python setlocal noswapfile
> as a first test...but it fails (supposedly a layer eight failure...)
>
> How can I acchieve this trick?

It appears that Vim creates the swap file before determining the
file type. I tried your autocommand for setting noswapfile and no
swap file appeared in the directory, so in that sense it worked for
me, but I could see by the directory's modification time that it had
been changed, so presumably the swap file was initially created then
deleted when the autocommand triggered. The following seemed to
work, though.

set noswapfile
au FileType * if &ft != 'python' | setlocal swapfile | endif

HTH,
Gary

--
--
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@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: