Skip to content

Instantly share code, notes, and snippets.

@beaugunderson
Created July 31, 2011 01:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beaugunderson/1116249 to your computer and use it in GitHub Desktop.
Save beaugunderson/1116249 to your computer and use it in GitHub Desktop.
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)
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment