Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Prompt to edit a corresponding .scss file when opening a .css file in vim
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)
" e[dit] the file
exe "e" file
" Execute the autocommands for the file
exe "doautocmd BufReadPost" file
" Execute EditScss() whenever a *.css file is read
:au BufReadCmd *.css call EditScss()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment