public
Created

Prompt to edit a corresponding .scss file when opening a .css file in vim

  • Download Gist
.vimrc
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
function! EditScss()
" The current file
let file = expand("%")
 
" The current file's basename plus .scss
let scss = expand("%:r") . ".scss"
 
" If the file exists
if filereadable(scss)
" Prompt the user and store the user's choice (1-indexed) in a variable
let choice = confirm("Do you want to edit " . scss . " instead?", "&Yes\n&No", 1, "Question")
 
" If the user picked [Y]es
if choice == 1
" Set file to the escaped scss filename
let file = fnameescape(scss)
endif
endif
 
" e[dit] the file
exe "e" file
 
" Execute the autocommands for the file
exe "doautocmd BufReadPost" file
endfunction
 
" Execute EditScss() whenever a *.css file is read
:au BufReadCmd *.css call EditScss()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.