0

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.

20
  • What do you have for 'fileformats' (alias 'ffs')? – B Layer May 12 at 19:03
  • 1
    :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 at 19:51
  • 1
    Then set autoread and no worries. – Matt May 12 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 at 20:06
  • 1
    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 at 20:45
2

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!
  autocmd BufRead ~/VendorApp/DataCamp/Python/history.py e ++ff=dos
augroup END
2
  • 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. – user2153235 May 13 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. – user2153235 May 13 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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