Question

I was happily editing some .rb files using different buffers and the fantastic vim plugin Ctrlp. However out of the blue when I reopened a specific file , in particular micropost.rb all the automatic indentation and syntax highlighting doesn't work.

I am pretty sure it has something to do with the fact that I let Vim delete .micropost.rb.swp, i.e. the according swap file, before opening it. And that there is some kind of left-over from the swap file.

Now, even if I 1) Backup the file 2) Write micropost.rb from scratch. No detection of .rb file happens.

Note however that if I start writing the same code in a new file, say picopost.rb, everything works as expected.

EDIT 1, this is my .vimrc:

execute pathogen#infect()
set runtimepath^=~/.vim/bundle/ctrlp.vim
syntax on
filetype plugin indent on
set number 

"" ADD A line to diferently indented blocks of code
set list lcs=tab:\|\ 

let mapleader=","
" Fast saving
nmap <leader>w :w!<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
"set expandtab

" Be smart when using tabs ;)
set smarttab

" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4

" Linebreak on 500 characters
set lbr
set tw=500

set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines


" a combination of spaces and tabs are used to simulate tab stops at a width
" other than the (hard)tabstop
set softtabstop=4


""CTRLP mappings
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'

"folding settings
set foldmethod=indent   "fold based on indent
set foldnestmax=10      "deepest fold is 10 levels
set nofoldenable        "dont fold by default
set foldlevel=1         "this is just what i use
hi Folded ctermbg=darkgrey
"Autosave folding state at quit
au BufWinLeave * mkview
au BufWinEnter * silent loadview

""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2

" Format the status line
"set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
"

"Splits configuration
set splitbelow  
set splitright


"Max out the height of the current split   ------  ctrl + w _
"Max out the width of the current split------ ctrl + w |
"Normalize all split sizes, which is very handy when resizing terminal-------- ctrl + w =
"Swap top/bottom or left/right split ------ Ctrl+W R
"Break out current window into a new tabview ---------- Ctrl+W T
"Close every window in the current tabview but the current one  -------  Ctrl+W o
Was it helpful?

Solution

Your own answer led me to guess at the cause of your problem.

You apparently have an autocmd that automatically saves a view when you quit a buffer, and loads the view again when you re-enter the buffer.

Thus, if you have "options" included in your 'viewoptions' option, then any options you manually set on a file after the first load gets them from you filetype plugins, will be remembered forever.

Probably you somehow cleared the 'filetype' option on that one file, so now every time you load the file, an empty filetype is restored from your view file.

Possible solutions: 1. delete the current view file, remove "options" from your 'viewoptions' setting so it doesn't happen again 2. manually set the filetype, rely on your view file to continue restoring that type forever

Which solution you choose is up to you, and depends on whether you really want all the options you set on a file to be persistent or not.

OTHER TIPS

In case someone encounters this same weird behaviour. I solved the issue by deleting the file where the file view preferences where stored.

In my case such file was found in the default location:

/home/user/.vim/view/\=+root\=+to\=+file=+*filename.rb*

That solved the issue, since Vim had to redetect the filetype and view preferences from scratch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top