I’m currently using MacVim and I’d like to print out all the files in my working tree. Is there a way to simply do this, perhaps using the hardcopy
command?
Try any one of the following commands to see recursive directory listing: ls -R : Use the ls command to get recursive directory listing on Linux. find /dir/ -print : Run the find command to see recursive directory listing in Linux. du -a . : Execute the du command to view recursive directory listing on Unix.
The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.
A convenient way to execute a command for a group of files is to
(1) collect the list of their names, define it as the new argument list
(see :help arglist
), and then (2) iterate the command over that list.
1. To perform the first step, use the :args
command with
a wildcard matching the desired files. For example,
: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 details about wildcard syntax, see :help wildcard
.
If the path to the root of a subtree containing files to print is unknown beforehand and is built by a script, use the command
:exe 'args' join(map(split(glob(p . '/**/*'), '\n'), 'fnameescape(v:val)'))
where the variable p
is supposed to contain the path to that
root directory.
2. For sending files in the argument list to the printer, execute
the :hardcopy
command for those files using the :argdo
command:
:argdo hardcopy!
The !
specifier suppresses the modal dialog for selecting printing
parameters.
A more complicated command can be used to print each file to a separate PostScript document located at the same directory as that file:
:argdo hardcopy! >%:p.ps
Here the name of a printed file is concatenated with the .ps
suffix
to get the name of a corresponding PostScript file (see
:help cmdline-special
).
For speeding up the :argdo
argument command, Vim ignores the
Syntax
autocommand event by adding it to the eventignore
list.
This implies that if Syntax
autocommands had not been run for
a file in the argument list before the :hardcopy
command is
:argdo
ne, the corresponding printed document would not be
syntax highlighted (despite syntax:y
being set in printoptions
).
To execute Syntax
autocommands for all files in the argument
list, use the following command first:
:argdo set ei-=Syntax | do Syntax
To do this in the same run as printing, concatenate the two commands:
:argdo set ei-=Syntax | do Syntax | hardcopy! >%:p.ps
Edit Sorry, I misunderstood before.
To print all, say php and C# files in your working directory:
:args ./*.{cs,php} **/*.{cs,php}
:argdo ha
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With