Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute file I'm editing in Vi(m)

Tags:

vim

exec

How to execute file that I'm editing in Vi(m) and get output in split window (like in SciTE)?

Of course I could execute it like that:

:!scriptname 

But is it posible to avoid writing script name and how to get output in split window instead just bottom of the screen?

like image 263
Alex Bolotov Avatar asked Jun 04 '09 22:06

Alex Bolotov


People also ask

How do I run a file in vi editor?

To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.

What is execution mode in vi editor?

This mode is where vi interprets any characters we type as commands and thus does not display them in the window. This mode allows us to move through a file, and to delete, copy, or paste a piece of text. To enter into Command Mode from any other mode, it requires pressing the [Esc] key.

How do I open a file in vim editor?

Open a new or existing file with vim filename . Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.


1 Answers

There is the make command. It runs the command set in the makeprg option. Use % as a placeholder for the current file name. For example, if you were editing a python script:

:set makeprg=python\ % 

Yes, you need to escape the space. After this you can simply run:

:make 

If you wish, you can set the autowrite option and it will save automatically before running the makeprg:

:set autowrite 

This solves the execute part. Don't know any way of getting that output into a split window that doesn't involve redirection to file.

like image 146
R. Martinho Fernandes Avatar answered Sep 28 '22 19:09

R. Martinho Fernandes