susam / vimer

Declutter your desktop by opening files in existing instance of GVim/MacVim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why use `findstr` to create an empty file on Windows?

b- opened this issue · comments

commented

I was perusing the code here after seeing this on lobste.rs, and I was very confused by the following line,

vimer/vimer.cmd

Line 185 in 23a5246

findstr "^" > "%stdin_file%"

I don’t have a Windows computer handy to see if there’s anything going on that I’m missing, but based on the comment it sounds like this just creates an empty file, a la touch on *nix. If this indeed is what’s going on, copy nul > file is a more supported (and potentially faster) way to do just that.

commented

The command findstr "^" > "%stdin_file%" mimics the behaviour of cat > "$stdin_file" on Unix. Compare

vimer/vimer.cmd

Line 185 in 23a5246

findstr "^" > "%stdin_file%"
with

vimer/vimer

Line 170 in 23a5246

cat > "$stdin_file"
to see the similarity.

Here is an example on Windows:

C:\>echo hello | findstr "^"
hello

C:\>echo hello | findstr "^" > out.txt

C:\>type out.txt
hello

Here is a similar example on Unix:

$ echo hello | cat
hello
$ echo hello | cat > out.txt             
$ cat out.txt
hello