Piping files to gvim

Pipe an old version of a file to gvim and set filetype for syntax highlighting:

git show 1a2b3c:foobar.js | gvim "+set filetype=javascript" -

Fill the buffer with the output of a command and set a filename for later saving (:w):

ls -l | gvim "+file ~/foobar.txt" -

Alternate approach to above:

gvim '+r ! ls -l' ~/foobar.txt

Found the last two tricks here.

Overcoming filename spaces with git ls-files

If your filenames and/or directory names contain any spaces, it can be a headache to pipe them around in bash. Enter null terminated filenames.

git ls-files -z | xargs -0 grep -li <word>

From git help ls-files:

           \0 line termination on output.

From man xargs:

    • null
  • 0 Input items are terminated by a null character instead of by whitespace, and the

quotes and backslash are not special (every character is taken literally). Dis-

Syndicate content