Vim Ex mode loads when opening terminal - node.js

I know little about Vim in terminal(Mac) and the other day I was working copy and pasting text and i think I accidently did it when in terminal. Now whenever I open terminal it instantly loads on Vim Ex mode. I know how to quit Ex mode once in terminal but is there any way i can get rid of Vim loading when I open Terminal?
Thanks
Edit: To explain further to what i mean when I open terminal.app from Utilities I get the following
and the only way I get back to the command prompt is by typing quit every time I open terminal and i cant understand why the Vim process is running in the first place.
I was just outside the terminal in a document copy and pasting text then accidentally did a command v to paste within terminal which resulted in this happening.

It appears that you've accidentally updated one of your shell startup scripts so it launches vim.
If your default shell is csh or tcsh, take a look at .cshrc, .tcshrc, and .login in your home directory, and look for a command like vi -e or vim -e.
If your default shell is bash, check .bashrc and .bash_profile.
It may be easier to figure out which file you messed up by checking which file in your home directory was modified most recently:
% ls -altr $HOME | tail
-a lists all files, including files whose names start with ..
-l gives you a long listing, showing timestamps.
-t sorts by modification time.
-r reverses the order, so newer files are shown last

Related

How do I run a shell command from vim in the existing terminal SCM session?

Here's the problem statement:
I open a GNOME terminal and run a startup script setup_myproject_view1 which sets up an SCM session and sets some enviroment variables.
I open terminal vim and start browsing through some files often in multiple split panes (:sp, :vsp)
I realize that I need to edit and save one or more of these files. But before I can do that I need to check out the file from the SCM server/depot.
Now I have multiple options:
Close all my vim panes and run the checkout command in the shell and then open one or all of the files I had open before. Very tedious.
Open a new terminal window or tab and run the startup script and checkout the file. Then return to the original terminal, run :e to load the file again with write permission enabled and proceed to edit it. Still tedious because I have to run the startup script (so I have to remember which project view I'm working in) and switch through windows/tabs.
Run the shell check out command from vim using :shell or :!. This would be ideal because I'm quickly able to return to editing without breaking my train of thought. But the shell inside vim again does not have the startup session setup_myproject1_view1. Nor do I want to put setup_myproject_view1 to run automatically in my shell's .cshrc file because I have different projects and views: setup_myproject3_view2, etc.
So how can I run a shell command conveniently from vim without having to setup the SCM project view?
you can pause vim using ctrl+z, do your checkout and then resume it with fg if you invoked vim from a bash shell. For more information see bash job control
An alternative, you should modify your setup script to export variables to underlying shells. For example if your script is like this:
# script.sh
MEH=4
you will get this result when you use it:
source script.sh
vim
:shell
echo $MEH
exit
but if you change it like this:
# script.sh
export MEH=4
you will get this result when you use it:
source script.sh
vim
:shell
echo $MEH
4
exit

Cygwin terminal input disappearing after quitting vim

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.

What will this command do

I accidentally ran the following command in my console.It was a copy paste error.
vim -> /etc/apache2/sites-available/25-xyz-https.conf.
But after that my 25-xyz-https.conf got corrupted. Eventhough I recovered the file just curious to understand what has happened.
This happens:
vim -
means open stdin in vim.
> file
is an output redirection by the shell. Stdout of the (vim) process will get stored in file. file will get truncated by the shell before the (vim) process get's started.
I recommend to always put a # into the shell before pasting things into the shell. That gives you a chance to review the line before executing it, especially if you paste the line together with the line break at the end. (which would execute it right away)
The shell ran "vim -" and then redirected the output from that command to /etc/apache2/sites-available/25-xyz-htttps.conf
If you run "vim -" you'll see it do something like this:
Vim: reading from stdin...
You will have to hit ^C to break out of reading from stdin, then :q to exit vim.
This is because many utilities interpret the '-' character as stdin (or stdout, depending on the context).
If you did something like:
date | vim -
This would open 'vim' with the contents of the document showing the current date. There is no open file, you could not simply :w to save the file, but you could :w./thedate.txt to save the contents to ./thedate.txt. The important thing is that the output of the 'date' command became the input to the 'vim' command.
After that, the > character just redirects stdout from the whole "vim -" session to overwrite the file provided.

vimdiff immediately becomes stopped job, crashes terminal when I try to fg it, but works with GUI

SOLVED: the problem was this line in my .vimrc:
set shell=/bin/bash\ -li
UPDATE: it appears the problem is due to my .vimrc (renaming the .vimrc to 'hide' it fixed the problem), so it probably has nothing to do with Mint.
I'm running Linux Mint 17 Cinnamon. When I run vim -d file otherversion in the terminal, I get a blank screen with
"otherversion" 18L, 218C
[1]+ Stopped vim -d file otherversion
user#machine:~/path/to/directory$ ;2R
If I do fg 1 that terminal window just closes. Also, there's no blinking cursor, though I am able to type. Same with vimdiff instead of vim -d. I've tried multiple distributions of vim, some that include the GUI, some that don't.
However, with versions that do include the GUI, if I run vim -d -g file otherversion, it works as expected.
I'd rather not depend on gvim to use vimdiff.
Any advice?
Thanks
If you need an interactive bash shell (to get your bash aliases for instance), use this code in your .vimrc instead of removing the option:
if &diff == 'nodiff'
set shellcmdflag=-ic
endif
This will only enable the interactive bash shell when not running vimdiff, so that you will have you bash aliases when running vim.
After removing the following line from my .vimrc, the problem went away:
set shell=/bin/bash\ -li
Thanks to comment from #FDinoff, the same problem at my end got solved.
The problem was "bash" command in my ~/.cshrc.
I had put that to avoid entering into bash every time after login. It was working fine until this issue started coming whenever I used to open vimdiff.
Removing ~/.vimrc didn't help me either. Then I read comment from FDinoff. There, he suggested that it could be related to shell, if "less" and "man" have also stopped working. I observed the same issue in my case, that helped me rule out the corruption in .vimrc.
After removing "bash" from my ~/.cshrc, the problem went away completely.

adding a shell script to a configuration file

I'm pretty new to shell scripting and linux in general. Basically, I need to change the configuration file for logging out so that when a user logs out, a certain shell script is run.
Now, I've located the logout configuration file and opened it with vi using this command
$ vi ~/.bash_logout
At this point, I'm experiencing some very weird behavior. When I try to type a character, the cursor jumps around seemingly erratically. What could this be due to? I'm running the latest version of ubuntu.
And once I get that figured out, what's the command to run a .sh file from within this configuration file?
If you're having trouble with vi, try using nano instead. nano .bash_logout
If you do need to use vi for some reason, "i" will put the editor into insert mode, and ESC will take it out of insert mode when you're done. ":wq" will write and quit the editor.
To run a command, just put it in the .bash_logout file as you would type it on the commandline.
Some other useful commands:
a insert after selected character
o insert at next line
O insert at previous line
r replace a single character
R replace mode
:q! quit without saving
:w save
:wq save and quit
To get familiar with Vi and its brother Vim ("VI improved") I recommend the book "A Byte of Vim", you can read it online or download for free at http://www.swaroopch.com/notes/Vim
You can permanently change your editor option. To find out what your current one is, type this:
export | grep -i edit
To change it on Ubuntu:
sudo update-alternatives –config editor
On any other BASH prompt, just do this:
export EDITOR="nano"
Replace 'nano' with 'vi', 'emacs', or any other preferred editor. You can also add this to your .bashrc by typing the following:
echo 'EDITOR="nano"' >> ~/.bashrc

Resources