As of May 31, 2023, we have updated our Code of Conduct.
5 votes
Accepted

How can I convert vim8 function mapping to vim9?

I would go with :h vim9-differences before converting legacy to vim9 script. In your def function: remove last : string in def as function returns nothing let should be replaced with var a:command ...
Maxim Kim's user avatar
  • 12.2k
5 votes
Accepted

How Can I Rename a Command but Still Use the Original Command

If you want to keep your habit typing tabclose you could use: cnoreabbrev tabclose TabClose Or as mentioned by @Rich to avoid that the abbreviation triggers in search or as part of other commands: ...
Vivian De Smedt's user avatar
3 votes
Accepted

Passing arguments to function in remapping

Those are mappings, not "remappings". You can use :help getcharstr() to, well… get one character from the user: xnoremap <expr> <key> Wrap("w", getcharstr()) nnoremap &...
romainl's user avatar
  • 36.9k
3 votes
Accepted

How to predefine functions in syntax file?

Vimscripts are sourced one line at a time, from top to bottom, so "things" have to be defined before they are consumed: let a = 1 echomsg a echomsg b let b = 2 1 E121: Undefined variable: b ...
romainl's user avatar
  • 36.9k
3 votes

How can I make a command that checks iteratively through parent roots until it finds something or reaches C:/?

You can use the findfile() function, together with the file-searching features in order to try to find the path to a file up the directory tree. For example: :echo findfile('top-level.txt', '.;') ...
filbranden's user avatar
  • 27.5k
3 votes
Accepted

Recursion in lambda expressions

It is possible, but you must refer to Fac as a "global" with g: to allow the lambda to refer to "itself," even if it is not actually defined already. let Fac = { n -> n == 0 ? 1 ...
Mass's user avatar
  • 13.6k
2 votes
Accepted

Select entire function call or extend selection

For func(gunk(a, b)) with the cursor on the f of func, I would press y% or d%. The % command jumps between matching pairs (roughly; depending on configuration, optional plugins that ship with Vim, ...
D. Ben Knoble's user avatar
  • 23.9k
2 votes
Accepted

How to write the command statement to call customized function briefly?

You seem to be reading the documentation one paragraph at a time, without the required foundational knowledge. "Defining command-line commands" is introduced in chapter 40 of the user manual:...
romainl's user avatar
  • 36.9k
2 votes
Accepted

User function unexpectedly returns the same output every call

let copy = g:jsonTemplate Obviously, this looks very wrong, as "jsonTemplate" has a type of List. And simple assignment of a list doesn't make a new copy in VimScript (and also in many or ...
Matt's user avatar
  • 19.5k
2 votes

Vimscript: how to overwrite a variable that is inside an if block?

The system() return includes a trailing newline: :let ls = system('ls | wc -l') :echo '|' .. ls .. '|' |61 | Press ENTER or type command to continue You can use ->trim() to remove newlines. Also, ...
Martin Tournoij's user avatar
2 votes
Accepted

How do I change behavior on write based on file path?

In this case, the easiest would be to add a check for the path in your function; for example: function! Formatonsave() if expand('%:p') =~ expand('~/src/linux') return endif … ...
Martin Tournoij's user avatar
2 votes
Accepted

Can you select and execute VimL / VimScript inside another file?

Very simple command that works: '<,'>source Explanation: '<,'>: that is the range. See this or :help '< source: that is the ex-command to run VimL / Vimscript Simple way: Select text ...
Pixelbog's user avatar
  • 184
1 vote
Accepted

Insert result of expression after cursor

I would do: function! InsertDate() execute "normal! \"=strftime('%FT%T%z')\<CR>p" endfunction Your tentative were good but the normal argument do not interpret the <CR> ...
Vivian De Smedt's user avatar
1 vote

Can I use Telescope to find all commands and functions?

If you are searching for lsp symbols you can do: :Telescope lsp_document_symbols For this to work you need to have Neovim LSP framework to be connected to the corresponding LSP server. In order to do ...
Vivian De Smedt's user avatar
1 vote
Accepted

Get current vimscript script name and line number?

Found it! You can use expand('<sfile>') and expand('<sflnum>') see h sfile for all the expanded stuff you can use. But instead use: function! log(msg) abort echom expand('<stack>'...
KamilCuk's user avatar
  • 233
1 vote
Accepted

Pass local variables in a vimscript function to python

I believe the problem is related to trailing ; in the definition of l:num_col I would do: function! MakeOrgTable(...) let l:num_col = a:0 > 0 ? (a:0) : 0 python << EOF import vim vim.current....
Vivian De Smedt's user avatar
1 vote
Accepted

User-defined commands that call the same functions but with different arguments

You are prefixing your function call with silent which effectively suppresses output of your echo in the function. Remove it and see different output. vim9script def g:MyFunction(a: string, b: bool) ...
Maxim Kim's user avatar
  • 12.2k
1 vote
Accepted

Use regex pattern as argument to function

I would suggest to use a string for that: autocmd BufReadPost * call TextEnableCodeSnip('bash', '^hello', '^world", 'SpecialComment') function! TextEnableCodeSnip(filetype,start,end,textSnipHl) ...
Vivian De Smedt's user avatar
1 vote
Accepted

How can I see a list of snippets in my Vim?

Coc Snippet Provider If you are using coc you can install the coc-snippets plugin that provides a snippet provider and auto-completion of snippets. You can install the snippet provider using the ...
Vivian De Smedt's user avatar
1 vote

How to remap F16 to F19 on macOS?

What I have done is that I have deactivated the special F keys for macOS, to have the standard keys, so F1 opens the help in Neovim and I don't have to press the fn which is far better. Then I ...
COil's user avatar
  • 121
1 vote

How to suppress "No matching autocommands"?

Thx to Matt's comment. Found the answer in :h exists. the relevant part is. #event autocommand defined for this event #event#pattern autocommand defined for this event and ...
qeatzy's user avatar
  • 940
1 vote

How could I make this mapping to a function repeatable?

Obviously, your mapping executes two commands, not one. Therefore, the second call (i.e. repeat-set) needs to have v:prevcount passed as argument. As of "without plugins", a plugin in Vim is ...
Matt's user avatar
  • 19.5k
1 vote

Recursion in lambda expressions

I'm not sure if it's worth to do but, at least, it's worth to mention that we can also parse the call stack to get lambda's name. And so we have " Calling the caller function! Self(...) abort ...
Matt's user avatar
  • 19.5k
1 vote

Select entire function call or extend selection

You can do: vf(%` f( moves the the first parenthesis % moves to the matching parenthesis Another way if your are at b and to follow your idea is: va(ob va( select (gunc(a, b)) o switch the cursor in ...
Vivian De Smedt's user avatar
1 vote
Accepted

Nvim function to compile file in terminal

We can pass the shell commands to the terminal buffer with :h chansend(). Here is an example: function! RunCppFile(filename, filedir) let cmd_compile = 'g++ ' . a:filename . ' -o ' . a:filedir . '\a....
3N4N's user avatar
  • 5,269
1 vote

Different replace patterns depending on visual/visual line mode

You can use the mode() function. It returns: v in visual mode and V in visual line mode. More information with: :help mode() mode([expr]) Return a string that indicates the current mode. ...
Vivian De Smedt's user avatar
1 vote

Automatically highlight visual selection matches

I have made it work. Firstly, I found from Vim does not call functions correctly when wrapped in another function that "Vim doesn't like updating Screen too often" so redraw was necessary ...
lobelk's user avatar
  • 21
1 vote

in-place replacement of code in HTML documents with TOhtml?

OK, I need to think about something else than freaking Magento. Pandoc would help with the first step but the rest can be done with pure Vim commands… Tell :help :TOhtml to only generate fragments: :...
romainl's user avatar
  • 36.9k

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