6

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. Background The central concept for ...


5

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 ...


3

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 ...


3

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><...


3

How about hdiw? I.e. move into the space and then delete the "word" formed by the whitespace. That will give you: horse catdog 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.


3

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. "let b:...


3

I have an alternative recommendation, and a flexible script you can adapt. Use Digraphs 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 ...


3

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)] endfor lockvar! s:MAPSAVE unlet! s:key let s:mappingsEnabled = v:true inoremap <expr> <c-s> <sid>ToggleMappings() fu s:ToggleMappings() let i = 0 ...


2

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>&...


2

Check if you have set noescapekeys somewhere in your config. 'esckeys': 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 ...


2

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>" Largely ...


2

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... ...


2

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 V [...] 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 ...


2

An idea: 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) endfunction 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 ...


2

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 ...


2

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.


2

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 ...


2

Use combination of :h c_CTRL-\_e, :h getcmdline() and :h getcmdpos(): func! KillLineToEnd() return strpart(getcmdline(), 0, getcmdpos()-1) endfunc cnoremap <C-k> <C-\>eKillLineToEnd()<CR>


2

Well, you can do it with vimscript, here is the proof of concept: func! MyTab() abort let spaces = matchstr(getline(line('.')-1), '\%.c\s*') if len(spaces) return spaces else return "\<Tab>" endif endfunc inoremap <expr> <tab> MyTab() NOTE though, the example uses quite recent vim that has added \%....


1

Simply because a line break in the replacement component of the substitution command is represented by \r in Vim rather than \n... :s/,/\r/gc Alernatively, you can use this: :s/,/^M/gc 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 ...


1

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-...


1

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.


1

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.


1

(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 <S-Insert> 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: imap <...


1

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 ...


1

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 ...


1

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: function! FoldLevel(lnum) return ( max([ \ indent(prevnonblank(a:lnum)), \ indent(nextnonblank(a:lnum)) \ ]) / getbufvar('.', '&tabstop', 1) )...


1

In normal mode: cTt Then press space


1

Using Vim's jump to first letter in line can be useful in situations like this. dTt delete backwards until you reach letter t, but dont include letter itself.


1

function! s:get_char(num) abort if a:num == 0 return matchstr(getline('.'), '.\%' . col('.') . 'c') else return matchstr(getline('.'), '\%' . col('.') . 'c.') endif endfunction Without corner cases and can handle wide characters. Then function! s:is_surrounded(match_list) return index(a:match_list, s:get_char(0) . s:get_char(1)) >= 0 ...


Only top voted, non community-wiki answers of a minimum length are eligible