On Sep 9, 8:55 am, Joachim Hofmann <[email protected]> wrote: > Hello, > > I am editing a *.rb (ruby) buffer. > Then I open a command line history window with q: , search for a > command and execute it. > The command line window closes and vim is back in the *.rb buffer. > > Problem: my settings for ruby are now still overwritten with my settings > for vim. > > I have settings in my _vimrc for entering and leaving ruby and vim files > like this: > > ... > autocmd FileType vim so $HOME/vimstuff/mymacs/vimenter.vim > autocmd FileType ruby so $HOME/vimstuff/mymacs/rubyenter.vim > autocmd BufEnter,BufRead,WinEnter *.rb so > $HOME/vimstuff/mymacs/rubyenter.vim > ... > > Normally setting the ruby and vim settings work. > It seems that in this special case (using q:) the vim settings are set > because of probably the command line window is of f vim; > but the ruby settings are not sourced again when going back to the ruby > file. > > Any ideas how I can get my ruby settings back; or can debug it? >
The usual way to do this, is with an ftplugin file, either in $HOME/ vimfiles/ftplugin or $HOME/vimfiles/after/ftplugin (this for Windows systems...for Unix-like systems use .vim instead of vimfiles). These files will be automatically sourced for the correct filetypes on a BufRead or a BufNewFile (inside a FileType autocmd IIUC) as long as Vim recognizes the filetype properly. I'm confused why you feel the need for the BufEnter and WinEnter autocmds. If you've constructed your scripts correctly, you should only need to apply the settings when you apply the filetype. Possibly, you're using :set commands instead of :setlocal. For filetype-specific settings, always use :setlocal instead of :set. Likewise, any filetype-specific mappings or autocmds should use the <buffer> keyword to make sure they only apply to the specific buffer. Sometimes this can still fail, especially when changing filetypes on the same buffer (not very common, but sometimes it's needed). For this reason, most well-written filetype plugins define a b:undo_ftplugin variable. This variable holds commands which will automatically be executed when the filetype changes away from the filetype which set it up. It is normally used to unmap buffer-local mappings, set options back to defaults/previous values, and the like. If you're sourcing your scripts after the default ftplugins either in your current Filetype autocmd, or in the ~/.vim/after/ftplugin directory, then you should append your commands to the existing b:undo_ftplugin rather than overwrite it. Check to make sure it exists() first! -- 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
