I want to remap the Ctrl + y command in vim (scroll up command) to Ctrl + q.
I tried to do
:map <C-q> <C-y>
But it does not seem to work...
Do you have any suggestion ?
Does this only affect the Linux terminal (not GVIM), and also Ctrl + S? Then, you need to disable the terminal's flow control commands, by putting the following into your ~/.bashrc:
stty start undef stop undef
PS: You should use :noremap; it makes the mapping immune to remapping and recursion.
Related
With gvim, I can map <C-LeftMouse>, but I can't with vim running inside a terminal emulator (konsole in my case).
I have reasons to think it's because the sequence Ctrl + CLICK is not sent/detected :
in insert mode, typing Ctrl + V, Ctrl + CLICK prints "" with gvim, but only "" with konsole.
how to make vim / neovim to recognize this (useful) combination ?
EDIT Note that I already set mouse=a in vim
in the terminal you have to enable the mouse:
set mouse=a
map <C-LeftMouse> :echo 'Hello Left'<CR>
map <C-RightMouse> :echo 'Hello Right'<CR>
see :help mouse
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.
The following command in vimrc works well for vim in my ubuntu os,
:map 11 :tabnext 1<CR>
,while in my CentOS system, i entered '11', it returns:
, i have to delete '<CR>', and then enter the "Enter" key to jump to tab 1;
All the '<CR>' in vimrc doesn't work, it seems the vim can't recognize '<BR>' as "Enter" KEY, anyone help me?
Try to replace <CR> with Ctrl + VEnter.
It looks like your CentOS system starts Vim in Vi-compatible mode. To be exact, the < flag in 'cpoptions' seems to be set.
Try launching Vim via vim -N or by putting set cpo-=< before the mapping definition. If this fixes the issue, you probably want to permanently disable Vi-compatible mode, by putting set nocompatible at the top of your .vimrc.
I input :map! <C-q> :q <CR> in command line mode, then return to normal mode, and press ctrl-q, but vim does not quit. Why?
As Johnsyweb suggested, Ctrl-Q does not reach Vim in the first place. This holds for the popular Ctrl-S as well. Both can be fixed by adding
silent !stty -ixon > /dev/null 2>/dev/null
to your .vimrc as it forces these control sequences to reach the application.
Why anyone would want to add yet another way of quitting Vim to the plethora already available is beyond me. However...
On Fedora 15, Ctrl-Q is likely being captured by your terminal as XON (resume) and therefore not reaching Vim to quit the application.
You can check if there's an error in your mapping or a clash like so:
:verbose map! <C-Q>
:map! is for specifing mappings in insert and command-line modes.
normal-mode mappings are (usually) specified like so:
:nmap <C-Q> :q<CR>
In vim, how can I map "save" (:w) to ctrl-s.
I am trying "map" the command, but xterm freezes when I press ctrl-s.
If I give ctrl-v,ctrl-s still I see only a ^, not ^S.
Ctrl+S is a common command to terminals to stop updating, it was a way to slow the output so you could read it on terminals that didn't have a scrollback buffer. First find out if you can configure your xterm to pass Ctrl+S through to the application. Then these map commands will work:
noremap <silent> <C-S> :update<CR>
vnoremap <silent> <C-S> <C-C>:update<CR>
inoremap <silent> <C-S> <C-O>:update<CR>
BTW: if Ctrl+S freezes your terminal, type Ctrl+Q to get it going again.
In linux with VI, you want to press Ctrl-S and have it save your document. This worked for me, put the following three lines in your .vimrc file. This file should be located in your home directory: ~/.vimrc. If this file doesn't exist you can create it.
:nmap <c-s> :w<CR>
:imap <c-s> <Esc>:w<CR>a
The first line says: pressing Ctrl-S within a document will perform a :w <enter> keyboard combination.
The second line says: pressing Ctrl-S within a document while in 'insert' mode will escape to normal mode, perform a :w <enter, then press a to get back into insert mode. Your cursor may move during this event.
You may notice that pressing Ctrl-S performs an 'XOFF' which stops commands from being received (If you are using ssh).
To fix that, place these two commands in your ~/.bash_profile
bind -r '\C-s'
stty -ixon
What that does is turn off the binding of Ctrl-S and gets rid of any XOFF onscreen messages when pressing Ctrl-S. Note, after you make changes to your .bash_profile you have to re-run it with the command 'source .bash_profile' or logout/login.
More Info: http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files
vim
# ~/.vimrc
nnoremap <c-s> :w<CR> " normal mode: save
inoremap <c-s> <Esc>:w<CR>l " insert mode: escape to normal and save
vnoremap <c-s> <Esc>:w<CR> " visual mode: escape to normal and save
zsh (if you use)
# ~/.zshrc
# enable control-s and control-q
stty start undef
stty stop undef
setopt noflowcontrol
bash (if you use)
# ~/.bash_profile or ~/.bashrc
# enable control-s and control-q
stty -ixon
Mac OSX Terminal + zsh?
In your .zprofile
alias vim="stty stop '' -ixoff; vim"
Why?, What's happening? See Here, but basically for most terminals ctrl+s is already used for something, so this alias vim so that before we run vim we turn off that mapping.
In your .vimrc
nmap <c-s> :w<cr>
imap <c-s> <esc>:w<cr>a
Why? What's happening? This one should be pretty obvious, we're just mapping ctrl+s to different keystrokes depending on if we are in normal mode or insert mode.