Questions tagged [lua]

Question about the Lua binding in Neovim

Filter by
Sorted by
Tagged with
0 votes
1 answer
270 views

How to know that neovim is started by zsh command "git commit" from my terminal emulator?

As title. I'm building a plugin and this is the last step. I've configured my .zshrc so that git will use neovim as its texteditor program to enter commit messages in interactive mode. The on-going ...
NeoZoom.lua's user avatar
  • 1,460
0 votes
2 answers
109 views

How to apply a command to all tabs?

As title. I want to call a command to all existing tabs to close all windows of specific filetype. How to do so efficiently?
NeoZoom.lua's user avatar
  • 1,460
0 votes
1 answer
53 views

Is it possible to disable showing `-- VISUAL LINE --` hint in the command line?

As title: I have a plugin that needs to show something in cmdline but now the space is occupied by: -- VISUAL LINE -- Any hint to get rid of it?
NeoZoom.lua's user avatar
  • 1,460
0 votes
1 answer
607 views

How to move buffer between tabs?

As title. And I also need to know how to specify a tab to move to. So I expect the syntax would look like this: :movebuf <buffer_id> <tab_id>
NeoZoom.lua's user avatar
  • 1,460
0 votes
0 answers
12 views

Why `<C-h>` is mapped to backspace even if I remove all the insert-mode keymaps of `<C-h>`? [duplicate]

As title. I'm using NeoVim and there is a syntax to remove all mappings of specific key-comb. in specified mode: vim.keymap.del('i', '<C-h>') But after the call :imap <C-h> shows: i <C-...
NeoZoom.lua's user avatar
  • 1,460
0 votes
1 answer
347 views

Is it possible to detect key-release event in NeoVim?

As title. I want to simulate the App-switching feature of macOS cmd+tab. To do so I need to detect the release of some key to trigger my lua function. Any idea?
NeoZoom.lua's user avatar
  • 1,460
0 votes
2 answers
792 views

How to get the filename where the line of vimscript/lua is in?

As title. Say I have a line to create an augroup located in file git.lua. What I want to achieve is that that line will always create an augroup named git.lua without hard-coding it by the string &...
NeoZoom.lua's user avatar
  • 1,460
1 vote
0 answers
335 views

Help setting up init.lua in Neovim, I'm a new user and don't understand the structure for plugins

First of all, I'm not a programmer, but a musician. I just happen to (kind of) know how to use the terminal, and I use a music notation/engraving program called LilyPond that works in the terminal. ...
Kai Vinter'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
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
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 ...
anonymous017's user avatar
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 ...
Mattia72's user avatar
  • 191
1 vote
0 answers
44 views

How to to get commmand completions for selection from a keymap?

The idea is to have a keybinding, which executes a lua/vimscript function to paste yanked text into the command line and then have the command completion showing suggestions or directly get the ...
Jay-Pi's user avatar
  • 123
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
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
0 votes
1 answer
447 views

Using Lua, how can I run a function whenever the cursor moves?

I want a function to fire whenever the cursor moves. How can I do this?
White's user avatar
  • 3
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
0 votes
1 answer
220 views

NeoVim-LUA: can vim.b only hold read-only data?

I'm writing a plugin for NeoVim in Lua and I'm trying to keep the state of my plugin in the vim.b table: vim.b.myplugin = vim.b.myplugin or { "property" = "value", ... } ...
Boris Brodski's user avatar
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 ...
Piet Pro's user avatar
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
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
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
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
0 votes
1 answer
1k views

Reload function when sourcing init.lua

In "~/.config/nvim/lua/foo.lua" I have the following local M = {} function M.test() vim.notify("hello") end return M And then in my init.lua I have local test = require('foo')....
Kurtis Nusbaum's user avatar
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.
NeoZoom.lua's user avatar
  • 1,460
1 vote
1 answer
7k views

How to setup intelephense with neovim + lua?

I have 2 neovims, one with coc, and another with lua. In neovim with coc, intelephense works. I am working with wordpress, and i need intelephense. Nvim coc setup. plugins.vim Plug 'yaegassy/coc-...
serii 's user avatar
  • 91
1 vote
1 answer
380 views

Attach to terminal buffer opened with termopen

I have the following Lua function: local function submit_diff(diff_msg_file) vim.fn.termopen("arc diff HEAD^ -F " .. diff_msg_file, { on_exit = function(_, exit_code, _) if ...
Kurtis Nusbaum's user avatar
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
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
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
0 votes
0 answers
597 views

(Code review) Copying file path relative to cwd with the line number appended

I am replicating what PHPStorm and VSCode do by allowing me to copy the file path and line number (plus column) to clipboard. I have written a function in lua to do this, but, I wanted to ask about ...
Marwan Fikrat's user avatar
0 votes
0 answers
782 views

How to get the current window horizontal padding?

Today I wrote this little utility function to resize my current window to a comfortable width: -- Resizes the current window to the maximum required width function M.resize_window() local padding =...
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
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
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'...
Evan Carroll's user avatar
  • 1,314
1 vote
0 answers
449 views

How does .vimrc relate to ~/.config/nvim/init.lua?

When I heard neovim had a "native language client", I wanted to trying moving it. Previously, I was using a language server loaded through vim-plug. This was always problematic. When I ...
Evan Carroll's user avatar
  • 1,314
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
1 vote
1 answer
1k views

How can I find what Lua API functions are supported in my Neovim?

When I try to run the following code in my conf or under :luado vim.api.nvim_create_autocmd({"BufNewFile", "BufRead"}, { pattern = {"*.t"}, callback = function () ...
Evan Carroll's user avatar
  • 1,314
1 vote
1 answer
1k views

How do you set terminal options like t_Co in neovim?

When I put into my ~/.config/nvim/init.lua vim.opt.t_Co = 256 I get E5113: Error while calling lua chunk: vim/_meta.lua:659: Not a valid option name: t_Co But there is an option in vim called t_Co. ...
Evan Carroll's user avatar
  • 1,314
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
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
0 votes
1 answer
2k views

How to install sumneko_lua

I'm a Mac user with complete lua config. I have tried installing sumneko_lua in Neovim 0.6.1 several times but without success. Frustration led me to open this question. I have also read and tried to ...
Joannes's user avatar
  • 237
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
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
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 ...
muppi090909's user avatar
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
1 answer
2k views

Neovim Lua script to dynamically load .lua config files

I'm trying to implement a Lua script that can dynamically load NeoVim .lua configuration files, given a single folder name. Here's the requireaPath function function requirePath(path) local files = ...
josef.van.niekerk's user avatar
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
0 votes
0 answers
234 views

Lua syntax errors when using `Packer` plugin manger with `config=require()` in Neovim

I'm using neovim 0.6.0 and my config is written in Lua. My init.lua file requires files such as mappings and plugins. I use packer to manage plugins, and when calling the packer use command I can pass ...
john's user avatar
  • 183
0 votes
2 answers
596 views

How to check if a buffer hidden in all tabs?

As title. I want to check that a buffer is not shown in any tabs. How to do so?
NeoZoom.lua's user avatar
  • 1,460