Skip to content

Instantly share code, notes, and snippets.

@johnnadratowski
Last active July 28, 2017 04:16
Show Gist options
  • Save johnnadratowski/64a06465fe31b198a234e7cae4594940 to your computer and use it in GitHub Desktop.
Save johnnadratowski/64a06465fe31b198a234e7cae4594940 to your computer and use it in GitHub Desktop.
vimdo - Terminal apply vim normal command to files in batch. Automatically apply vim commands to multiple files.
#!/bin/sh
# Basically just runs vim commands as ":execute normal", saves the file, and quits for each file in a loop
vimdo() {
local CMD=$1
shift
for f
do
vim -N -u NONE -n -c "set nomore" -c ":execute \"norm! $CMD\"" -cwq! $f
done
}
# Examples:
#
#
# vimdo "GddggP:%s/Foo/Bar/g\<CR>" ./foo.go
# -- Move the last line of a file to the top, and rename every occurrance of Foo to Bar
#
# vimdo "/Func\<CR>f)i, newParam\<ESC>" ./*.go
# -- Search for Func function, and add a parameter called "newParam" as the last argument
#
#
# References:
#
#
# StackOverflow - Executing VIM commands in a shell script - https://stackoverflow.com/a/18865698
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment