New answers tagged

2

Two separate issues! Firstly, adding | to a keybinding (officially called a map, if you don't mind me nitpicking) is tricky. It is a special character so it must be escaped. Here are two examples of how to do this: nnoremap x :echo "hi" \| echo "hi2" <CR> nnoremap x :echo "hi" <Bar> echo "hi2" <CR> ...


2

I am author of SpaceVim. The main feature of spacevim is key binding guide. This feature need to run :map <prefix> to paser all mappings, and generate guide context. In vim, too many default key binding begin with g, most users include me do not remenber all of them. so I need the guide when I forgot next key after press g.


0

I guess all bracketing plugins have this behaviour for brackets at least. This is the case of lh-brackets for instance. And it's quite easy to extend to anything else. The important part is CR+ESC+O, O is what will ensure a correct indent. See this related answer on SO: https://stackoverflow.com/questions/35708395/how-to-move-opening-curly-braces-to-a-new-...


0

It should work out of the box if you have these patches: 8.2.0852 cannot map CTRL-S on some systems 8.2.0856 CTRL-S stops output Although, I would rewrite the mappings: nnoremap <c-s> :<c-u>w <bar>echo 'Saved'<cr> inoremap <c-s> <c-\><c-o>:w <bar>echo 'Saved'<cr>


2

From :help CTRL-{char}, under notation section, CTRL-{char} {char} typed as a control character; that is, typing {char} while holding the CTRL key down. The case of {char} does not matter; thus CTRL-A and CTRL-a are equivalent. But on some terminals, using the SHIFT key will produce another code, ...


0

Use <C-_>. For example, to map Ctrl/ to :help, noremap <C-_> :help<CR> Reference: To be determined.


1

Alright, so: I am having a remarkably hard time finding the section of the documentation that discusses how the right-hand-side of a mapping is interpreted (i.e., how the keycodes are read during :map and then later used upon execution). What I did discover with some trial-and-error, though, is this: nnoremap ... :execute "normal! <C-u>"<...


2

Use :execute to run a command made out of strings: let g:board_ip = "192.168.100.18" nnoremap <F6> :execute "AsyncRun echo " . g:board_ip . " > /dev/pts/1 2>&1"<CR>


2

The automatic bookmarks '< and '> get updated only after the Visual mode is left. Hence <Cmd> is not useful for your example, as you effectively apply the previous selection range, not the current one. You really should use "normal colon"-mapping here: xnoremap <Leader>c :w !xsel<CR> Note (1) use xnoremap instead of ...


0

As @pdr written, macOS has the ability to change the behavior of some modifier keys. You can go to System Preferences -> Keyboard and check on the lower right corner of the window. There is the button Modifier keys.... If you click the Modifier keys... button, then a drop-down panel appears when you can change the behavior of the keys: Capslock Control ...


0

Thanks to the link in the comment by @statox♦ I was able to figure this out. This answer included a link to this question where the accepted answer explains that intercepting a <C-f> is equivalent to intercepting a <C-F> (technically <C-S-f>) in gvim, because: Vim reads characters from the terminal, which sends ^F (ASCII code 0x06) for ...


1

There at least two possible answers here: vnoremap jq :!jq<cr> as suggested by @Ralf works for jq >= 1.6. See https://github.com/stedolan/jq/commit/5fe053671a768d28bc9773719cc4a9a35e72f30d For earlier jq versions where the dot is not implied, it needs to be in the command: vnoremap jq :!jq .<cr> I was using an older version of jq. The answer ...


2

If you use the GUI, you don't need anything special, but you need at least the patch 8.2.0851. Remove all of your code, except the mappings: inoremap <M-h> <left> inoremap <M-j> <down> inoremap <M-k> <up> inoremap <M-l> <right> If you use Vim in a terminal which supports the modifyOtherKeys feature (typically ...


2

You can control that with the 'selection' option. To disable the "past line" cursor behavior, use the following command: set selection=old Beware that using a non-default setting for this option is possibly likely to break behavior of some plug-ins, so it might not be a great idea to change it. There's also a motion that might be close to what you ...


1

let line_count = line("'>") - line("'<") + 1 This doesn't work as you expect, because you're calling your function from within Visual mode ("expr"-mapping). And so the marks '< and '> are not updated yet. You must do this instead: let line_count = abs(line(".") - line("v")) + 1 BTW. This is ...


2

I tried creating an expr map, but the visual start and end marks don't seem to be correct: That's because Vim doesn't set/update the visual marks until you quit visual mode. Try this: function! Xsurround() abort let is_linewise = mode() ==# 'V' let [curpos, pos_v] = [getcurpos()[1:2], getpos('v')[1:2]] let control_end = curpos[0] > pos_v[0] ||...


1

:h quote_ : 9. Black hole register "_ *quote_* When writing to this register, nothing happens. This can be used to delete text without affecting the normal registers. When reading from this register, nothing is returned. You could map it like that: vnoremap d "_d


0

This should work to clear all Insert-mode mappings starting with space: let l:map = mapcheck(' ', 'i') while !empty(l:map) execute 'iunmap' l:map let l:map = mapcheck(' ', 'i') endwhile Unfortunately, there is no way to restrict mapcheck to buffer-local mappings only; however, the ugly loop does let us sidestep parsing command output, which may be ...


3

You can try to analyze the result of split(execute('imap <buffer> <space>'), "\n") From there, keep only the second field (IIRC). => ->map({k,v -> split(v)[1]}), and generate the clearing commands, => prefer ->map({k,v -> 'iunmap <buffer> '.split(v)[1]}) And finally ->execute(). TL;DR :call execute('imap <...


2

If your insert mode mappings are filetype specific then .vim/after/plugin/map.vim and autocmd VimEnter * imapclear would not work as they are executed before fitetype creates them. Also imapclear deletes all insert mode mappings including default ones. You can try to apply imapclear <buffer> on bufread/filetype event though: using after/ftplugin create ...


Top 50 recent answers are included