I want to press CTRL-; to generate the special character ö. I have tried to write this line in my .vimrc
inoremap <C-;> <C-K>o:
but nothing happens when I press CTRL-;. What am I doing wrong?
If you already have ö, why not use it directly?
inoremap <key> ö
Anyway, the core issue, here, is that the control character ^; doesn't exist. This means that TUI Vim, which cares about characters, not keys, can't see that Ctrl+; you pressed and thus can't do whatever you mapped to <C-;>.
I would suggest you find another mapping.
Related
In my vimrc, I've remapped jk to escape using imap.
The problem emerges when I use jk; it doesn't escape, it only echoes out <Esc>.
Here's the entry in quiestion:
imap jk <Esc>
It's also a good point to make that I'm also using vim-X11 in fedora.
It looks like your 'cpoptions' settings contains <; then, special key codes like <Esc> are not recognized.
Find out where this got set via
:verbose set cpo?
or re-write the mapping to use a literal Escape character; enter it via Ctrl + V Esc; it should appear as ^[ in the buffer.
PS: Though not related, you should usually use :inoremap unless remapping is required.
For those who are here because of the title, the jk mapping will also not work when :set paste is enabled.
Right now in Vim when I go to a new line (or press 'p' or 'o' in normal mode) I get a lovely automatic indent, that also disappears if I exit insert mode without adding anything to it.
Is there a way to bind something to before I exit insert mode, such as inserting a phantom character then removing it?
Argh, I just read about this exact thing like two days ago but I can't remember where.
Anyway, the trick is to input a character right after <CR> and delete it immediately. There are a bunch of ways to do it:
<CR>a<Esc>x
<CR>a<C-w>
<CR>a<BS>
--EDIT--
Vim being Vim there are probably many other ways.
To automate these, you need to add a mapping to your .vimrc:
inoremap <CR> <CR>a<BS> " insert mode mapping for <CR>
nnoremap o oa<BS> " normal mode mapping for o
But I'm not sure you should overwrite defaults like that.
--EDIT--
However, what is annoying with Vim's default behaviour is that you may need to do some <Tab><Tab><Tab><Tab> before actually inputing some text on non-indented line or do == when you are done or rely on the automatic indentation rules for your language at the next <CR>.
All that can be skipped by using <S-S> which puts you in INSERT mode right at the correct indentation level.
Try either cc or S in normal mode to change a line with respect to indention. No need for phantom characters.
:h cc
:h S
A mapping like the following should do the trick:
imap <esc> <esc>:s/\s\+$//<CR>
This one deletes trailing characters when you press esc in insert mode.
I've got a problem with backspaces in Vim. If I hit backspace, the last character gets removed. I'd like to get the Vi (not Vim) behaviour. In Vi backspace moves the cursor to the left, and if I type in something, the characters I backspaced get replaced.
I tried
:imap <BS> <Left>
It works in GVim (even if the backspaced chars don't get replaced), but it does not work
in Vim. If this helps, I use the standard XTerm as my terminal emulator, and my $TERM environment variable is set to 'xterm'.
I believe you want Replace instead of Insert mode. Hitting the 'insert' key once will put you into Insert mode but hitting it twice will put you into Replace mode. That should give you the expected behaviour.
I like to use hlsearch but I hate to keep everything highlighted after searching, to solve this problem I could simply use :nohlsearch or an abbreviation of it but that is still to much effort so I decided to try to do that on pressing escape. What I came up with is:
nnoremap <ESC> :nohlsearch<CR>
This works exactly as I want it to in GVim which I usually use for development but it does not work in vim.
If I search something in vim, press escape to deactivate the highlighting and use one of the arrow keys to navigate vim goes directly into insert mode and inserts a character on a new line.
As I never really came around to using h, j, k and l for navigation this is really annoying and I would like to know how I can make vim behave like gvim.
If you need more information you can find my entire vim configuration here.
Your problem is that when you press <Up> terminal sends something like <Esc>OA (you will see it if you type <C-v><Up> in insert mode) which is remapped to :nohlsearch<CR>OA. I do not know any solution except not mapping a single <Esc>, try either mapping to double <Esc>.
I created this map to disable search when press double <Esc>
nnoremap <silent> <Esc><Esc> :let #/ = ""<CR>
is :noh still too much work?
EDIT: I don't know about you, but I personally think :noh is easier than pressing Esc key, since I can press all the buttons without stretching my pinky too far (which is why I think the default mapping of Esc for going back to Command Mode from Insert Mode is a bit unfortunate). If you really use the :nohlsearch that much, you probably should remap it to something you can reach from the Home Area (i.e. regular letters, or numbers, or perhaps Ctrl-letters).
Anyway, typing the exact command you give works in my vim (on gnome-terminal). Are you sure you put the rule in .vimrc file, instead of .gvimrc? No luck after restarting vim? Try :source /path/to/config/file and see if that makes it to work.
I'd like Ctrl-Backspace to delete the current word in vim insert mode. From within xterm I can pull this off via
:inoremap <C-H> <C-W>
but in gnome-terminal I cannot figure out a way to make it happen.
When in vim insert mode, if I type control-v and then press backspace, I get ^H in xterm, and ^? in gnome-terminal. Unfortunately,
:inoremap <C-?> <C-W>
doesn't do the trick in gnome-terminal; control-backspace just erases a single character no matter what.
Regarding ASCII codes:
Gnome-terminal lets you change the backspace character under Edit -> Profile Preferences -> Compatibility. Unfortunately, no option works, as far as I can tell: whatever character I apply to Backspace via the settings, if I try mapping the character itself, like
:inoremap <C-H> <C-W>
then regular backspace and control-backspace both erase an entire word; and if I try mapping control plus that character, like
:inoremap <C-^H> <C-W>
then regular backspace and control-backspace just erase a single character.
gnome-terminal's libvte would need to be patched.
libvte already has several options to map backspace, none of which distinguish Ctrl-backspace. It needs an option that does, maybe one that follows the behaviour of the linux console (^? for backspace, ^H for Ctrl-backspace). See this gnome bug.
2015 update: this was fixed in 23c7cd0f99d504cbab06d4c27254d4f3e2807ba8.
libvte 0.41.90, 0.40.3 and newer have the fix.