Questions tagged [lua]

Question about the Lua binding in Neovim

Filter by
Sorted by
Tagged with
5 votes
2 answers
5k views

How can I change the default terminal in Neovim (lua)?

I have tried adding this line to the init.lua but it doesn't work and I don't understand the syntax: local g:terminal_emulator="powershell" I get an error upon running the source command: ...
0 votes
1 answer
23 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....
0 votes
1 answer
1k views

I am currently configuring my Neovim setup, but I am only get it to work as a root user

Basically, I am creating a .config/nvim for Neovim on my M1 Macbook Pro (Monterey 12.6), and I using the iTerm2 terminal emulator. I am having to create the entire configuration as a root user because ...
0 votes
1 answer
299 views

Use LspConfig root_dir in Neogit cwd

I'm trying to setup Neogit to open in my workspace directory instead of cwd. The problem is that I use multi root workspaces, so I usually set my cwd to be workspace1/... My initial try was to use ...
0 votes
1 answer
2k views

How to include/configure lua_ls on lspconfig?

I am trying to include lua_ls on my lspconfig but I am getting this error [lspconfig] Cannot access configuration for lua_ls. Ensure this server is listed in `server_configurations.md` or added as a ...
0 votes
1 answer
32 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()....
0 votes
0 answers
21 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 ...
0 votes
1 answer
72 views

How to highlight missing comma in lua files?

I often forget the comma between embedded table entries in lua code. t = { a = { "str" }, b = { { "str3", v = 1, } <<-- missing comma ...
1 vote
3 answers
507 views

How can I create command abbreviations (`ca`) with the lua api?

In my init.vim, I have the following: ca WQ wq What would be the equivalent in my init.lua?
1 vote
1 answer
25 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 ...
1 vote
0 answers
12 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 ...
0 votes
1 answer
169 views

How to enter terminal buffer using command?

As title. Assume my cursor is already at the terminal buffer, but it's still in normal mode. I'm trying to use TermEnter to enter terminal mode when ever I switch to a terminal buffer.
0 votes
1 answer
21 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 ...
0 votes
2 answers
3k views

Configuring VimTeX in NvChad config

I've been trying to configure vim-tex working on the NvChad configs. I got the :VimtexCompile working and giving me output pdf. But the usual <leader>ll is giving me these errors. Also in vim {{ ...
0 votes
0 answers
15 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. ...
1 vote
1 answer
18 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([[...
0 votes
1 answer
3k views

Sumneko lua-language-server failed to load

My OS is openbsd 7.2 with neovim v0.7.2. I am using the repo at https://github.com/amy-juan-li/nvim-lua.git to configure Neovim. There is a problem with the neosolarized.rc.lua file. Can anyone see ...
2 votes
1 answer
25 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'}, ...
0 votes
1 answer
943 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 ...
0 votes
1 answer
1k views

How to make a http (https) request with a lua plugin?

does anyone know if it is possible to install a Lua HTTPS library that I can access from a Lua plugin in Neovim to make HTTPS requests (POST)? And how would I install such a library? For example, to ...
0 votes
1 answer
307 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 ...
0 votes
1 answer
52 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 ...
2 votes
1 answer
67 views

Where is the text data stored during typing text in insert mode?

I would like to develop a small app in React and Nodejs that sends real-time typed text from my Nodejs/Express server to my React frontend. To do this, I would like to use socket.io. The text data is ...
4 votes
1 answer
1k views

How to disable semantic highlighting for certain filetypes only?

Using Neovim's native LSP interface, I noticed that semantic highlighting provided by LSP makes things worse for certain languages, so I want to disable it based on filetype. I know about possibility ...
0 votes
1 answer
87 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 ...
2 votes
1 answer
58 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", "...
0 votes
1 answer
35 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", ...
1 vote
1 answer
45 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. ** ...
0 votes
0 answers
30 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 ...
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 ...
1 vote
1 answer
62 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.
0 votes
0 answers
21 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.
0 votes
1 answer
97 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' }, { ...
2 votes
2 answers
270 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 ...
0 votes
2 answers
2k views

See live word count in Lualine

I am currently using lualine as my statusline. I would like to see the live world count of the file similar to the feature in airline preferable I would like to get this working natively or else any ...
1 vote
1 answer
78 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:...
0 votes
1 answer
1k views

Moving the visual selection up by 1 line using Lua (NeoVim)

So I am trying to create a Lua function to move the visual selection elsewhere. For question simplicity, lets assume 1 line above the current visual selection position. This question is not about ...
-1 votes
1 answer
648 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 ...
2 votes
1 answer
64 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 ...
1 vote
1 answer
934 views

How to install nvim-html-css neovim plugin in NvChad

Neovim plugin: nvim-html-css I don't know lua but I need this plugin installed for bootstrap classes. I have Neovim NvChad lazy.nvim setup. Copy pasting didn't worked so I tried to cut out maybe ...
1 vote
0 answers
354 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 = { ...
0 votes
0 answers
51 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 ...
0 votes
1 answer
249 views

Neovim: Telescope fails to find `tbl_isarray`

I run Neovim v0.9.1 using Lua 5.1 (not LuaJIT) and telescope. As soon as I invoke telescope.builtin.git_files, Neovim shows the following error: E5108: Error executing lua: ...ugins/telescope.nvim/lua/...
0 votes
1 answer
110 views

Neovim source code: what is if_true in options.lua?

The defaults that Neovim has are specified in src/nvim/options.lua. I'm trying to understand this source, Let's take for example, something like backup { full_name='backup', abbreviation='bk'...
0 votes
1 answer
284 views

How to run a callback when an nvim plugin is loaded. Can I tie this back to running a callback when a plugin is required/imported?

I can see in vim how we can: Call function only when the plugin is loaded But I want to: Call function only when the plugin is required
0 votes
1 answer
47 views

Lua insert mode mappings are pasting the rhs in buffer instead of executing them

In my init.lua, I've got some keys bound to some actions in insert mode. e.g.: vim.keymap.set('i', '<C-j>', '<Plug>(easymotion-bd-w)') But when I press Ctrl-ew, instead of highlighting ...
0 votes
0 answers
44 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 ...
1 vote
2 answers
1k views

How to add <bits/stdc++.h> header file in Clangd installed through Mason (Neovim lua)?

I want to add/expand the Clangd Language server, which I installed through Mason within Neovim, with the standard libraries that come with MinGW (I run windows 11). I'm trying to do CP, and for that I ...
1 vote
0 answers
54 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 ...
1 vote
1 answer
132 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 ...