How to run Vim commands from Terminal

断了今生、忘了曾经 提交于 2021-02-07 14:42:57

问题


My questions is one that I haven't seen answered, the usual question is how to run certain commands to a file.

My question is how to run Vim commands or functions, from outside Vim (i.e. Terminal), these wouldn't affect any file, just Vim itself. Is this is even possible? If so, how?

If this is not possible like this, is there a way to go into Vim, run a command automatically, and then exit when that ends? Or run another command and then exit?

Thanks for your help!


回答1:


Use

vim --cmd 'Command launched before vimrc' \
     -c 'Command launched after vimrc' \
     -c 'qa!' # Quit vim

. For running a command in an existing vim session you have to use +clientserver feature: run one vim with

vim --servername vim

and others with

vim --remote-send '<C-\><C-n>:Command<CR>'


来源:https://stackoverflow.com/questions/13522599/how-to-run-vim-commands-from-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!