open vim file in new unix terminal - vim

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]

Related

how to start the neovim gio from the cli

I'm trying to switch from vim/gvim to neovim on Linux. Up to now my standard workflow started with opening the cli, navigate to my project directory, and run gvim <filename> with the file I intend to start working with.
With neovim I can start it from the KDE menu to get a nice GUI. according to the menu settings, it simply runs nvim with an optional filename parameter. But I don't find the way to run nvim from the cli in a way, that it starts the GUI. Running nvim <filename> simply starts the cli UI.
Google gave me a lot of interesting information, but not, what I'm looking for.
There are different GUIs for neovim. Check which one do you actually use and start it from the command line. Navigate to the KDE menu for neovim GUI, right-click on it and select Edit application... Go to the Application tab and check the Command edit box. There you'll see the actual command which is run by KDE when you select the corresponding menu item. You can create your own shell script or alias which will run this command and use it on the command line.
UPDATE
Maybe some parameter or environment variable is passed to nvim so it changes its behavior. You can try to see what system call KDE actually performs to start the editor. For example, I'm using KDE plasma, so pidof plasmashell gives me the pid which I need. Then:
strace -f -v -e trace=execve -p `pidof plasmashell` &> plasma.trace
After that go to KDE menu and start neovim. Terminate the strace command with Ctrl-C and check the plasma.trace file for the execve system calls made to start the neovim process.

How to make Vim open in a terminal instead of XQuartz when logged onto a remote server?

When I'm on my own computer's terminal, when I enter the command vim filename and vim opens the file in the terminal.
When I log into my school account using SSH, and I enter vim filename, nothing happens.
I assume it's trying to open it using XQuartz, which I recently uninstalled.
How do I make it open in the terminal window, like on my own computer?
I have tried not using -Y when logging on, but it doesn't make a difference.
Actually, there is a workaround. You can try to edit it using the scp option in Vim.
Just run vim scp://user#schoolserver.edu/path/to/your/file from your terminal and you'll start editing the file using Vim from your local machine.
If you want to learn more about scp in Vim type :help scp in Vim.

Freeing Terminal While Using gVim

Is there a way that I can free my terminal from running the gVim process w/o quitting gVim so that I can continue to use the terminal? I'd like to be able to
do something similar to what I do with emacs. With emacs I can either use the emacs [file] command to have the process run through the terminal, or I can use the runemacs [file] command to keep the terminal free.
I start gVim with the command:
gvim [file]
and then the terminal hangs until I :quit gVim. When I searched for an answer to this question on the web, people advised that the best thing to do was to use ctrl-z to suspend the vim process and then use fg to return. However, this fails to work for me in both command line and gVim mode. I'm using Git Bash for my terminal on Windows 7.
You could run gvim in background as any other process:
gvim [file] &
After executing this command you receive a message indicating the pid of the new process. When you end it you should receive a similar message on that shell.
Edit:
The ctrl-z/fg problem is probably related to windows. This question states that GitBash would create a new shell instead of returning to the current one, so it probably doesn't work as in Linux. A possible solution would be to run your commands from gVim, either calling the shell through :! on mappings, or plugins/commands (fugitive for git, :py or some plugin for python interpreter, etc).

How can I get vim to point to macvim? Where can I find macvim?

I would like vim to point to macvim :)
Probably through an alias.
vim is here: whereis vim
/usr/bin/vim
macvim I can't find, e.g.
whereis macvim returns nothing
The MacVim distro comes with a script called mvim that takes exactly the same arguments as vim. Put mvim somewhere in your path. Then, just set the alias: alias vim='mvim'
If you want to completely override the system vim, an easy way is to use Homebrew. Just install MacVim with $brew install macvim --override-system-vim. The --override-system-vim flag will create mvim symlinks to vi, vim, etc. You may find it a cleaner way to achieve the same goal. Plus, I prefer to use Homebrew as a package manager.
EDIT: Since you say you don't know where MacVim is, you may just want to download the latest tarball for your system and start from scratch. There are three files: the MacVim application, the mvim script, and a README.
Put MacVim in your Applications folder. Put mvim somewhere in your path.
Going forward, you should look for mvim using which rather than whereis. E.g. $which mvim #=> /usr/local/bin/mvim
which returns the pathnames of the files which would be executed in the current environment. whereis checks the standard binary directories, and may miss files included in your personal path.
Alternately, use Homebrew, as I suggest above and it will manage the location of both files.
My answer is kind of the opposite of michaelmichael's and I've made it quite a few times:
MacVim comes with a CLI executable that you can use in place of Mac OS X's default Vim if you add a single alias to your ~/.bashrc/~/.profile. No need to compile anything, no need to put MacVim in a special place, no need to overwrite default programs with symlinks
This way, you can stay in CLI-land and enjoy the power of a powerful/recent/fast Vim.
EDIT
MacVim is a native Mac OS X GUI version of Vim. It doesn't come preinstalled with your OS so you have to download it from the Internet or install it through homebrew (see michaelmichael's answer). Once it's installed, MacVim is where you have put it, plain and simple.
Because it's a full fledged GUI app, MacVim can't really be used as a drop-in replacement for the default Vim in the terminal.
`$ MacVim file.txt` will not work. `$ open -a macvim file.txt` will not work either.
You basically have two options: use the mvim CLI wrapper to open MacVim from the terminal or use an alias to MacVim's bundled CLI executable.
The mvim wrapper
I think michaelmichael's answer could be a expanded a bit but the most important is said.
EDIT: well scratch that.
The bundled CLI executable
Just add this line (customized to reflect your system) to your ~/.bashrc or ~/.profile or whatever file is run by your shell at startup:
alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
Open a new terminal window, $ vim file.txt should launch vim in your terminal window, just like the default /usr/bin/vim but with a lot more bells and whistles.
After installing mvim, you can find where it is located with typing into terminal:
which mvim
On my system this gave me:
/usr/local/bin/mvim
Then you create an alias in .bash_profile by typing the following in your terminal, and hit enter:
echo alias vim='/usr/local/bin/mvim' >> .bash_profile
Restart your terminal and try typing:
vim .
This should launch mvim and not vim

How do I open a new window (shell) from command line in Linux?

I'm working with a tool right now that requires me to putty to a remote host, login, run a series of commands to start an engine, open a new window (and login again) to start a different engine, then open a third window (and again, login) to actually use the tool (leaving the engines running in those first two windows). I'd like to write a shell script to automate the process so that I could just open one window, type "sh whatever.sh" and be off and running, without physically opening the new windows and logging in again. However, I can't find a command to get me from one window to the next. Any thoughts?
You can just background the first processes by adding an ampersand (&) to the command line or pressing Ctrl+Z when it is running (and then enter bg to let the process continue, more information about that with jobs).
If that's not enough, you can create virtual shells with screen or tmux.
If you've redirected X (i.e. you can access GUIs over ssh), you can also just start a new window by executing your favorite (GUI) console program, like xterm, konsole, gnome-terminal, etc.
Are you familiar with jobs on linux?
nohup whatever_1.sh &
nohup whatever_2.sh &
nohup whatever_3.sh &
Or perhaps screen would be of use here:
https://serverfault.com/questions/25301/job-control-and-ssh
See also, nohup:
http://en.wikipedia.org/wiki/Nohup
The bash command opens a Bourne-again shell (bash) session.
Try typing in "konsole". That should open a new bash window and set the focus to it.
On my Ubuntu 18 I just type the command:
gnome-terminal
and a new shell opens... I don't like the above answers because xterm and konsole most likely not already be installed.
Shell script on target machine cannot be aware of putty windows on client machine.
Consider using Screen : http://www.gnu.org/s/screen/ - it is clean and powerful way.
I think you need command line window then write:
$ xterm
# new window started
If you need python in new window:
$xterm python
#now a window will shown with python shell
Another nice option from Xfce's terminal:
xfce4-terminal

Resources