Manually toggling :set paste/:set nopaste as suggested by francois P is cumbersome, and resetting the TERM variable as evaristegd suggests is a very bad idea as explained in the comments (which hint at the better solution below). The best solutions that I could find are explained here, and I'll briefly repeat them below.
The central concept for ...
I want to end up in insert mode after a macro. Is there a way to do that?
Yes! You can stop recording a macro using Ctrl+O, q (Ctrl+O is a sequence to enter a single Normal-mode command from Insert mode, see :help i_CTRL-O.) This will result In a macro that, when replayed, will leave you in Insert mode, after inserting any characters you have inserted as ...
As sussed out in the comments, you have mappings that begin with <esc> somewhere (and the surprise indicates you didn’t ask for them). You can use :verbose imap <esc> to find out where the mappings are coming from; in general, mappings with a prefix cause a delay whenever the prefix is entered, as vim has to distinguish between the prefix ...
Thanks to D. Ben Knoble I ended up using:
iabbrev <silent> main <C-O>:put! =join(readfile(...), \"\n\")<CR><esc>A
last <esc>A is needed in order to account for the extra space that abbrev inserts.
Edit (thanks to filbranden) - removing join():
iabbrev <silent> main <C-O>:put! =readfile(...)<CR><...
How about hdiw? I.e. move into the space and then delete the "word" formed by the whitespace. That will give you:
To keep 1 space between cat and dog, the best I can think of is ge2ldw, i.e. go to the end of the previous word, move to the second space in the gap, and delete to the start of the next word.
This looks like a textbook example of the sort of situation for which the 'keymap' option exists.
To use this option, first create a file ~/.vim/keymap/spanish.vim with the contents:
" Uncomment the following line to set a "short" name for the keymap.
" This will be shown in the statusline instead of the full keymap name.
I have an alternative recommendation, and a flexible script you can adapt.
Vim has wonderful support for a large swath of characters that are hard to enter on many ISO/American Keyboards (among others). Without even looking, I could tell that the digraph for ñ is n~ (and the same goes for most accented characters). Ironically, this isn't ...
As a naive attempt, try this:
inoremap a;o año
inoremap e;e eñe
const s:LHS = ['a;o', 'e;e']
let s:MAPSAVE = 
for s:key in s:LHS
let s:MAPSAVE += [maparg(s:key, 'i', v:false, v:true)]
let s:mappingsEnabled = v:true
inoremap <expr> <c-s> <sid>ToggleMappings()
let i = 0
If you don’t want to type non-breaking spaces, you can just map them to normal spaces. Doing so globally can be done by this command (add it to your .vimrc or init.vim file):
execute "inoremap \u00A0 <Space>"
If you want to map only in the current buffer, use <buffer>, like so:
execute "inoremap <buffer> \u00A0 <Space>&...
Check if you have set noescapekeys somewhere in your config.
Function keys that start with an <Esc> are recognized in Insert
mode. When this option is off, the cursor and function keys cannot be
used in Insert mode if they start with an <Esc>. The advantage of
this is that the single <Esc> is recognized immediately, instead of
Adding my comment as an answer on Rich's advice; while mappings don't apply in this case specifically, it's still a possible cause of the problem
Remapping <esc> can also trigger the problem.
In my case, I had a map like this:
inoremap <expr> <esc> pumvisible() ? "<C-o>:pclose<CR>" : "\<esc>"
One option is instead of trying to bind a key combination to this action, just use the default key binding for it, which is Ctrl+W.
See :help i_CTRL-W.
This same key binding should be available by default in zsh (or bash, etc.) so you could just use it everywhere with no need for custom configuration.
You could try to map Option+⌫ to do the same in Vim... ...
It depends if you can edit where your cursor is or if you need to move your cursor.
For example, you have the following:
Your cursor here
[...] hell [...]
and want to change hell into shell, you'd use i, to be in the good place directly (rather than using append, and move the cursor with the arrow key while in insert mode).
However, if you have the ...
nnoremap <expr> f FindInsert('f', 'i')
function FindInsert(find, insert) abort
const l:char = getchar()->nr2char()
return printf('%s%s%s', a:find, l:char, a:insert)
It would then be easy to add F/t/T, or to use a instead of i, or what have you.
But be aware that when you press ; or ,, you won't get this behavior.
Also, I ...
All you need to do is insert <C-\> before the <C-o>.
inoremap <C-_> <C-\><C-o>dB
Help for i_CTRL-\_CTRL-O says:
CTRL-\ CTRL-O : like CTRL-O but don't move the cursor
That's it. Well except for a caveat or two which I'll reproduce here for your convenience ;) ...
The CTRL-O command sometimes has a side effect: If the cursor ...
There isn't, but it is possible to create a mapping to do this. For example, if you want <leader>e to do the equivalent of e then i:
nnoremap <leader>e ei
Edit: as statox notes in the comments to the original question, whilst this is possible it may be symptomatic of non-idiomatic vim usage.
Since you're looking at pairing open/close tags across multiple lines (enclosing a block) and in your case it makes sense to insert the closing tag when breaking the line, my suggestion is to add a mapping to the Enter key in Insert mode and then use an <expr> to decide whether we need to add the closing tag. You can make that decision based on the ...
Well, you can do it with vimscript, here is the proof of concept:
func! MyTab() abort
let spaces = matchstr(getline(line('.')-1), '\%.c\s*')
inoremap <expr> <tab> MyTab()
NOTE though, the example uses quite recent vim that has added \%....
Simply because a line break in the replacement component of the substitution command is represented by \r in Vim rather than \n...
Alernatively, you can use this:
Where the ^M is entered by typing Ctrl+V then Enter
See :h s/\r and :h s/<CR>
FYI using \n will...
insert a <NL> (<NUL> in the file) (does NOT break the ...
So your issue is that you are actually trying to execute several commands while <C-o> only allows to run one. What you could do is create a user defined command which will be executed as only one command but will run everything you need:
command! FormatParagraph normal! mtvipgw`t
nnoremap <leader>fp :FormatParagraph<CR>
See :h user-...
Thank you for answering the question. Although no body found what the problem is, I still be thank to you.
The reason is timeout and ttimeout is off as the same time. It caused my vim waiting a operation forever. The solution is open the timeout. If you want to let your vim to be faster, you can turn on ttimeout and set ttimeoutlen to a low value. my is 100.
Fortunately, a solution is fairly simple
nnoremap <LeftMouse> <LeftMouse>i
This leverages the "nore" part of nnoremap, allowing you to use the built-in functionality of the map on the right-hand-side while overriding it via left-hand-side.
(First I think I have to say is that my environment is simply Terminal and zsh, all I use are built-in stuffs provided by macOS.)
In INSERT MODE I typed option + ⌫ then strangely
appeared (I think this is because I modified the Terminal preferences to make option + ⌫ be mapped to \033[2;2~) , then I used the following and it works:
I'm going to off an alternative perspective for forcing spaces everywhere: leave tabstop alone unless you're viewing files with tabs and you want them to be skinnier to save on screen real-estate. (So, leave it as default, 8.) This is more realistic, though in general one cannot control how tabs appear in foreign environments.
Set expandtab, of course (note ...
However, it doesn't mention softtabstop, why not?
I suppose it's because softtabstop can be set up independently.
Without setting softtabstop, every Tab I insert result in the default number of spaces for the filetype (4 for Python), and not the value configured for tabstop?
Actually it's vice versa. If you miss it, maybe it's because of Python's ftplugin ...
It seems like the indent fold method has some flaws, and this is one of them. My solution might not be the best, but here it is:
I created my own fold implementation in my vimrc:
return ( max([
\ ]) / getbufvar('.', '&tabstop', 1) )...