How to extrapolate variable in command mode in vim?

0

I want to know how to extrapolate the vim variables, for example, to format the file I am working on.

:!fmt -w  mifichero

when working in several directories referencing the path of the file It's tedious.

:!fmt -w /home/user/miproyect/lalaala/otro_directorio/otro_mas/mi_fichero

the idea would be to extrapolate some vim variable in the command mode.

Does anyone know?

    
asked by John 20.12.2018 в 03:44
source

1 answer

0

On the command line you can use the wildcard %:p to get the full path of the file you are editing. Obviously it will not work with a buffer that you have not yet saved the file, and of course, the command will only act with the last changes that you have saved. For example:

:!fmt -w 80 %:p 

If you want to redirect the output to the same buffer, you can do

:r !fmt -w 80 %:p  # En la posicion actual
:0r !fmt -w 80 %:p # Al comienzo del buffer

Or if you want to replace the entire content:

:% !fmt -w 80 %:p
    
answered by 20.12.2018 / 13:45
source