Question

I have mapped <Leader>ev to open .vimrc for editing using:

nmap <Leader>ev :e $MYVIMRC<CR>

I now wish to map <Leader>ec to edit currently used colorscheme file, and also map <Leader>es to edit current filetype syntax file. I don't want to hard code the paths (or part of the paths) as I will be moving around between environments. It will help me quickly adjust color/syntax in middle of editing.

Any help?

Was it helpful?

Solution

The paths from which Vim loads colorschemes, plugins, etc., are determined from the 'runtimepath' setting. The globpath() function can perform lookups from it. By taking the first match, we'll get the path to the current colorscheme:

:echo get(split(globpath(&runtimepath, 'colors/' . g:colors_name . '.vim'), "\n"), 0, '')

Something similar can be done for filetype plugins; the current one is in &filetype.

To insert the path into the mapping, you can use <C-R>= (insert register contents, used with the expression register):

:nnoremap <Leader>ec :edit <C-R>=get(split(globpath(&runtimepath, 'colors/' . g:colors_name . '.vim'), "\n"), 0, '')<CR><CR>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top