Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [lua]

Question about the Lua binding in Neovim

Filter by
Sorted by
Tagged with
1 vote
0 answers
10 views

Listening for changes in the `inccommand=split` preview buffers

I'm attempting to write a small lua script that can track the changes in the inccommand=split preview window. In essence, I want to have some kind of programmatic notification when the preview list ...
ollien's user avatar
  • 111
1 vote
2 answers
34 views

Check if there are non-empty or named buffers open

When closing Neovim, I'd like to store the session, but only if there are any files open. If I only have the dashboard open, or an empty unsaved buffer, I want to skip this step. So, I need a way to ...
ElRudi's user avatar
  • 113
0 votes
1 answer
13 views

Convert vimwiki_diary_months to lua

How do you set g.vimwiki_diary_months in lua? According to :h g.vimwiki_diary_months: *g:vimwiki_diary_months* It is a |Dictionary| with the numbers of months and corresponding names. Diary uses it. ...
Ludenticus's user avatar
0 votes
1 answer
32 views

How can I use vim.api from an external Lua script?

I want a different program to communicate with neovim. Based on documentation, this should be done via vim.api. I found examples on how to do this via Java or Python. I want to use a Lua script. If I ...
grbll's user avatar
  • 1
0 votes
0 answers
18 views

pylsp + vim.lsp.buf.format not working

require'lspconfig'.pylsp.setup { settings = { pylsp = { plugins = { autopep8 = {enabled = false}, black = {enabled = true}, ...
mankind86's user avatar
1 vote
1 answer
34 views

How to lua-ify a parameterized vimscript function call?

Let's say there is a vimscript function that takes a dictionary as a parameter. In vimscript, it is called like this: call Vote({'name':'Phil Collins', 'band':'Genesis'}) I'm interested in what that ...
Phil R's user avatar
  • 503
0 votes
1 answer
26 views

How do I close the quickfix window inside a user-defined function?

If the quickfix window is open, I can close it with :cclose. I can map that to a shortcut key: vim.keymap.set('n', '<C-q>', ":cclose<CR>") vim.keymap.set('n', '<C-q>', vim....
Sasgorilla's user avatar
0 votes
0 answers
24 views

Set the current line limit for jumping in Vim

I want to set a limit for the use of e. Basically e is for jumping forward to the end of words, but I do not want to go to the next line. I just want to jump to the end of all the words in the current ...
mohamadi_arch's user avatar
0 votes
1 answer
36 views

How to get the value of visual-mode wordcount() in lua script

Objective I am working on writing a keymap through lua script in Neovim: First, selecting some words in visual mode and, in the corresponding lua script, trying to get the value of vim.fn.wordcount()....
HRC's user avatar
  • 23
1 vote
1 answer
34 views

How can I accept a range in a Lua user command?

I want to optionally accept a range in a user-defined function: vim.api.nvim_create_user_command('Pizzafy', function(args) if args.range > 0 then -- visual mode, I think ...
Sasgorilla's user avatar
1 vote
0 answers
17 views

How can I jump to a sibling node in Neovim?

Say I want to write a custom function / keyboard shortcut to jump to the next sibling node in Neovim/Lua. In theory, I can get that with TSNode:next_sibling(). But I'm lost as to how I would put the ...
Sasgorilla's user avatar
0 votes
1 answer
26 views

How to identify names of lua configuration variables to inspect them?

I load a plugin, and the plug docs tell me that I can configure it using lua code like this, which I might put in my startup file: lua require('plugin_name').setup{ \ foo ...
Mars's user avatar
  • 123
0 votes
0 answers
16 views

Creating a faster way to <next error> -> <suggest fix> -> <accept fix>

I'm using lazyvim with clangd extra installed, and when I have an error / diagnostic that needs handling I do the following routine: ]d / ]e (go to next diagnostic / error) <LEADER>ca (i.e. ...
CIsForCookies's user avatar
1 vote
1 answer
20 views

Range marks aren't set in lua function called from keymap

I'm trying to insert a table of contents with an external process. Currently, I have this: .config/nvim/after/ftplugin/markdown.lua --- @param v boolean local function toc(v) if v then vim.cmd([[...
theherk's user avatar
  • 133
2 votes
1 answer
27 views

Neovim: Making a function that checks the beginning of line and acts depending on it

Extra details, The whole code: local obsidianSettingsGroup = vim.api.nvim_create_augroup('Obsidian Group', { clear = true }) vim.api.nvim_create_autocmd('FileType', { pattern = {'markdown'}, ...
Crimson Crusader's user avatar
0 votes
1 answer
125 views

From a Neovim extension, how to detect project root?

I am learning to write Neovim extensions. Let's name it my-extension. From my extension, I want to detect the presence of a .my-extension.json at the root of the project. This is because I want to ...
Mihamina Rakotomandimby's user avatar
0 votes
1 answer
37 views

keybindings that change mode: cannot use keybindings on the new mode

I have defined the following keybindings: local opts = { noremap = true } local ll = "<leader>i" opts["desc"] = "Send visual lines" vim.keymap.set("v", ...
robertspierre's user avatar
2 votes
1 answer
68 views

What is set_opfunc?

I'm configuring toggleterm.nvim, and in particular I'm putting this keybinding in my config file, as suggested by the plugin author here: -- Send motion to terminal vim.keymap.set("n", "...
robertspierre's user avatar
0 votes
0 answers
40 views

":term" style completion in vim.ui.input()

I currently have the following keymap: vim.keymap.set('n', '<leader>sr', function() return ":vs | term " end, { expr = true }) This drops me into a vim command where I can complete ...
Kurtis Nusbaum's user avatar
0 votes
0 answers
28 views

How to get/print all max-nested non-empty subdirs starting from some path(dir)?

How to get/print all max-nested non-empty subdirs starting from path(dir)? I found a random option to do this on Linux (bash): find ~/.config/nvim -type f | sed 's%/[^/]*$%%' | sort -u But I'm ...
cuc's user avatar
  • 1
1 vote
1 answer
70 views

How can I force a reload on a previously require'd module?

I have updated the module I'm writing, but: :lua= require('XXX') keeps returning a cached value.
Ari Sweedler's user avatar
0 votes
0 answers
25 views

Can you trigger a specific lsp code action programmicaly?

Doing the equivalent of :lua vim.lsp.buf.code_action() And pressing a key. I tried some variants like :lua vim.lsp.buf.code_action() :sleep 5 :call feedkeys('4','t') doesn't seem to work.
eyal karni's user avatar
  • 1,136
0 votes
1 answer
56 views

How to display a colored file icon in the statusline?

So I was setting up my status line and I wanted a function which gives the icon of current file type. But it has to be in string. provider=function() str="{some icon}" return str end so ...
Prajwal 's user avatar
2 votes
2 answers
496 views

Run pyright in single file mode and some questions

I have pyright set up as an lsp in neovim and my configuration is like this: lspconfig.pyright.setup({ on_attach = on_attach, capabilities = capabilities, root_dir = function(fname) local ...
f4T1H21's user avatar
  • 23
0 votes
1 answer
1k views

How do you toggle inlay hints?

Previously, vim.lsp.inlay_hint.enable() used to toggle inlay hints. However, this functionality has been removed and now vim.lsp.inlay_hint.enable() just enables inlay hints. How can I toggle inlay ...
Evan Carroll's user avatar
  • 1,384
1 vote
1 answer
60 views

Using a single carret character as the fold character in Neovim using Lua

I am using Neovim v0.9.5 and configured this editor using Lua. I'm searching for a way of using a single caret down (▾) character for folds. Here is what is currently used by Neovim by default. ** ...
Amin NAIRI's user avatar
2 votes
1 answer
87 views

How to set the value of 'foldexpr' to be a lua function?

I have read the documentation on foldexpr, and I have read through Possible to set `foldexpr` using a function reference?. I have tried this: vim.o.foldexpr = function() return "1" end ...
Ari Sweedler's user avatar
1 vote
0 answers
470 views

How to lazy-load `oil.nvim` on `FileExplorer` event?

I have next oil.nvim setup (in lazy.nvim of course): return { { 'stevearc/oil.nvim', cmd = { "Oil" }, event = { "FileExplorer" }, opts = { ...
Vladyslav Rehan's user avatar
0 votes
1 answer
117 views

How to set `cmp-zsh` completion source for `:!` commands (`nvim-cmp` stuff)?

I have next setup for nvim-cmp cmdline : completion: cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ -- { name = 'path' }, { ...
Vladyslav Rehan's user avatar
0 votes
0 answers
54 views

input with completion in times of lua (nvim-cmp ?)

let user_dir = input('Enter a directory: ', '', 'dir') This is simple not working for me. When I press <tab> instead of completion, I get ^I . I use nvim-cmp. Could it be the reason? Can I use ...
eyal karni's user avatar
  • 1,136
0 votes
0 answers
51 views

How can I get text inside double brackets under cursor in Lua?

I'm trying to write a simple little function to follow markdown wiki links of the form [[wiki link]]. I have a bunch of markdown notes with links of this type and they all link to files with the .md ...
ln4lar's user avatar
  • 101
2 votes
1 answer
98 views

Can't use "lua require" before call plug#end()

I'm using this minimal setup for easy repro: call plug#begin() Plug 'nvim-tree/nvim-tree.lua' lua require('nvim-tree-init') call plug#end() Running neovim results in this error upon opening of neovim:...
Fedja's user avatar
  • 55
1 vote
0 answers
62 views

How can I handle whitespace of the path with nvim_buf_get_name?

I am using Neovim and I use this code to get the full path of the current file. local currnetPath=vim.api.nvim_buf_get_name(0) I want to use this variable for opening the current HTML file, so I need ...
mohamadi_arch's user avatar
1 vote
1 answer
164 views

How can we set abbreviations in Lua for Neovim?

I am using Neovim and I asked this question from Google Bard and it was answered with this code: vim.g.abbreviations = { ["btw"] = "by the way", ["imo"] = "in my ...
mohamadi_arch's user avatar
0 votes
1 answer
87 views

Is vim.fn.winrestview supposed to restore the view saved with vim.fn.winsaveview?

Inspired by this answer (quoted below), I wanted to make a similar mapping using Lua. nnoremap <expr> * v:count ? '*' : '<Cmd>silent keepjumps normal! *<CR><Cmd>call ...
nullromo's user avatar
  • 255
0 votes
0 answers
47 views

How to detach/disable a buffer-update callback in nvim

In vim, we can implement a vim script, which monitors text changes in details, with listener_add(), listener_remove(), listener_flush(). In nvim, nvim_buf_attach() is available to attach a callback. ...
Rick Howe's user avatar
  • 363
2 votes
1 answer
90 views

Avoiding name conflicts in ~/.config/nvim/lua/

I've installed telescope.nvim plugin for NeoVim. Now, I would like to put some configuration code related to this plugin in this file: ~/.config/nvim/lua/telescope.lua In my init.lua file, I've ...
Flimm's user avatar
  • 2,262
0 votes
2 answers
200 views

How to exclude a specific buffer from the BufEnter autocmd group?

I want to load a plugin when I enter a buffer, so I set this event to BufEnter. But when I start neovim, the plugin loads at the dashboard buffer. I want to exclude that buffer. How can I do it? ...
Nias26's user avatar
  • 11
0 votes
1 answer
2k views

Configuring vimwiki in neovim

I am struggling with the basic configuration for vimwiki in neovim. I cannot get it to use my configuration. For import I am using lazy.nvim. This is the concerning lazy-section: {"vimwiki/...
hmaier's user avatar
  • 123
0 votes
0 answers
370 views

goto definition

I'd like to have a shortcut ('gD', say) to go to the definition using vim.lsp.buf.definition; however, in a new tab (if this is not open yet), or in the tab already open.
Alois Pichler's user avatar
0 votes
0 answers
305 views

packer error "module 'packer.luarocks' not found:"

I am trying to install packer.nvim to my NvChad configuration. I installed packer using git clone https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\start\...
ori raisfeld's user avatar
1 vote
1 answer
394 views

Why are non-existent vim.fn functions defined in Neovim's Lua API?

From within Neovim, I can execute the command :lua print(vim.fn.non_existent_function), and would get something like function: 0x01052bc2a8 as the printed output. But of course, if I were to actually ...
Jethro Cao's user avatar
2 votes
1 answer
356 views

Neovim: Converting Vimscript Terminal Functions to Lua

Author: @mizlan Source: https://github.com/mizlan/vim-and-cp/blob/master/cp.vim#L16 This code adds charm to neovim integrated terminal. For cpp programs, I have these: F9 compile, F10 run, F12 ...
Mega Bang's user avatar
  • 309
0 votes
1 answer
219 views

I need help updating config code from vimscript to lua

About three years ago, I had gathered chunks of code from the net and made my init.vim config file. Now, with Lua released, I am unable to convert it. And it's down to you folks whether you can help ...
Mega Bang's user avatar
  • 309
0 votes
1 answer
1k views

Error when configuring lspconfig with mason

I'm trying to set up autocompletion, fixing, etc. for lua files in Neovim. I started by trying to follow the instructions from this video: https://www.youtube.com/watch?v=lpQMeFph1RE&t=188s ...
quant's user avatar
  • 105
0 votes
1 answer
373 views

In Lua, how can I check if a buffer exists on disk?

I use Neotree on Neovim, and have mapped a key to open the file browser which is supposed to: open the file browser pointing to the current file if there is no filename, open the file browser at the ...
artfulrobot's user avatar
0 votes
0 answers
53 views

How to change spelllang alias in vim-airline (option `vim.g.airline_detect_spelllang = 1`)?

I have enabled the vim.g.airline_detect_spell = 1 and vim.g.airline_detect_spelllang = 1 options (config is written in Lua and can be found here). The vim.g.airline_detect_spelllang = 1 makes the vim-...
Vladyslav Rehan's user avatar
0 votes
0 answers
21 views

switch to terminal opened from autocomand

I am trying to create autocommand to run current python file in a terminal, when it is saved. It is working with the following autocommand: vim.api.nvim_create_autocmd("BufWritePost", { ...
user48990's user avatar
3 votes
1 answer
321 views

How do you pass options to a lua plugin?

In many Neovim plugins these days, configuration is done in a new way, and the readme just says to "pass option_name = someval to enable some behaviour". For example, archibate/nvim-gpt, ...
TamaMcGlinn's user avatar
1 vote
1 answer
3k views

Neovim/Lua: How to use vim.keymap.set with vim.v.count

I'm trying to add a count to one of my keymap bindings. vim.keymap.set("n", "<leader>o", vim.v.count .. 'o<Esc>') does not work as expected. My intention for this ...
agshe's user avatar
  • 23