Questions tagged [lua]

Question about the Lua binding in Neovim

Filter by
Sorted by
Tagged with
12 votes
3 answers
8k views

How to remove Neovim trailing white space?

In Vim I used autocmd BufWritePre * :%s/\s\+$//e to delete trailing white space on save. Now, Neovim 0.7 has the new vim.api.nvim_create_autocmd. What is the correct syntax to adapt this autocmd in ...
Joannes's user avatar
  • 237
7 votes
2 answers
13k views

How can I change the root of my nvim-tree?

I have checked this screenshot (list of nvim-tree commands): But there seems to be no command to change the root of my tree. Also I am hoping to setup a convenient startup location but could not find ...
samuelnihoul's user avatar
7 votes
3 answers
10k views

How can I get the current cursor position in Lua?

How can I get the current cursor position in Lua? I want to get a number so that I can use it in a for-loop. I tried this, but I got a hashed value instead: local lineNum = vim.api.nvim_win_get_cursor(...
John Winston's user avatar
5 votes
2 answers
6k views

Are vim.cmd() and vim.api.nvim_command() the same, if not, what are the differences?

I'm a little confused. Is vim.cmd just a shorthand for vim.api.nvim_command or are they used for different things?
Martin Braun's user avatar
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: ...
samuelnihoul's user avatar
5 votes
1 answer
656 views

How to use -complete=lua for command-completion?

If you check the help for :command-completion, there is a line that reads: -complete=lua Lua expression But it does not give further instructions about how to use it, or how to provide a Lua ...
Danielo515's user avatar
4 votes
1 answer
3k views

How to check if an external command exists in Lua

How do I translate this VimL code into Lua? if executable('rg') set grepprg=rg\ --vimgrep endif
Jay's user avatar
  • 211
4 votes
1 answer
1k views

Is the goal of Lua in neovim to replace Ex, and if not what is it?

I am a new user to neovim, and a moderator on this site said You seem to imply that you expect there should be a native way to run [filetype] (and to some extent every Ex command) directly in Lua. ...
Evan Carroll's user avatar
  • 1,314
4 votes
1 answer
217 views

Trouble in overriding `indentexpr` in neovim

Say I do not quite like the shipped Lua indentexpr (GetLuaIndent(), defined in $VIMRUNTIME/indent/lua.vim). With vim, I can disable or change it using this minimal configuration: ~ % cat .vimrc ...
Futarimiti's user avatar
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 ...
Thunderbeef's user avatar
3 votes
1 answer
296 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
3 votes
1 answer
4k views

Is it possible to set a vim.api.nvim_create_autocmd for a FileType (not just a pattern)?

Currently I'm using pattern in vim.api.nvim.create_autocmd(): vim.api.nvim_create_autocmd({ "BufEnter", "BufFilePost" }, { pattern = { "*.tf" }, callback = ...
RubenLaguna's user avatar
3 votes
2 answers
642 views

Alt > or Alt < mappings do not work

I am trying to configure the key mappings for the barbar plugin commands, specifically the BufferMovePrevious and BufferMoveNext actions. The desired key combinations are Alt < and Alt >. ...
Jastcher's user avatar
3 votes
2 answers
87 views

How to detect whether the current file might contains a long line?

As title. I want to disable some plugins when the current file is a production file, i.e. it is compacted into < 10 lines but each line contains >1000 columns. I'm using NeoVim so I prefer ...
Kindred's user avatar
  • 153
2 votes
3 answers
5k views

How to add keymapping for LSP code formatting in visual mode?

In neovim I would like to set a keybinding -- via lua config -- to use LSP to format the visual selection when I type \qf. Using this setting, I can format the whole buffer from normal mode: vim.api....
Vincent's user avatar
  • 121
2 votes
1 answer
4k views

How can I port nmap, map, and imap commands to Lua configuration?

How can I port map commands in my vimrc file to Neovim lua configuration? For example: nmap <silent> <F2> <Plug>(lcn-rename)
Evan Carroll's user avatar
  • 1,314
2 votes
1 answer
258 views

Why does this mapping of g to gj give "'Undefined variable gj"?

E121: Undefined variable : gj E121: Undefined variable : gk local keymap = vim.keymap.set local default_opts = { noremap = true, silent = true } local expr_opts = { noremap = true, expr = true, ...
ZenVentzi's user avatar
  • 123
2 votes
1 answer
6k views

How can I setup a nerd font in init.lua?

I am in Windows 11. I have downloaded and installed all the fonts 'CascadiaCode'. I have tried to add some thing like vim.g.guifont="CascadiaCode" to my init.lua but can't figure it out.
samuelnihoul's user avatar
2 votes
2 answers
757 views

Some migration problems from vimrc to init.lua

How can I simplify the following codes in my init.lua? (For "simplify" I mean that by vim.cmd(...) you're actually letting Lua run vimscript under the hood. But there is probably a Lua API ...
NeoZoom.lua's user avatar
  • 1,460
2 votes
1 answer
3k views

How to add `~/.config/nvim' into runtime path for Lua?

In my init.lua I call: require('plugins') require('theme') This works when editing in the ~/.config/nvim directory, where init.lua, plugins.lua and theme.lua are located. But when I run vim outside ...
Miki Vanoušek's user avatar
2 votes
1 answer
88 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,232
2 votes
1 answer
646 views

Minimap config in lua

Sorry if the question looks dumb, is it possible to set the config file of minimap in lua ? I test the following, but the plugin is not found (the package command works wheel eg. Minimap or ...
Hadock's user avatar
  • 143
2 votes
1 answer
1k views

How to move cursor one line down with API in the way like the default 'j'?

For example, I have this in the buffer: line1 .... A .... line2 B line3 .... C .... Follow these steps: At first it's in Normal mode and the cursor is under A Press j and the cursor will move to B ...
vim.ggyG's user avatar
  • 201
2 votes
1 answer
5k views

Neovim Lua: Error while calling lua chunk [...] '' expected near 'local'

When I run Neovim (NVIM v0.6.1), I get Error detected while processing /home/ecarroll/.config/nvim/init.lua: E5113: Error while calling lua chunk: vim.lua:63: /home/ecarroll/.config/nvim/lua/plugins....
Evan Carroll's user avatar
  • 1,314
2 votes
2 answers
3k views

Unable to use lua inside a `.vim` file

I am using a nightly build of nvim, and I am trying to use neovim/nvim-lspconfig. I have followed to doc and setup the language server, but nvim throws error and reports that it is unable to process ...
John Winston's user avatar
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 ...
Ari Sweedler's user avatar
2 votes
1 answer
5k views

Neovim lua module not found even though it exist

I have structured my neovim config files like this ~/.config/nvim ├── init.lua └── lua └── [username] ├── core │   └── options.lua ├── init.lua └── plugins These ...
me.nkr's user avatar
  • 41
2 votes
2 answers
915 views

Applying commands to buffer from Neovim command line with complex plugin managers

I come from the following problem: I'm using Neovim (0.8.3) with AstroNvim as plugin/everything-manager. I've successfully set up multiple LSP servers from within that, which use the right servers, ...
Marcus Müller's user avatar
2 votes
1 answer
1k views

How to set keywordprg to call a lua function in neovim?

A plugin unidentified is setting the keywordprg option to :Man but I want it to be LSP based. So I attempted set keywordprg=:lua\ vim.lsp.buf.signature_help() but it gives me the following error and ...
muppi090909's user avatar
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'}, ...
Crimson Crusader's user avatar
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", "...
robertspierre's user avatar
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 ...
f4T1H21's user avatar
  • 23
2 votes
1 answer
318 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
  • 199
2 votes
1 answer
187 views

Neovim paste without overwriting register w/ Lua

So I know with vimscript you could make paste not overwrite your register with this: vnoremap p pgvy And I've tried a few ways to get this to with with Lua such as: vim.api.nvim_set_keymap('n', 'p', '...
Zach B.'s user avatar
  • 123
2 votes
1 answer
2k views

How to call a command with remapping in neovim?

Say I have a normal mode mapping on key P, for sure it can be executed in command mode: :lua normal! P Now I want to do this in lua, so I tried: vim.cmd('normal! P') and NeoVim executed it as "...
NeoZoom.lua's user avatar
  • 1,460
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 ...
Piet Pro's user avatar
2 votes
0 answers
1k views

Neovim - How do you call Python from Lua and store the results as a Lua variable?

I am trying to improve a GitHub repository for Neovim called quangnguyen30192/cmp-nvim-ultisnips It's a Lua repository that calls another Vim plugin repository, SirVer/ultisnips , a primarily Python-...
ColinKennedy's user avatar
2 votes
0 answers
667 views

Cannot get current node tree with treesitter in Lua in nvim

I am trying to get the AST tree to find the node I want. Based on the doc, I should be able to get the tree like this: local parser = vim.treesitter.get_parser(0, vim.o.filetype) print('check ...
John Winston's user avatar
1 vote
2 answers
8k views

How do I port a filetype command to neovim's lua format?

Currently my .vimrc file has this in it, filetype plugin indent on -- filetype detection[ON] plugin[ON] indent[ON] How can I port filetype plugin indent on to neovim's lua format?
Evan Carroll's user avatar
  • 1,314
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?
David Goldstein's user avatar
1 vote
1 answer
499 views

Get byte length of current line in Lua

How do I get the length, in bytes, of the current line in Lua? vim.api.strlen('foo') doesn't work
Jay's user avatar
  • 211
1 vote
1 answer
338 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
1 vote
2 answers
153 views

Detect Editing of Directory

How do you detect if a directory is opened(with :edit) in Vimscript? I am lazy loading a file explorer and need it to load it before I open a directory. One approach I tried using an autocommand that ...
unrealapex's user avatar
1 vote
1 answer
2k views

How to insert text from lua function at cursor position (insert mode)

I realize there is a similar question here but using vimscript. I have created a function that returns a uuid in lua. But I would like to assign this to a keymap and insert the text at the cursor ...
Boyd's user avatar
  • 209
1 vote
2 answers
4k views

How to create a lua function that gets called for a vim (neovim) motion

Vim has the concept of actions, which can act on text objects via motions. For example diw will delete (the action) the inner word (the motion). I want to create a function that can be applied/...
Danielo515's user avatar
1 vote
1 answer
2k views

leader not working in visual mode in lua?

I am migrating from vimscript to lua for my keybindings and I have remapped the leader key as space: vim.g.mapleader = " " It works fine with all my key bindings. Except in visual mode. ...
Vinn's user avatar
  • 781
1 vote
2 answers
3k views

Unable to turn off syntax highlighting with lua script in neovim

running newvim 0.6.1. Totally clean install, no plugins. In init.lua: vim.opt.syntax = "off" Also tried "false" and "disabled." Didn't work. Also tried vim.g, vim.o, vim....
StevieD's user avatar
  • 1,492
1 vote
2 answers
2k views

How do I open an existing file in a floating window?

For a plugin, I want to open an existing file situated in lua/myPlugin/ in a floating window, so whatever the actual working directory is, this file is always the one to be opened. It sounded easy, ...
Ludo's user avatar
  • 31
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 ...
Sasgorilla's user avatar
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([[...
theherk's user avatar
  • 133