Created
July 31, 2011 01:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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