vim - how to map Ctrl-y to "+y in visual mode? - vim

I can yank a visual selection into the X clipboard in vim using "+y - I would like to map this to something more convenient. I tried mapping to Ctrl-y by adding
:vmap <C-y> \"+y to my .vimrc but it doesn't work. How can I do this?

In ~/.vimrc add:
vnoremap <C-y> "+y<Esc>
or Ctrl-Shift-y:
vnoremap <C-S-y> "+y<Esc>
Make sure that your terminal does not already use that shortcut. For Gnome terminal see this.
Tip: if using default Gnome terminal shortcuts, paste that C-y yanked chars with: C-S-v in terminal or just C-v elsewhere.

The problem was that I was escaping the " character. This, it seems, is wrong in this context. simply:
:vmap <C-y> "+y
works, as expected.

Related

Resize Splits in Vim after NERDTreeToggle

I am looking for a way to automatically resize my open v-split panes in Vim after I call NERDTreeToggle.
I have NERDTreeToggle being called on the shortcut "ctrl+\" at the moment, and ideally what I want is to call the keyboard shortcut "ctrl+w =" immediately afterwards.
Any ideas? Thanks.
If this is your current mapping:
:nnoremap <C-\> :NERDTreeToggle<CR>
You can just append the window command after it:
:nnoremap <C-\> :NERDTreeToggle<CR><C-w>=
Alternatively, you can execute this from command-line mode as well, via :normal!:
:nnoremap <C-\> :NERDTreeToggle<Bar>execute "normal! \<lt>C-w>="<CR>
Note that for window commands, there's also a special :wincmd to invoke them:
:nnoremap <C-\> :NERDTreeToggle<Bar>wincmd =<CR>

Arrow keys in vim (linux) in insert mode broken for me

When I use the arrow keys in vim in insert mode I get letters inserted instead of movement.
Up produces an A
Down produces a B
Left products a D
Right produces a C
Does anyone know what would cause this?
Thanks in advance
If these keys work fine in normal mode, but do not in insert then you must have some mappings to the first one or two characters (normally <Up> is either <Esc>[A (terminals that use CSI) or <Esc>OA (xterm)). Try checking out output of
verbose imap <Esc>
, there should be not much mappings starting with <Esc> in insert mode (I have none, for example). I can say, that with arrow keys working normally in insert mode, using
inoremap <Esc> <Esc>
produces just the same behavior as if you had problems with terminal recognition or had 'compatible' set.
Your vim seems to be starting in the vi compatibility mode. Do this
Open Vim editor,
Get the path of your home directory by typing :echo $HOME
Check if you have .vimrc file in $HOME location,(if you don't have create it)
Add the following line line to .vimrc file
:set nocompatible
Find more solutions for the same problem here ( Especially if your problem is terminal related, the re-mapping of keys solution might work for you )
The following worked for me. Just put it in your .vimrc
:set term=cons25
Open Vim editor.
Get the path of your home directory by typing: :echo $HOME.
Check if you have .vimrc file in $HOME location, and if you don't have create it.
Add the following line line to .vimrc file: :set nocompatible
Reference: http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell
None of the answer here worked for me. I'm in Linux, with konsole/yakuake terminal and tmux. This fix works for me:
nnoremap <silent> <ESC>OA <ESC>ki
nnoremap <silent> <ESC>OB <ESC>ji
nnoremap <silent> <ESC>OC <ESC>hi
nnoremap <silent> <ESC>OD <ESC>li
inoremap <silent> <ESC>OA <ESC>ki
inoremap <silent> <ESC>OB <ESC>ji
inoremap <silent> <ESC>OC <ESC>hi
inoremap <silent> <ESC>OD <ESC>li

vimrc help : trying to map Ctrl-s to :w

My current .vimrc file is
syntax on
colorscheme zellner
set nu
set ruler
set si "Smart indet
map <C-s> :w<cr>
I thought the last line would allow me to hit control-s to automatically save while in normal mode?
{
The last line is just the trim downed version of what I really want which is
map <C-s> <esc>:w<cr>a
}
Am I forgetting something?
I'm using vim 7.3 that came with my mac.
Like mentioned if you want it on both modes you have to just put
inoremap <C-s> <esc>:w<cr>a
nnoremap <C-s> :w<cr>a
in your .vimrc.
But note that if you are using the terminal vim then you might have a problem
mapping ctrl-s. By default it stops the flow. In that case add the following to your .bashrc (not sure if the same problem in zsh):
stty -ixon
If I got it right, you want
:inoremap <C-s> <esc>:w<cr>a
Whoops, just read you want it in normal mode
:nnoremap <C-s> :w<cr>
When you're writing commands in vim files (like .vimrc) you don't need the :. It is only a method of entering commands on the command line.

Custom Hotkeys in gvim

I am using gvim under linux and I really love it, the problem I have with it is that Shorcuts like Crlt+C doesn't work...
I added the following code to my gvimrc but it doesn't have any effect :/
nmap <C-V> "+gP
nmap <C-V> "+y
nmap <C-A> ggVG
nmap <C-Z> u
nmap <C-Y> ^R
The problem is not that the shortcuts don't work, rather than that you don't know what the shortcuts are supposed to do.
It might help for you if you add behave mswin to your .vimrc. It remaps many key bindings to behave more like other programs.

Why doesn't "map! <C-q> :q <CR> " work in vim?

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>

Resources