Questions tagged [lua]

Question about the Lua binding in Neovim

Filter by
Sorted by
Tagged with
0 votes
2 answers
786 views

How can I switch to the `[No Name]` buffer

As title. Is it possible to change the current buffer by vimscript to the (only) [No Name] buffer? I need these tools: an API to return all (loaded) buffers loop through each of them if the buffer ...
NeoZoom.lua's user avatar
  • 1,460
0 votes
2 answers
3k 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 (...
CozyPenguin's user avatar
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 ...
Elv13's user avatar
  • 101
1 vote
1 answer
115 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 ...
henriquehbr's user avatar
0 votes
2 answers
95 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?
NeoZoom.lua's user avatar
  • 1,460
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
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
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
0 votes
2 answers
279 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 ...
InsertSON's user avatar
  • 376
1 vote
1 answer
817 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 ...
ahelwer's user avatar
  • 113
0 votes
2 answers
387 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....
dimus's user avatar
  • 145
0 votes
0 answers
473 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')
nextloop's user avatar
  • 113
1 vote
0 answers
155 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?
Eric Wong's user avatar
  • 530
1 vote
1 answer
173 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 ...
SergioAraujo's user avatar
  • 1,175
0 votes
1 answer
379 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 ...
John Winston'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
0 answers
372 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 ...
Pierre's user avatar
  • 11
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
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

1 2 3
4