Gtk vim remove mapping of <C-Y> - vim

I used classic vim, but recently i moved to gtk-vim on ubuntu, but emmet plugin don't working, it is because when I press <C-Y> it copies above char to cursor position, i failed to disable it. When i set unmap or iunmap <C-Y> it writes that there is no maping, also this shortcut is not noted in imap.
EDIT:
I find out that i'm unable to imap, when i press any shortcut it just print it out, for instance
map <F2> :echo 'Current time is ' . strftime('%c')<CR>
is working well but
imap <F2> :echo 'Current time is ' . strftime('%c')<CR>
is printing <F2> to text

It looks like you've :set paste, which disables insert mode mappings and abbreviations. This option is meant for pasting text from the terminal (e.g. via middle mouse button); it should only be set during the paste itself, not permanently (and you can easily toggle this via the 'pastetoggle' option).
So, check via :verbose set paste?, then find the place where this is set, and disable it.
PS: Your demo imap needs <C-o> before it; else (if imaps are working, that is), you'd just insert the :echo ... into the buffer.
imap <F2> <C-o>:echo 'Current time is ' . strftime('%c')<CR>

Related

vim: Tagbar windows opened when typing <Enter> in normal mode

When typing <Enter> in normal mode in Vim with the Tagbar plugin installed, the Tagbar window is opened automatically. I want to disable this functionality. What must I do?
put the flowing code in you .vimrc
unmap <cr>
Your mapping for <C-m> is actually the cause of the Enter key opening Tagbar. If you remove that map from your vimrc, the enter key will no longer trigger :TagbarToggle.
Mappings for <C-m> and <CR> (Enter) are synonymous in Vim:
The following table shows the mapping between some of the keys on the keyboard and the equivalent Ctrl-key combination:
Ctrl-I Tab
Ctrl-[ Esc
Ctrl-M Enter
Ctrl-H Backspace
If you use one of the Ctrl-key combination in the above table in a map, the map also applies to the corresponding key. Both the keys produce the same key scan code. For example, if you create a map for CTRL-I, then you can invoke the map by pressing Ctrl-I or the Tab key.
This means when you set nmap <C-m> :TagbarToggle<CR>, it is the same as
also setting nmap <CR> :TagbarToggle<CR>.
You'll probably want to choose a new key instead of M. The alternative is to
change the key code sent by <C-m> at the operating system level with some
remapping program.
The terminal key bindings come from readline, the program that processes input text in
your terminal prompt. A full list of key bindings is in the readline
manual.
You can find more info about Vim key codes by typing :help keycodes in Vim, or reading the help docs here.
Try :help tagbar to open the documentation. It sounds like you might have a mapping in your vimrc file that says something like
nnoremap <silent> <CR> :TagbarToggle<CR>
or
nnoremap <silent> <CR> :TagbarOpen<CR>
if you find and remove that mapping will no longer open Tagbar

why is `ctrl -h` not work in insert mode?(version gvim 8.1.1)

In "Practical Vim" (second edition), the writer says <c-h> can delete back a character. I've tried in git bash, and it worked. However, it doesn't work in gvim in win10 as expected.
When I enter something in insert mode, I can use <c-h>, <c-w> and <c-u> before I leave insert mode. When I switch to insert mode without entering anything, <c-h>, <c-w> and <c-u> don't work.
Note that <c-h> is not mapped (:map <c-h> prints No mapping found).
Vim, by default, does only allow to delete characters that you typed since you entered insert mode. It does not allow to delete chars before the point where you started inserting. This behavior is inherited from the original Vi.
To change that, Vim has the option 'backspace'. It configures how <Backspace>, <Del>, <c-w> and <c-u> work. Add the following to your _vimrc and Vim will behave as you expect:
set backspace=indent,eol,start
Then you can backspace over autoindent, start of insert and end-of-lines.
See :help 'backspace'.

VIM: set term=xterm changes <BS> to <Del>, is it reversible?

I have added set term=xterm to my vimrc to be able to use 256-color vim schemes in terminal, but it comes at a price (at least for me). It also replaces (sort of) the BackSpace with Delete (i.e. BackSpace starts to delete forward just like Delete does) in insert mode and makes it "BackSpace" instead of moving left (or h) in normal mode. I have nothing against Ctrl-H as a way "to Backspace", but I simply don't want to have two delete buttons and ability "to BackSpace" (delete backward) in normal mode.
How can I reverse that change while retaining the setting I need?
PS I've read :h CTRL-h and a bit of :h xterm, but I couldn't find the solution.
Vim's inoremap and nnoremap commands can be used to adjust how keys are interpreted in Vim.
A solution is documented here for your specific context: https://conemu.github.io/en/VimXterm.html
The relevant quote:
"If you have problems with BS in Vim (BS acts like Delete key) under ConEmu when term=xterm, you may try to remap BS key:
inoremap <Char-0x07F> <BS>
nnoremap <Char-0x07F> <BS>
"
In general, when a key does not do what you want, the trick is to find out what it actually sends to Vim. Sometimes hitting Ctrl-V followed by that key in insert mode might help figure it out. Then inoremap and nnoremap as shown above can be used to reassign it to the behaviour you want in insert and normal modes, respectively.

Map <S-Insert> to paste content of clipboard in a filetype

I want to use <S-Insert> to paste the content of clipboard in vim irrespective me being in normal or insert mode
I am using [Fedora 23, Gnome terminal 3.18.3, vim 7.4 +xterm_clipboard]
The usual problem I have is:
I go on the web and Ctrl-C on multiple lines
Back to vim in Insert or Normal mode I want to paste WITHOUT indentation modification
And I get a paste with a messed up indentation but only when the file being copied to as a filetype like r/python (I guess because an indent is defined)
What I have found
I found this post (amongst others) but that's not working.
How I can make it work
When I use the paste mode it works
For example if I do
I go on the web and Ctrl-C on multiple lines
In vim :set paste
I do <S-Insert>
Then it works irrespective of mode OR filetype and I can :set nopaste
Another way is to paste from clipboard "+p which works (without messing with paste mode)
Leads ??
Thing is I am not even sure this is vim related, I think I cannot map <S-Insert> as if I do
nnoremap <S-Insert> <NOP>
inoremap <S-Insert> <NOP>
vnoremap <S-Insert> <NOP>
And start new terminal then vim and try <S-Insert> it still copies
I get a paste with a messed up indentation
This is because vim assumes the copied text as a stream of characters typed in to it.
If you can use system clipboard in vim, use these mappings
:map <silent> <S-Insert> "+p
:imap <silent> <S-Insert> <Esc>"+pa
You can find if vim has clipboard support using
vim --version
If you see "+xterm_clipboard", you are good to go. Use it with
set clipboard=unnamed " or
set clipboard=unnamedplus
If using system keyboard is out of the picture, my suggestion would be to write a function that takes you to paste mode with set paste, pastes the copied text, takes you back to normal mode with set nopaste

mapping function keys in vim

I want to map my F2 for nerdtree with the following entry:
map <F2> :NERDTreeToggle<CR>
But even before that, and after saving the vimrc , whenever i press F2, it just switches the case of the letters on which the cursor is present. Later found out that any function key does it. F5 switches case of 5 characters and so on. Is this because of some other plugin? I presently use c.vim , snippetsEmu , surround , nerdtree , and minibufexpl
There are no keymappings to any function key in my vimrc.
Your problem is that vim does not know what does terminal emit when you press <F2>. On some terminals it emits something like <Esc>[12~, so the vim quits current mode (or just beeps if it can't) (<ESC>), does nothing ([1: there must be some key after [, but not 1, so it does nothing) and changes case of two letters (2~). So, you should open .vimrc and write there the following:
set <F2>=<C-v><F2>
where <C-v><F2> means that you must press <C-v> and then <F2>. This line should tell the Vim the exact sequence of codes which is emitted by terminal when you press <F2>. After that, use noremap <F2> whatever and it should work. If it is not the only terminal that you are using, then you may want to put if $TERM==#"<C-r>=$TERM<CR>" before this line and endif after.
:map <F2> :NERDTreeToggle<CR>
After starting Vim you can look with
:map <F2>
what F2 is mapped to. It is possible that the plugins change the mapping (not visible in .vimrc)

Resources