Skip to content

Instantly share code, notes, and snippets.

@dprea
Last active January 27, 2016 21:06
Show Gist options
  • Save dprea/a35863788bcb93f3eb97 to your computer and use it in GitHub Desktop.
Save dprea/a35863788bcb93f3eb97 to your computer and use it in GitHub Desktop.
Shell Script - Open Vim then Write Text then Save and Quit Vim
# Uses Vim to create a text file (file.txt) with text 'hello'
# Save and quit Vim
vim file.txt -c '$put =\'hello\' -c 'wq'
# -----------------------------------------------------------------------------------------
# SOURCE http://stackoverflow.com/questions/5978108/open-vim-from-within-bash-shell-script
# -----------------------------------------------------------------------------------------
# vim -c
# -c => pass ex commands.
# Example: vim myfile.txt -c 'wq' to force the last line of a file to be newline terminated
# (unless binary is set in some way by a script)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment