Print all files with Vim recursively

I am currently using MacVim, and I would like to print all the files in the working tree. Is there a way to do this, perhaps using the hardcopy command?

+6
source share
2 answers

A convenient way to execute a command for a group of files is to collect a list of their names, define it as a new argument list (see :help arglist ), and then repeat the command on these files in the argument list.

  • To complete the first step, use the command :args using the pattern matching the desired files. For instance,

     :args ./**/* 

    sets the argument list to the names of all files in the current directory and its subdirectories; Similarly

     :args /tmp/**/*.{c,h} 

    selects all .c and .h files in /tmp and its subdirectories. For more information on wildcard syntax, see :help wildcard .

    If the path to the root of the subtree containing the files to print is unknown in advance and the script is built, use the command

     :exe 'args' join(map(split(glob(p . '/**/*'), '\n'), 'fnameescape(v:val)')) 

    where it is assumed that the variable p contains the path to its root directory.

  • To send files to the printer argument list, execute :hardcopy for these files using the command :argdo ,

     :argdo hardcopy! 

    Specifier ! suppresses the modal print options dialog box.

    A more sophisticated command can be used to print each file into a separate PostScript document located in the same directory as the file.

     :argdo hardcopy! >%:p.ps 

    Here the name of the print file is combined with the suffix .ps to get the name of the corresponding PostScript file (see :help cmdline-special ).

    To speed up the command :argdo -argument Vim ignores the Syntax auto-command event, adding it to the eventignore list. This means that if Syntax autocommands were not run for the file in the argument list before the command :hardcopy :argdo ne, the syntax will not be highlighted in the corresponding printed document (in the case of syntax:y set to printoptions ). To run the Syntax auto command for all files in the argument list, use the following first.

     :argdo set ei-=Syntax | do Syntax 

    To do this at the same start as printing, combine the commands:

     :argdo set ei-=Syntax | do Syntax | hardcopy! >%:p.ps 
+6
source

Edit Sorry, I did not understand before.

To print everything, say the php and C # files in your working directory:

 :args ./*.{cs,php} **/*.{cs,php} :argdo ha 
+3
source

Source: https://habr.com/ru/post/899751/


All Articles