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?

有帮助吗?

解决方案

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top