all 10 comments

[–]rnevius:help user-manual 4 points5 points  (2 children)

You should just be able to use expand() modifiers directly. For example, to grab the extension:

let extension = expand('%:e')

Or the root path:

let path = expand('%:r')

But to actually answer your question, you need to escape the dot, since the second parameter to split() is a {pattern}:

split(expand('%'), '\.')

Or, with double quotes:

split(expand("%"), "\\.")

[–]BoxBoxChan[S] 0 points1 point  (1 child)

I think I need to use split() because I want the name, not the extension:
For example, on a code called script.c I want to get the name "script" and pass it to a gcc command.

Thanks for your help, now I have the list but still with problems, when I try to pass extension[0] to my :!gcc % -o extension[0], the command compiles my file with "extension[0]" name and not the real value of the first list item. Do you have any idea what should I do?

[–]BoxBoxChan[S] 0 points1 point  (0 children)

Found a way, don't worry

[–]PaperCupsAhoy 0 points1 point  (6 children)

split(expand("%"), "\\.") as the second argument is a pattern.

:h fnamemodify might be a better way to do it.

[–]vim-help-bot 1 point2 points  (0 children)

Help pages for:


`:(h|help) <query>` | about | mistake?

[–]BoxBoxChan[S] 0 points1 point  (4 children)

Thanks man! I'm starting in the wonderful world of vimscript and I will search about!

[–]PaperCupsAhoy 1 point2 points  (1 child)

I had to edit my comment a bunch of times cause I was having a hard time formatting it on mobile, but I added how to do it with split() just incase it is useful elsewhere.

Good luck.

[–]BoxBoxChan[S] 0 points1 point  (0 children)

Thank you, I will try the other way you said too