Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [lua]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
16 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-...
user avatar
  • 15
0 votes
0 answers
10 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 ...
user avatar
0 votes
2 answers
60 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/...
user avatar
0 votes
1 answer
70 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....
user avatar
  • 103
0 votes
1 answer
73 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....
user avatar
0 votes
0 answers
24 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 ...
user avatar
0 votes
0 answers
31 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 =...
user avatar
0 votes
1 answer
56 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. ...
user avatar
  • 75
2 votes
2 answers
42 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 ...
user avatar
  • 123
0 votes
0 answers
33 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
user avatar
  • 1
0 votes
1 answer
31 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'...
user avatar
1 vote
0 answers
35 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 ...
user avatar
1 vote
1 answer
41 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. ...
user avatar
1 vote
1 answer
175 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 () ...
user avatar
0 votes
1 answer
39 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. ...
user avatar
-1 votes
1 answer
37 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)
user avatar
0 votes
2 answers
171 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?
user avatar
0 votes
0 answers
163 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 ...
user avatar
  • 103
0 votes
1 answer
231 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....
user avatar
  • 101
1 vote
1 answer
148 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 ...
user avatar
0 votes
1 answer
155 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 ...
user avatar
0 votes
1 answer
79 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....
user avatar
  • 1,237
0 votes
0 answers
33 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 ...
user avatar
0 votes
1 answer
302 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 = ...
user avatar
1 vote
1 answer
161 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, ...
user avatar
  • 21
0 votes
0 answers
41 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 ...
user avatar
  • 153
0 votes
2 answers
130 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 (...
user avatar
0 votes
0 answers
164 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 ...
user avatar
  • 101
1 vote
1 answer
33 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 ...
user avatar
0 votes
2 answers
20 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?
user avatar
  • 731
1 vote
2 answers
168 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 ...
user avatar
  • 731
0 votes
0 answers
231 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-...
user avatar
0 votes
1 answer
949 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 ...
user avatar
0 votes
2 answers
82 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 ...
user avatar
1 vote
1 answer
134 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 ...
user avatar
  • 113
0 votes
2 answers
74 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....
user avatar
  • 135
0 votes
0 answers
75 views

How to require `luafile` not in a subdirectory

in my config of init.lua ,I want to load a luafile from anywhere or any directory so : can I source it without function vim.cmd() vim.cmd('luafile /full/path/to/file.lua')
user avatar
1 vote
0 answers
49 views

How to run command asynchronously whith :lua command?

When using vim8.1, it does not provide vim.fn and vim.call function, so we can not use vim.fn.job_start. then how can I run command asynchronously in lua?
user avatar
1 vote
1 answer
35 views

How to get the searchcount() total of matches into a lua variable

The searchcount() gives use something like: {'exact_match': 1, 'current' : 1, 'incomplete': 0, 'maxcount': 99, 'total': 5} It is a dictionary, I am trying to do something based on the help: local ...
user avatar
0 votes
1 answer
146 views

How to get range value of a ex-mode command in Lua?

I want to get the range of ex-mode command in Lua(eg 1 and 3 in 1;3d). The range value should be stored as a:firstline and a:lastline in vim, but based on the doc, a is not implemented in the vim ...
user avatar
1 vote
0 answers
118 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 ...
user avatar
1 vote
0 answers
116 views

stash and restore highlight colors with lua and neovim

I would like to toggle an option and with it the highlight color of Whitespace. Before setting the color with vim.api.nvim_command("hi Whitespace guifg=#ff0000") I would like to stash the ...
user avatar
  • 11
3 votes
1 answer
1k 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(...
user avatar
1 vote
2 answers
1k 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 ...
user avatar