Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a shell command through vimscript?

Tags:

shell

command

vim

In my Vim setup I'd like to add a configuration that runs a shell command with a certain mapping. Is there any possible way to do this in Vimscript?

like image 525
beakr Avatar asked May 26 '12 12:05

beakr


2 Answers

vim has a a system() function:

:call system('date')
like image 138
kev Avatar answered Oct 06 '22 11:10

kev


I do this with traditional vi, so I assume it would work with vim as well.

In my .exrc I have:

map ^_ !}fmt 71 72^M

(That's a ^_ entered by typing ctrl-V ctrl-_, and a ^M entered by typing ctrl-V ctrl-M

When I hit ctrl-_ in vi, it reformats my current line to 72 characters.

like image 45
ghoti Avatar answered Oct 06 '22 13:10

ghoti