Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "%:r" in vimrc file?

Tags:

vim

vi

filenames

  1. What is %:r in vimrc file?
  2. what is difference between :gcc and :!gcc ?
  3. what is % in vimrc file?

I'm studying vi/vim...but it's hard for me. I want information about vimrc operations. where can I get it??

I really appreciate all answers.

like image 664
JKU Avatar asked Dec 24 '22 12:12

JKU


1 Answers

Let's answer your questions in order…

  1. What is difference between :gcc and :!gcc?

    :something is an ex command. You can find a complete list of available ex commands under :help ex-cmd-index and look for help on a specific command with :help :something.

    :gcc is not an existing ex command.

    :!something calls the external command something so :!gcc would call gcc.

  2. What is % in vimrc file?

    It's not anything specific to your vimrc. When used as argument to an external command, it represents the current file name. Assuming the current file name is foobar.c, :!gcc % is expanded to gcc foobar.c before being passed to the shell.

    See :help c_%.

  3. What is %:r in vimrc file?

    Again, it's not anything specific to your vimrc. :r is a file name modifier applied to the current file name. Assuming the current file name is foobar.c, %:r would be expanded to foobar.

    See :help filename-modifiers.

It looks like you are trying to make sense of a command similar to:

:!gcc % -o %:r

which, again assuming the current file name is foobar.c, should be expanded to:

gcc foobar.c -o foobar

before being sent to your shell… and result in a foobar executable right beside your foobar.c.

like image 131
romainl Avatar answered Jan 16 '23 13:01

romainl