I followed the advice here to make only one buffer hidden so that it remembers settings like fileformat=dos:

set bufhidden=hide " This should be the solution
e ++ff=dos         " All the ^M symbols disappear (yay)
e                  " All the ^M symbols reappear  (boo)
setl ff            " Shows as unix                (boo)
set ff             " Shows as unix                (boo)
  • The set bufhidden=hide is supposed to be the solution.
  • The e ++ff=dos makes the ^M symbols disappear from the ends of the lines (they were only present on some lines).
  • The e brings the ^M symbols back!
  • The setl ff and set ff commands confirm that the fileformat reverted back to unix instead of staying dos.

What am I doing wrong? Is there a solution that will persist?

I thought that my problem might be having set nomodifiable and readonly, but reversing both of these doesn't solve the problem.

I'm not sure if it matters, but the the buffer of interest is opening a Spyder command history file. Spyder frequently updates the file and I want to use Vim to yank content into (say) tmp.txt for manipulation.

  • What do you have for 'fileformats' (alias 'ffs')?
    – B Layer
    May 12, 2021 at 19:03
  • 2
    :edit or :edit % intentionally reloads current file (:h reload) and so it also forces ff re-detection. Just don't do this.
    – Matt
    May 12, 2021 at 19:51
  • 2
    Then set autoread and no worries.
    – Matt
    May 12, 2021 at 20:02
  • 1
    Or "frequently" means "really frequently"? Then you must do :e +ff=dos. Bind it to a mapping, for example.
    – Matt
    May 12, 2021 at 20:06
  • 2
    If you're not already doing so suggest you only unset 'ffs' right before loading that particular file (filetype?) then restore it afterwards. Generally, you want to have autodetect on so if you can figure out how to disable it temporarily/situationally that's ideal. BTW, does it work if you (temporarily) :set ffs=dos,unix and don't pre-set ff? I'm wondering if autodetect will choose the opposite of what you're getting when you reverse order of the params as they are order dependent. (No big deal...just curious.)
    – B Layer
    May 12, 2021 at 20:45

1 Answer 1


You can add an autocmd to have Vim execute :e ++ff=dos every time this particular file is read or reloaded.

Assuming the path to the file, after resolving symbolic links, is ~/VendorApp/DataCamp/Python/history.py (according to your comment), then this autocmd should work for you:

autocmd BufRead ~/VendorApp/DataCamp/Python/history.py e ++ff=dos

So when you open the file, it will first be read using the normal automatic detection for line endings, but then this autocmd will trigger and reload it with ++ff=dos. (Autocmd's by default are not nested, meaning the :e itself will not trigger the autocmd again.)

NOTE: Whenever you define an autocmd, make sure you add it inside an augroup, to prevent duplicate definitions if you end up reloading the script file where you defined it (such as your vimrc file.)

augroup spyder_history
  autocmd BufRead ~/VendorApp/DataCamp/Python/history.py e ++ff=dos
augroup END
  • 1
    Thanks! Since I am using Cygwin's Vim with Anaconda's Spyder on Windows 10, I actually have the soft link to the history file located at an odd location. The following adaption of your answer worked for me: autocmd BufRead ~/VendorApp/DataCamp/Python/history.py e ++ff=dos. The actual location is /c/Users/UserName/.spyder-py3/history.py. May 13, 2021 at 0:42
  • 1
    Thanks for the clarification on autocommand groups. I always found autocommands confusing, but this NOTE prompted me to find the right location in the help. May 13, 2021 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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