Accidentally I typed vim -y install python-requests instead of yum ... and I do not know how to exit from vim now. Standard option with shift + : + q! does not work. Are there any options how to exit from vim without killing it?
With -y (easy mode), Vim defaults to insert mode, and you cannot permanently exit to normal mode via <Esc>. However, like in default Vim, you can issue a single normal mode command via <C-O>. So to exit, type <C-O>:q!<CR>.
Alternatively, there's a special <C-L> mapping for easy mode that returns to normal mode.
-y option makes vim start in easy mode, you can type CTRL-L to return to normal mode and then type :q! to exit.
I use the gVim Easy, and it works for me to add the set im! in the .gvimrc.
gVim Easy v.s. gVim
It's good to remember that vim and vim -y (gVim Easy) are almost identical except for these differences:
vim starts out in NORMAL mode; vim -y starts out in INSERT mode.
Esc, Ctrl-[, and Ctrl-C exit INSERT mode in vim. However, these do not work in vim -y. Instead, these have been replaced with Ctrl-L.
And it's good to remember this important similarity as well:
In INSERT mode, both vim and vim -y will allow you to use the Ctrl- commands that work during INSERT mode. Examples include:
Ctrl-T to indent the current line.
Ctrl-D to dedent (that is, un-indent) the current line.
Ctrl-N and Ctrl-P to auto-complete the word currently being typed.
Ctrl-R x to paste the contents of register x where the cursor is.
and, relevant to this thread:
Ctrl-O to temporarily enter NORMAL mode to issue one NORMAL-mode command (after which you'll immediately return to INSERT mode).
Hopefully you'll see that this last one (the Ctrl-O command) will allow you to save (with :w), save-and-quit (with :wq), discard unsaved changes (with :e!), as well as simply quit-without-saving (with :q!).
You can also use Ctrl-O followed by a non-ex command, like u (for "undo"), dd (to delete the current line), ZZ (to save-and-quit), and ZQ (to quit-without-saving).
So if you're not familiar with using Ctrl- commands in vim's INSERT mode, I strongly recommend learning at least the Ctrl-O command, as remembering that will help you figure out how to exit (and save documents in) vim -y. (While knowledge of Ctrl-L will help with vim -y, knowledge of Ctrl-O will help in both vim -y and vim.)
Key Takeaways
If there are only two things you remember from this post, remember these:
vim's normal way of exiting INSERT mode (that is, Esc, Ctrl-[, and Ctrl-C) have been replaced with Ctrl-L in vim -y (Vim Easy).
The INSERT mode command of Ctrl-O works just as well in vim -y (Vim Easy) as it does in vim. So you can use it to your advantage to execute any NORMAL commands you want.
Related
In my init.vim for Neovim, I have the same line as in my .vimrc in Vim, which, when pressing F12, runs the file currently in the buffer using the python3 interpreter:
autocmd FileType python nnoremap <silent> <F12> :!clear;python3 %<CR>
Now I'm trying to run this tiny "test.py" script by pressing F12 in normal mode:
import IPython
IPython.embed()
Works fine in Vim:
But doesn't work in neovim despite exactly the same line in my ~/config/nvim/init.vim:
So it does run IPython, but then immediately (red arrow) inexplicably asks if I want to exit. It's also got a bunch of weird escape sequences inserted (yellow arrow) which I suspect are the reason why it wants to exit, and which don't appear with normal vim.
I don't really like the internal neovim terminal, so how can I get neovim to behave exactly like vim in this case?
This is a known limitation of NeoVim, :! is non-interactive and it will not allocate a pseudo-terminal which is typically required for full-screen applications such as IPython to run properly.
See issue #1496 for details.
An alternative is to use NeoVim's (or Vim 8's) support for terminal, with the :terminal command, or with a function such aa termopen() (in NeoVim) or term_start() (in Vim 8) to run full-screen applications such as IPython.
In your case, something as simple as :term python3 %, running the command in a terminal in a split, might be an adequate replacement.
You might also find the vim-bang-terminal plug-in interesting. It replaces a :! command with a similar command invocation that runs inside a Vim/NeoVim terminal instead.
I want to copy text from vim buffer to the system clipboard by using the command "*y but when I press the double quote sign in command mode, it doesn't seem to get fired at all as I don't see anything in the status bar (nothing gets copied also even if I blindly continue with the command). I can see all other commands in the status bar in vim. I'm using Ubuntu 12.04 and I have clipboard support enabled in my vim version.
You should press "+y in NORMAL (or VISUAL) mode.
If you love to do it in command line, do this:
:y +
(same for "*y)
:echo has('clipboard') returns 1, but whenever I execute "+yy" or "*yy" nothing seems to be in those registers. If I use regular yy to copy another line of text, then try to paste from the register using CONTROL+V nothing happens. If I try "+p vim pastes the line of text I copied using the regular yy command.
What's going on here? I'm on FreeBSD by the way.
Your vim version may not be compiled with X11 clipboard integration.
In vim run the :version command and look for xterm_clipboard in the output. It will be prefixed with a + (supported) or - (unsupported) sign.
What worked for me in Ubuntu 20.04 and Vim 8.1.2269
sudo apt install vim-gtk3
Explanation
This package adds support for the x_term_clipboard in vim if not present already.
For more info: Click Here, #blankblank's answer.
Another thing that could be going on is your DISPLAY environment variable is not being set correctly. This could happen sometimes if you're running vim from tmux or screen.
Try opening a new terminal, running echo $DISPLAY, and then from the terminal running vim, leave vim, execute export DISPLAY=:0 (but replace :0 with the output from your other terminal), and then re-enter vim and see if clipboard works by doing "+p.
If you have copy something to clipboard and paste that in vim, you can use "+p.
+ is a quoteplus, which means CLIPBOARD documented X selection. :help quoteplus for more information.
If you want to copy something in vim to clipboard and paste the content in the other place by Ctrl+v, you can do "+yy, this will copy the current line to clipboard.
more information about vim register:
:help registers
:help quotestar
I also met this problem.
My case is that DISPLAY is not set properly in tmux.
And I found a script to automatically update tmux DISPLAY.
My problem was my input source English (US, intl., with dead keys), in addition to vim not being compiled with x-clipboard.
I don't face the same issue on windows, but on Ubuntu 20.04 I have to press "<space>+y with this input source.
Edit:
Seems I can fix this by switching the input source to English (Intl. with AltGr dead keys)
how to select all and copy in vim insert mode? and is there another way to do it in normal mode?
I have tried visual mode and gg and shift + gg to select all and then yank, however that doesn't transfer it to the clipboard to be able to paste it in another application like skype or chrome browser.
I am sure this is a common task, and there are a lot of varieties by smarter ppl than me out there, please feel free to share yours.
In normal mode:
gg"+yG
In ex mode:
:%y+
There are a few important informations missing from your question:
output of $ vim --version?
OS?
CLI or GUI?
local or remote?
do you use tmux? screen?
If your Vim was built with clipboard support, you are supposed to use the clipboard register like this, in normal mode:
gg"+yG
If your Vim doesn't have clipboard support, you can manage to copy text from Vim to your OS clipboard via other programs. This pretty much depends on your OS but you didn't say what it is so we can't really help.
However, if your Vim is crippled, the best thing to do is to install a proper build with clipboard support but I can't tell you how either because I don't know what OS you use.
edit
On debian based systems, the following command will install a proper Vim with clipboard, ruby, python… support.
$ sudo apt-get install vim-gnome
ggVG
will select from beginning to end
#swpd's answer improved
I use , as a leader key and ,a shortcut does the trick
Add this line if you prefer ,a shortcut
map <Leader>a :%y+<CR>
I use Ctrl y shortcut to copy
vmap <C-y> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>
And ,v to paste
nmap <Leader>v :call setreg("\"",system("xclip -o -selection clipboard"))<CR>p
Before using this you have to install xclip
$ sudo apt-get install xclip
Edit: When you use :%y+, it can be only pasted to Vim vim Ctrl+Insert shortcut.
And
map <C-a> :%y+<Esc>
is not conflicting any settings in my Vimrc.
If you just want a simple way to copy file content from inside the terminal (you mention "copy text to another application"), then the cat command is easy to select/copy the output:
cat <filename>
For VS Code + vim you can:
"vim.useSystemClipboard": true,
and then
ggVGy
gg - go to the beginning of the file
V (capital) - start linewise visual mode
G (capital) - go to the end of file
y - yank (copy)
This works for me across applications in Ubuntu 22.04 and in Windows 11.
gg"+yG is more correct because it explicitly targets the clipboard (rather than a vim register), but "vim.useSystemClipboard": true, + ggVGy seems to work across applications so I use that since it's easier for me to type.
BTW. If using VS Code + vim then
"vim.useCtrlKeys": false,
allows using Ctrl+A.
My approach is to 'cat' the file content then make a selection with the mouse and scroll finally copying to the clipboard with Mac+C / Ctrl+C or even right click and then selecting 'copy'.
I installed cygwin on Windows 7. When I start vim in cygwin terminal it starts in interactive mode. I can't change mode to command one by pressing ESC. What could be the reason?
UPDATE:
Also vim prints these varnings at start:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
If by interactive mode you mean insert mode (where keypresses are inserted as text, just as in other editors), then your Vim is in easy mode.
In it, you can temporarily execute normal mode commands via Ctrl + O. But I guess you don't want this strange beginner's mode. To turn it off, check whether Vim has been invoked with the -y argument or as evim (is there a shell alias?). Or, if you find a :set insertmode command in a .vimrc, remove it. (By default, at least in my Cygwin installations, Vim is not configured for easy mode, so it must be something in your configuration.)
Try to
Press “ESC” and "shift" and ":" together;
You should find the place that you can type command line in vim;