So I'm in a file and can't get out, I'm on SSH so can't reset terminal. Can anyone help? There is no information online that I can find, 99% of the results are about Vim but I'm not using Vim.
I've tried CTRL+C, CTRL+D, :quit, exit, quit, ESC and many more,
I've also tried all options in the opposite case.
There's multiple ways which worked for me, here they are.
Option one was to press CTRL+X+C, the X first is important.
Although you said you had tried this, so on to option two. Do what I said above, but putting C first, then you should have an input at the bottom, enter ! and it should exit the editor.
You're welcome.
Hold the Ctrl button. Press 'x' button, release it, then press 'c' button: Exit Emacs
Reading the answers and the comments, it is very strange, that Ctrl+x then Ctrl+c is not working. All key combinations in Emacs are bound to commands, also Ctrl+x Ctrl-c. It is bound to the command
save-buffers-kill-terminal
So what you can try is press Alt-x to execute a command. You should see M-x in the minibueffer at the bottom of emacs. then enter save-buffers-kill-terminal and voilá, you exited emacs. (Emacs will ask, if you have unsaved buffers or running processes, otherwise it will exit directly)
Hope this helps.
Related
I am new to vim, and I learn that you can interact with the terminal two ways while in vim. The first is to type: ! . The second is :term, when you have a terminal side by side with your source code. As soon as I press :term, my cursor is in the terminal. How do I switch back to the my source code and vice versa? The answer over here does not really help. I tried the key combinations C-W, and then :bn but it only exits terminal, then back to terminal again.
(How do I run a terminal inside of Vim?)
As :help :terminal says, you can always exit to normal mode using <Ctrl-\><Ctrl-N> (:help CTRL-\_CTRL-N). Use i to return to terminal interaction.
You can swich terminal with :shell or :sh and turn back to Vim with exit. You can also use C-z and fg couple in same matter.
I have a problem that have been bothering me for days now.
Whatever I do, I simply cannot place any single {,},[ or ].
Every time I try, it takes me up to the next or previous paragraph. I've looked it up and I can't find a good way to unmap it and finally have my azerty keyboard to behave correctly so I can peacefully code
In the normal mode, press 'i' to enter the insert mode.
And you can start to edit your file.
After everything is done, press the 'ESC' key and then ':wq' to save your modification.
Vim / vi has several different modes. This dates back to the times when you would edit using a teletyper, i.e. no "visual" representation of the data you are editing, no mouse etc.
With only the "usual" keys at your disposal, you need to navigate in the data, you need to insert data, and you need to execute commands on the data. Not so coincidentially, these are the three modes of Vim / vi, and in each mode, the keys do something differently.
By default, the editor starts in the "normal mode", which you will use to navigate, and enter the other modes from.
In this mode, ) moves you to the end of the sentence, ( to the previous sentence. } and { do the same for paragraphs, combinations of [ and ] work with chapters.
If you enter "insert mode" (most simply by pressing i in "normal mode"), you can enter all the above letters normally. You exit "insert mode" by pressing <Esc>. You will recognize "insert mode" by -- INSERT -- being displayed in the bottommost line of the screen.
If you are in "insert mode", and pressing any of the above keys does move your cursor instead of entering the corresponding symbol, there is some (broken) configuration at work. Check your ~/.vimrc, and if necessary, rename it and try again with a "clean" configuration.
It is next to impossible to do Vim / vi justice in the scope of a SO answer. It is very much an expert-friendly editor, not a novice-friendly one. You need to actually learn how to use this editor, but it is absolutely worth it in the long run.
In insert mode, you should be able to insert brackets without trouble.
In normal mode, those correspond to motions.
To go to insert mode from normal mode, press i.
See: :h object-motions
Alright, Problem Solved ! I had to uninstall and reinstall the Ubuntu bash on windows 10 multiple times and it worked ! Thanks for the help everone !
Sometimes I start to search and replace something with :%s/string/..., then quickly change my mind. Or, maybe I am manipulating my tabs. I want to quickly return to the cursor position I just left.
Is there a way to cancel that command/go back to the editor using a single shortcut? It's kind of tedious having to just backspace through the command.
Obviously this is very nit picky, but perhaps the answer is simple.
Ctrl+c
:help CTRL-C
CTRL-C
CTRL-C Interrupt current (search) command. Use CTRL-Break on
MS-DOS dos-CTRL-Break.
In Normal mode, any pending command is aborted.
Use Ctrl+C to abort the current command.
Just press CTRL+C which will abort the command.
ESC key should also work.
More vimish :)
I just started using Vim as an IDE. I was using it as a test editor for a while now, so I didn't have to go to command mode very often. But, since I program in Java, I have to go to command mode to make the file, compile/run it... etc.
The problem is: I need a good way to switch between the two modes.
I looked online and it says that the <Esc> key is supposed to do that, but that doesn't work for me (maybe it's not for gVim? I don't know why.)
I have to press CTRLO every time to go to command mode; the escape key works from that mode... it brings me back to insert mode. But is there a better, or easier, way of switching between command mode and insert mode?
Pressing ESC quits from insert mode to normal mode, where you can press : to type in a command.
Press i again to back to insert mode, and you are good to go.
I'm not a Vim guru, so someone else can be more experienced and give you other options.
Looks like your Vim is launched in easy mode. See :help easy.
This happens when Vim is invoked with the -y argument or as evim, or maybe you have a :set insertmode somewhere in your .vimrc configuration. Find the source and disable it; temporarily this can be also done via Ctrl + O :set noim Enter.
This has been mentioned in other questions, but ctrl + [ is an equivalent to ESC on all keyboards.
Using jj
In my case, the .vimrc (or in gVim it is in _vimrc) setting below.
inoremap jj <Esc> """ jj key is <Esc> setting
Coming from emacs I've found that I like ctrl + keys to do stuff, and in vim I've found that both [ctrl + C] and [alt + backspace] will enter Normal mode from insert mode. You might try and see if any of those works out for you.
For me, the problem was that I was in recording mode. To exit from recording mode press q. Then Esc worked as expected for me.
There is also one more solution for that kind of problem, which is rather rare, I think, and you may experience it, if you are using vim on OS X Sierra. Actually, it's a problem with Esc button — not with vim. For example, I wasnt able to exit fullscreen video on youtube using Esc, but I lived with that for a few months until I had experienced the same problem with vim.
I found this solution. If you are lazy enough to follow external link, switching off Siri and killing the process in Activity Monitor helped.
You can use Alt+H,J,K,L to move cursor in insert mode.
How could I exit Vim, not :q, and then go back to continue editing?
Assuming terminal Vim on a flavor of *nix:
To suspend your running Vim
Ctrl + Z
will suspend the process and get back to your shell
fg
will resume (bring to foreground) your suspended Vim.
To start a new shell
Start a subshell using:
:sh
(as configured by)
:set shell?
or
:!bash
followed by:
Ctrl+D (or exit, but why type so much?)
to kill the shell and return to Vim.
You can use :sh to exit to your default shell then typing $ exit at the shell prompt will return you to Vim.
You can switch to shell mode temporarily by:
:! <command>
such as
:! ls
You can also do that by :sus to fall into shell and back by fg.
If you frequently need to go back and forth between shell and vim, probably what you really want is have only one vim instance in the shell, and use it to open any file in the workspace. If so, check this question. Once you set it up correctly, you can :sus or C-z to return to the shell, then just v or v <newfile> to get back to vim.
And my answer is almost my daily routine.
If you are on a Unix system, Ctrl + Z will suspend Vim and give you a shell.
Type fg to go back. Note that Vim creates a swap file while editing, and suspending Vim wouldn't delete that file (you aren't exiting Vim after all). On dumb terminals, this method was pretty standard for edit-compile-edit cycles using vi. I just found out that for me, gVim minimizes on typing Z.
If you're using Neovim, you can do the following:
:terminal command to bring up a terminal window.
Do your terminal stuff
Type exit to kill the terminal process
Press any key to return to Neovim
Just put in fg and go back to your most recently suspended program.
There are several ways to exit Vim and have everything the same when you return. There is very good documentation within Vim itself explaining the various ways this can be done. You can use the following command within vim to access the relevant help page: :help usr_21
To give you a brief summary, here are the different methods of quitting and returning with your session intact:
Suspend and resume - You don't actually quit Vim with this; you simply hide your session in the background until you need it. If you reset your computer or issue a kill command to Vim, you will lose your session. This is good for when you want to switch to another task temporarily, but if this is the case, then you might want to look into using the GNU Screen utility instead.
Sessions - This is the true way of saving your session between instances of Vim. Even if you truly quit Vim, your session will be there for you when you return. This is probably what you are looking for.
To extend user Zen's answer, you could add the following line in your ~/.vimrc file to allow quick toggling between Bash and Vim:
noremap <C-d> :sh<cr>
If you don't mind using your mouse a little bit:
Start your terminal,
select a file,
select Open Tab.
This creates a new tab on the terminal which you can run Vim on. Now use your mouse to shift to/from the terminal. I prefer this instead of always having to type (:shell and exit).