Questions tagged [lua]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
20 views

How can I color a certain character, using Lua or otherwise?

I want to color arbitrary characters. As an example, let's say we want to color whatever character is to the immediate right of the cursor. Suppose we have the line: int x = 5; and the cursor is on n,...
  • 3
0 votes
1 answer
31 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?
  • 3
-1 votes
0 answers
14 views

Raspberry Pi Neovim is missing meta-accessors

On my Raspberry Pi I installed neovim. While writing the configuration files in Lua vim.g and vim.o don’t exist. Is it possible to install the meta-accessors afterwards by hand?
  • 1
1 vote
1 answer
126 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, ...
  • 113
0 votes
1 answer
19 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", ... } ...
0 votes
0 answers
11 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 ...
1 vote
1 answer
22 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 ...
0 votes
0 answers
21 views

What is the Lua equivalent of an <expr> mapping with the ternary operator (?:)?

I was trying to set up a keybinding for vsnip in NeoVIM using Lua. The docs provide a vimscript snippet that I've been unable to translate. What would be the Lua equivalent of: imap <expr> <...
0 votes
1 answer
47 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
  • 151
1 vote
1 answer
186 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
  • 151
0 votes
0 answers
140 views

Neovim how to rexecute vim.fn.expand() every time a keymap is called?

I would like to create a keymap to edit files by my current path, while showing the directory path of the current file For example, if I was editing file: /Users/[username]/projects/test.py Clicking &...
  • 111
3 votes
1 answer
75 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 ...
0 votes
1 answer
229 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')....
0 votes
1 answer
32 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.
  • 781
0 votes
1 answer
759 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-...
  • 15
0 votes
1 answer
62 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 ...
0 votes
2 answers
823 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/...
2 votes
1 answer
532 views

How to remove vim trailing white space?

In Vim I used autocmd BufWritePre * :%s/\s\+$//e to delete trailing white space. Now, Neovim 0.7 has the new vim.api.nvim_create_autocmd. What is the correct syntax to update this autocmd in Lua? vim....
  • 123
0 votes
1 answer
1k 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....
0 votes
0 answers
110 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 ...
0 votes
0 answers
104 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 =...
0 votes
1 answer
479 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. ...
  • 135
2 votes
2 answers
48 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 ...
  • 123
0 votes
0 answers
145 views

Convert Vim keymap to lua

I want to change my emmet leader key in vim, but I do not know how to do this in lua. Vim Script code: imap ,, <C-y>, Lua Code: local map = vim.keymap.set
  • 1
0 votes
1 answer
52 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'...
1 vote
0 answers
91 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 ...
2 votes
1 answer
184 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. ...
1 vote
1 answer
542 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 () ...
1 vote
1 answer
235 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. ...
-1 votes
1 answer
222 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)
0 votes
2 answers
970 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?
0 votes
0 answers
799 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 ...
  • 123
0 votes
1 answer
714 views

keymap 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....
  • 101
1 vote
1 answer
424 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 ...
0 votes
1 answer
369 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
2 answers
367 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....
  • 1,277
0 votes
0 answers
80 views

How I can refresh a lua script?

How to reproduce, in ~/.config/nvim/init.vim: command! Scratch lua require'tools'.hello() In ~/.config/nvim/lua/tools.lua: local M = {} function M.hello() print('hello') end return M nvim :Scratch ...
0 votes
1 answer
814 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 = ...
1 vote
1 answer
584 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, ...
  • 31
0 votes
0 answers
98 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 ...
  • 163
0 votes
2 answers
412 views

How do I change my language in my init.lua? - neovim

I've got the problem that the neovim language is set to German for some reason even though I only use a German keyboard layout (see this question). Unfortunately I am using lua for configuring neovim (...
0 votes
0 answers
387 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 ...
  • 101
1 vote
1 answer
50 views

BufDelete running after window is closed

For some reason, the BufDelete autocommand is being executed right after a window is created, instead before, and i think it shouldn't be like that, according to the docs: Before deleting a buffer ...
0 votes
2 answers
21 views

Insert mode <S-Tab> to delete one <Tab>-indent?

I want to use <S-Tab> to do the reverse of <Tab> in insert mode in Lua. (If this is complicated in Lua then VimScript is OK) How?
  • 781
1 vote
2 answers
274 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 ...
  • 781
1 vote
0 answers
461 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-...
0 votes
1 answer
1k 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 ...
0 votes
2 answers
126 views

Run a Function Upon Exiting a Terminal

By using the following code... vim.fn.termopen("foo") I can open a terminal with a certain command. What I want to do is run a Lua function from a plugin upon exiting the terminal. Pseudo ...
  • 126
1 vote
1 answer
296 views

How can I read the contents of a buffer or line then rewrite them, from a Lua script?

I am trying to write a pretty-printer Lua plugin for a LaTeX-like language. The idea is that if a user types \cup in insert mode then presses <Space> or <Tab> or <CR>, then my script ...
  • 113
0 votes
2 answers
133 views

How to find line and column for a n-th byte in a buffer?

I want to find a line number and a column for a particular byte number in a buffer in Neovim. I can get it (sort of) with local b = 444 local line = vim.fn.byte2line(b) local line_start = vim.fn....
  • 135