[vim] Implement fast switching between source/header & shaders

This commit is contained in:
Lara 2020-02-19 12:16:57 -05:00
parent 3f91e5f26f
commit 278a9565e2

18
vimrc
View file

@ -196,6 +196,8 @@ for prefix in ['i', 'n', 'v']
execute prefix . "noremap " . key . " <Nop>"
endfor
endfor
"[Switch quickly between source and header]"
nnoremap <leader>f :e <C-r>=SwapExtension()<CR><CR>
@ -242,6 +244,22 @@ function! ChangeScriptMode()
endif
endif
endfunction
"[Swap file extensions, for example cpp/h]"
"https://stackoverflow.com/a/22145246"
function! SwapExtension()
let [rest, ext] = [expand('%:r'), expand('%:e')]
if ext ==? 'h'
let ext = 'cpp'
elseif ext ==? 'cpp'
let ext = 'h'
"swap between vertex and fragment shader"
elseif ext ==? 'vsh'
let ext = 'fsh'
elseif ext ==? 'fsh'
let ext = 'vsh'
endif
return rest . '.' . ext
endfunction
" Only do this part when compiled with support for autocommands.
if has("autocmd")