I need to check the file type I have opened in Vim to do one thing or another inside a function.
This is what my vimrc looks like:
function! MyFunction()
autocmd filetype typescript <C-V>%
autocmd filetype go <C-V>%
endfunction
nnoremap <Leadar>f :call MyFunction()<CR>
Next to <C-V>% will be more instructions, but for now this is what I'm testing.
My function has to detect the file I have openend, according to its type do one thing or another. I'm doing this inside a function because in the near future I will move this to a separete plugin, but for now it is my vimrc file.
Another thing I've tried already and I know it works is this
autocmd filetype typescript nnoremap <Leader>f <C-V>% DoTypescriptThings
autocmd filetype go nnoremap <Leader>f <C-V>% DoGolangThings
If I move this lines outside of a function body I works. But this way I couldn't change the <Leader> KEY easily if I make this a plugin. That's why I moved it to a function.
How can I make my function detect my types so my function works?