4

I can do :echo globpath('~/path/to/dir', 'string*') to get a list like: This is not a List. This is a long String with newlines. To get a List you must supply the 4th argument as in :h globpath(): echo globpath('path', ''expr', 1, 1)


4

It's the formal parameter name, chosen by the person who has written this code, to the lambda expected by map(). Almost anything would have been valid. map() calls the lambda with 2 parameters for each element in the list: the index of the element (ignored here -> _), and the element (arbitrary named v). I guess the choice of using v stems from the ...


4

See my answer to your other question about v: What is `v` in this vimscript? _ is the chosen name for the key/index parameter of the lambda. As it isn't used, _ is used to say ignored/unused.


4

In vim script (vim 8.x and older), a variable can belong to one of a number of scopes. While it's true it's idiosyncratic as no other language has this feature, it's also consistent as no other language has e.g., "buffer variables." buffer-variable b: Local to the current buffer. window-variable w: Local to the current window. ...


3

What a coincidence. I encountered this exact same thing a few hours before you posted this. I just figured it was a line-ending issue and solved it by wrapping the system() call in a call to trim(). Since you mentioned it I since verified that the cause is the presence of a newline in the output of system(). So you can solve this with a trim() call that ...


3

There isn't always a corresponding Ex command for each Normal-mode command. It's the case with all commands behind <C-w>, in fact there's :wincmd which gives you direct access to all of them, besides shortcuts such as :resize 1 (same as 1<C-w>_) or :split (same as <C-w>s) but, again, not all Normal-mode commands are exposed as Ex commands. ...


3

The .. string concatenation operator was added to Vim fairly recently, as of version 8.1.1114 from April 2019. The documentation at :help expr-.. explains the rationale for adding it: For String concatenation .. is preferred, since . is ambiguous, it is also used for Dict member access and floating point numbers. This commit has been ported to NeoVim in ...


3

And I'm wondering what's v in this context? v:false, v:true, {_, v ->, and fnamemodify(v,? There are two separate instances of v here and they mean two different things. Vim variables under the v: namespace Vim has a list of special variables under the v: namespace. Note that v: is fixed here. Variables here include v:argv (the arguments passed to the ...


3

I'm going to guess that the documentation is outdated with respect to that limit. I'm looking at the code for alloc_new_sign()... // Check that next_sign_typenr is not already being used. // This only happens after wrapping around. Hopefully // another one got deleted and we can use its number. ... if (lp->sn_typenr == next_sign_typenr) ...


3

Starting with Vim 8.2.2189 you can easily surround a single word using the small delete register like this: ciw"CtrlR-" The whole operation is repeatable using the . command. So if you have a line like this: foo bar foobar With the cursor anywhere on the first word, simply type ciw'<C-R>-'. This will put single quotes around to first word. ...


3

I don't like using windo that could trigger events if done without any caution, and thus I prefer using programmatic ways instead. For instance, we can obtain the window numbers of the windows in diff mode with :echo filter(range(1, winnr('$')), 'getwinvar(v:val, "&diff") == 1')


2

Even though the answer from @Matt is the obvious solution for vim, I needed something that will work in neovim as well, so I ended up writing a function that works in both editors. function! GetVisibleLines() let l:visible_w = gettabinfo(tabpagenr())[0]['windows'] let l:current_w = win_getid() let l:visible_l = [] for w in l:visible_w noautocmd ...


2

I modified this answer by Martin Tournoij to my needs. fun! s:write() abort if get(b:, 'write_start', 0) is 0 let b:write_start = wordcount() else let l:words = wordcount()['words'] - b:write_start['words'] let b:write_start = wordcount() execute !BashScript l:words endif endfun command! Write call s:write() ...


2

I haven't had time to test more than the first code-block, but the others are mostly mechanical transformations. function MyLinks(pat, strip) abort return glob(a:pat, v:false, v:true) \ ->map({_, v -> printf('[%s](%s)', fnamemodify(v, ':t:r')->substitute(printf('^%s', a:strip), '', ''), fnamemodify(v, ':t'))}) \ ->join("\n&...


2

What you're seeing is the newline at the end of the command, as @BLayer's answer states. A better approach for this specific case of finding a binary would be to use the Vimscript function exepath() here instead of shelling out to the which command: let g:coc_node_path = exepath('node') This is more efficient (since it doesn't need to spawn an external ...


2

As the OP noted and can be found in What's the functional difference between the key notations "\<xxx>" and '<xxx>'?, we need :help expr-quote here: " note that I prefer nnoremap nnoremap <expr> <space>t ManageTerminal() function ManageTerminal() if bufname('terminal') ==# 'terminal' if expand('%:t') =...


1

My own mappings for this purpose: " Bubble single lines up and down nnoremap - :.move +1<CR> nnoremap _ :.move -2<CR> " Bubble lines up and down in visual mode vnoremap - :'<,'>move '>+1 \| normal! gv<CR> vnoremap _ :'<,'>move '<-2 \| normal! gv<CR>


1

There are too many plugins to move lines of text to mention them here. An example to exchange (move) selected lines, more or less like in tpope/vim-unimpaired: xnoremap <expr><silent>[e printf(":move '<--%d<CR>gv", v:count1) xnoremap <expr><silent>]e printf(":move '>+%d<CR>gv", v:count1) So [...


1

"Why?" Having to explicitly write a: to access parameter values while formal parameter names are defined without the a: scope in the function definition is a very old choice. Note: in this case, a: stands for argument. IMO if you really want to know why this choice has been made, you'd better ask on vim-dev mailing. I guess it is needed to ...


1

This is probably concealing. The first thing you'll have to do is to identify the syntax group of the character you want to transform. As an example, let's take this typescript code: /** * This function makes the sum of its arguments. * * @param nums The list of numbers to add together * * @return The sum of the given numbers */ function add(...nums: ...


1

? needn't be called with :norm. Just use ?: alone. With your :norm calls there's no need to wrap in :execute since there are no variables being used. And need to start insert with, well, :startinsert. That gives... function! AddBlock2(...) range let l:hdr = strftime("_%d%b%y_%H-%M-%S") let l:b = repeat("-", 20) call append(...


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