:s...">

How to call vim function from inside the map and ": split"

I would like to map the key using the "map" from my vimrc file as follows:

map <CI> :split ~/some/file 

This command is working fine.

My question is: how do I call the vim function (in this case, "resolve ()") on this path to the file from the map / split line. This does not work, but hopefully you understand:

 map <CI> :split =resolve("~/some/file") 

Perhaps he uses call ()? I'm obviously confused about vim scripts in general. Thank you for your help!

+4
source share
2 answers

There are two additional ways to do this that will work outside the display, and it is safer using <Cr> (POSIX resolves file names with any byte, but \x00 , including control codes):

 nnoremap <Ci> :execute "split" fnameescape(resolve("~/some/file"))<CR> nnoremap <Ci> :split `=resolve("~/some/file")`<CR> 

In the second case, escaping is not required, but the file name should not contain a new line (this will not hurt, it will simply lead to an error).

Other things to consider:

  • Use nnoremap , it will allow you, for example, to exchange values ; and : without changing the maps, and also not allowing your map to be corrupted by plugins if they do not redefine the <Tab> display (same as <Tab> ). The forced normal mode is here, because in other modes it will give unexpected results.
  • Escape arguments: fnameescape(resolve("~/some/file")) , this will prevent errors for filenames with spaces.
  • You can write <Cr> where @Austin Taylor suggested writing source control code. I do not like if any of them are inside the file, because it will make it impossible to view in the terminal.
+6
source
 map <CI> :split ^R=resolve("~/some/file")<cr><cr> 

If you put this in .vimrc , type Cv Cr to type ^R

+1
source

All Articles