Whenever I am using gedit to write code I can access either gedit or the terminal but not both. For example, when I type gedit hello.c linux brings up the file hello.c inside gedit. Now, while gedit is still displaying hello.c I cannot type anything into the terminal without closing hello.c in gedit.
How can I get around this so that I may actively use both the terminal and gedit simultaneously?
Thanks
type gedit hello.c &
or if you have already typed it without the ampersand press Ctrl + Z to send it to background, and type bg to enable gedit as David pointed out.
if you already started gedit, press CTRL + Z, then type
bg && disown
dis will run gedit in background and disown it from the terminal (so gedit wont die if you close the terminal)
Related
Using Cygwin, I tried creating and editing a file in Vim:
touch test | vim
This is obviously a mistake; something like vim "$(touch test)" has a better chance of actually working. Nevertheless, this command throws the error:
Vim: Warning: Input is not from a terminal.
And after this, Vim opens and I exit the program with :q. Any subsequent commands I enter into the terminal are hidden from view until I restart Cygwin.
Why is this?
You don't understand what does a pipe | do in shell.
Pipe will take the pervious command's stdout as stdin to next command, in a subshell.
Your touch foo doesn't generate any output, what do you expect to happen? same for vim "$(touch test)".
If you want to create a file and open it in vim in one shot, you can try:
touch foo && vim foo
If you want to edit it with vim anyway, actually, you can simply just:
vim foo
then save the buffer after your editing.
How to open existing vim file from unix shell (bash) in new terminal (not in same/new tab of existing terminal) on local machine ?
Also is there any way to split file on new terminal (not in same/new tab of existing terminal) from inside vim ?
How to open a new terminal is platform dependent; This doesn't really have a whole lot to do with vim itself.
For example, if you're using GNOME you could do this by running gnome-terminal -e "vim $filename" & disown. Look up the documentation for the terminal emulator you're using to find out how to launch a new terminal and execute commands in it.
Another (IMHO much better) solution is to simply use GVim for situations like these, unless you have a very good reason to run vim in the terminal (if you're running this over ssh this won't work anyway, in that case you're better off using a terminal multiplexer like screen or tmux).
PS: bash isn't a terminal (emulator); bash is a shell. If you just run a new instance of bash it'll run in the same terminal, which is not what you want here.
Try this:
vim [your file]
If this isn't working for you, make sure you have it installed with:
sudo apt-get install vim
If you're already IN vim do
:edit [your file]
If I run gedit in the Linux terminal ($ gedit) it opens as a background job; which is not what I'm after at the moment.
Other programs (such as emacs) run in the foreground with commands like ($ emacs) and only run in the background if I've specified it via something like ($ emacs &).
I've tried searching for a solution but almost everything is about the opposite (trying/struggling to get things to run in the background).
Any ideas?
As it works for me: I run gedit /tmp/file.txt for the first time and it runs in the foreground. Then I open another terminal tab and run gedit /tmp/file2.txt while Gedit is still open — the second command instructs running instance of Gedit to open second tab and exits immediately. Gedit is still in the foreground in the first terminal tab.
According to gedit help, it has an option
-w, --wait Open files and block process until files are closed
If in the second terminal tab I run gedit --wait /tmp/file3.txt, then it opens a new tab in the existing Gedit window but the command stays in the foreground until I close that file tab.
Just in case: it was tested under KDE, Ubuntu 16.04, gedit version is 3.18.3
I am using Ubuntu 12.04 and Octave:
$ octave
octave:1> _
I set my editor to gedit:
octave:1> edit editor "gedit %s"
I edit a function:
octave:2> edit someFunction
gedit opens someFunction.m as expected and prompt returns while gedit still has the file open:
octave:3> _
I run some other long-running function:
octave:3> runAllTests
While runAllTests is executing I press CTRL-C to interrupt it.
The observed behavior is that runAllTests is interrupted AND gedit is killed.
The expected behavior is that runAllTests is interrupted AND gedit is NOT killed.
Does anyone know how to stop CTRL-C from killing gedit in this circumstance? Alternatively is there another way to interrupt runAllTests without killing gedit?
The setting:
edit editor "gedit %s &"
causes octave to place the editor "in the background", so CTRL-C does not effect it and has the expected behaviour.
Try:
edit mode async
which specifies asynchronous mode of execution of the edit command
The problem is CTRL+C is also a copy command. IT may need to be customized as in Octave GUI Xoctave. They claim that customization is available.
Unfortunately, putting the forked process in background with '&' is not enough when working with the command line (octave-cli).
There is a bug open on the GNU Octave development webpage about this issue.
Of course it is not only an editor problem, but any new forked process is affected. For instance
octave> system("$TERM&")
creates a terminal in a new window, which would be killed by subsequent <ctrl-c>.
I propose a shell-based workaround. This consists in adding an additional layer of "forking in background", which would protect the final terminal (or text editor or whatever) from the signals sent to octave. In brief, I launch a terminal which launches another terminal in background, from which I kill the first terminal (so that it does not bother us).
Create an executable:
term-kill.sh
-----------------------------
#!/bin/sh
$TERM&
sleep 0.01
kill $1
-----------------------------
(note the sleep commands without which the second terminal does not have time to get detached from the first before the latter gets killed). Then, the command
octave> system("$TERM -e term-kill.sh $$&")
creates a single terminal which won't get killed.
To open a text editor, simply consider the executable
term-edit-kill.sh
------------------------
#!/bin/sh
$TERM -e $EDITOR $1&
sleep 0.01
kill $2
------------------------
and change the octave edit command through
octave> EDITOR('$TERM -e term-edit-kill.sh %s $$')
N.B.: I assumed that your system knows how to find term-kill.sh and term-edit-kill.sh, and that the variables $TERM and $EDITOR exist and suit your needs. The terminal emulator must support the -e option.
I am using gcc to compile c code that I am writing in gedit. My problem is that while my .c file is open in gedit, any command I type into my terminal just hangs until gedit is closed. Obviously it is quite cumbersome editing, saving, closing, running, reopening etc. I was wondering how I can have gedit open while compiling so I don't have to close it every time?
Are you launching gedit from that same terminal? This may be a stupid answer, but make sure you're launching gedit with an ampersand, i.e. using the command line gedit &. Without the &, that terminal window won't let you execute additional commands until gedit closes. With the &, gedit runs in the background. Gcc should have no problem compiling a file that's open in an editor. But remember that only the most recent saved version will be seen by gedit, so save your work before trying to compile.
run gedit in background. Like
gedit yourfile &