Questions tagged [vimscript-lua]

Lua programming interface to Vim. DO NOT use for questions with Lua examples or about syntax highlighting in Lua.

Filter by
Sorted by
Tagged with
1 vote
1 answer
55 views

Resize a vertical split to just fit the max width of the file contents

I'm trying to make the width of a vertical split as small as possible but still fully show even the longest line of text. No line wrap. I'm trying to do something like :vertical resize <longest-...
agshe's user avatar
  • 23
1 vote
2 answers
83 views

VimL: check if Lua is supported

How do I check if Lua is supported? From my .vimrc, I only want to put an if around a Lua heredoc so that my config works in plain vim or versions of neovim which didn't support Lua (pre 0.5.0?). What'...
Tom Hale's user avatar
  • 2,601
1 vote
1 answer
87 views

Negate pattern in autocmd

I have some lua auto command that triggers whenever I open a file that has */some_pattern/* in the path. vim.api.nvim_create_autocmd({ 'BufEnter' }, { pattern = vim.fn.expand('~') .. '*/...
Stein's user avatar
  • 143
1 vote
1 answer
778 views

How to write clipboard+=unnamedplus in a lua config?

I'm wondering how could i write the settings: set clipboard+=unnamedplus in a lua config. Currently i do this: vim.cmd("set clipboard+=unnamedplus") but is there a way to use: vim.opt....
enthus1ast's user avatar
1 vote
1 answer
1k views

How to setup treesitter in vim script?

I have my entire nvim setup written in vim script at ~/.config/nvim/init.vim, but tresitter on it's GitHub says require'nvim-treesitter.configs'.setup { -- A list of parser names, or "all" ...
Vladyslav Rehan's user avatar
2 votes
2 answers
3k views

Recommended way to run vimscript normal commands with lua

What is the recommended way to run VimScript normal commands in Neovim with Lua? Sometimes, I can achieve things very easily with a few keypresses executed as a normal command compared to scripting ...
matko031's user avatar
1 vote
2 answers
414 views

Vimtex - How to run :VimtexCompile on start using lua

How do I execute :VimtexCompile automatically whenever I open a .tex file? As mentioned in this GitHub thread, this is done in Vimscript via: augroup vimtex_config autocmd User VimtexEventInitPost ...
A is for Ambition's user avatar
1 vote
2 answers
107 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
0 votes
0 answers
639 views

Create a temporary, readonly buffer for test output in Neovim

I want to create a Neovim plugin that automatically runs a test suite whenever a file is saved. Here's an overview: If I save a Rust file, run cargo test If there's not a buffer opened for the test ...
Nick's user avatar
  • 101
1 vote
1 answer
147 views

Having trouble setting up syntax regions from lua [closed]

I'm running nvim v.0.8.1 on LuaJIT 2.1.0-beta3. In a lua config file I have: vim.cmd[[syntax include @Yaml syntax/yaml.vim]] vim.cmd[[syntax region yamlFrontmatter start=/^---$/ end=/^---$/ keepend ...
SoyBison's user avatar
2 votes
1 answer
382 views

How to find LUA method for VIM Command

I am in the process of converting my .vimrc to init.lua. Several of my lines end up containing vimscript inside a call to vim.cmd, such as vim.cmd("highlight Normal guibg=none ctermbg=none") ...
Benj's user avatar
  • 145
0 votes
1 answer
2k views

How to get the scrolloff set by user in Lua for NeoVim?

As title. I'm fixing a plugin and I need to know the scrolloff set by user.
NeoZoom.lua's user avatar
  • 1,302
0 votes
1 answer
707 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
0 votes
1 answer
859 views

Passing a count to a user command with neovim's Lua API

vim.api.nvim_create_user_command("TestCommand", function(opts) print(opts.count) end, { count = 1 }) vim.keymap.set("n", "<C-x>", "<cmd> TestCommand ...
what the's user avatar
  • 101
1 vote
1 answer
214 views

What's the effect of "range" on :lua and :luafile commands?

The :lua and :luafile commands take an optional [range] specification. But it's unclear what effect it has (unlike the :luado command, where the effect is explained clearly in the help text). Is ...
user98761's user avatar
  • 121
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
0 votes
0 answers
162 views

Porting Asyncrun vimscript to lua

In my Vim's configuration file init.vim I am using code, that sets a default viewer for practically any kind of file suffix. Here I will demonstrate only an example for .md files: let g:...
71GA's user avatar
  • 109
2 votes
1 answer
972 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
1 answer
1k 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
3 votes
1 answer
2k views

neovim: vim.fn is nil

I have a lua plugins script defining local fn = vim.fn. A couple of lines later it defines local install_path = fn.stdpath('data'). This script is called from my init.vim by lua require('plugins'). ...
Jonathan Scholbach's user avatar
1 vote
0 answers
971 views

LspConfig code action does not work

I have problems with LspConfig when extracting a method to a new file. When executing the following command buf_set_keymap("n","<space>ca","<cmd> lua vim.lsp.buf....
FrFernandez's user avatar
0 votes
0 answers
89 views

Cursorline became black when cursor is moving

If I change the colorscheme by <option>+12345 :colorscheme newsprint Then when I will firstly got the expected result: But then if I move my cursor by j/k, the clean cursorline gone: I can ...
NeoZoom.lua's user avatar
  • 1,302
0 votes
1 answer
1k views

How to use packer.use inside neovim?

I was switching vimscript to lua in neovim, and I saw packer.nvim is a famous plugin manager for lua. In this README.md file I saw I can use startup function, but it's not required and I can also use ...
rafid100's user avatar
0 votes
1 answer
2k views

How to transform this Vimscript into Lua?

Can anyone help me transform this into nvim.lua? inoremap <silent><expr> <TAB> \ pumvisible() ? "<C-n>" : \ <SID>check_back_space() ? "<TAB&...
NeoZoom.lua's user avatar
  • 1,302
0 votes
0 answers
408 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
0 votes
1 answer
249 views

How to colorize words in a buffer, using type data and position data?

I am writing a plugin for Neovim using Lua. If I have a text and some predefined arbitrary types, for example: chita wolf grizzly types: dog(green), cat(blue), bear(yellow) And I know positions/...
dimus's user avatar
  • 135
0 votes
1 answer
2k views

How to use vim.loop interactively in Neovim?

I want to read texts with Neovim scrolling them down automatically. The following code provides such functionality: local M = {} function M.down() local timer = vim.loop.new_timer() local ...
dimus's user avatar
  • 135
1 vote
1 answer
262 views

How to provide modifier keys in lua?

If I want to move a cursor one line down with Lua in Neovim I can use :lua vim.cmd('normal j') How do I move the screen down one line? For example, this does not work: :lua vim.cmd('normal \<C-E&...
dimus's user avatar
  • 135
0 votes
0 answers
211 views

How to get strings between `[ and `] in lua?

I'm trying to play around with text objects in lua, here's what I got: https://learnvimscriptthehardway.stevelosh.com/chapters/33.html On that webpage, I found that I can operate on the text send to ...
lyhokia's user avatar
0 votes
1 answer
200 views

How to call function with lisp style via mappings from lua in neovim?

I'm trying to use v:lua to call functions written in lua (actually it's fennel, which compiles to lua). Now I have a function named lisp-style , then I can't directly use v:lua.lisp-style() because it'...
lyhokia's user avatar
2 votes
1 answer
306 views

How to tabdo all the visible buffers without changing view of the current tab?

My init.vim code: cd ~/Documents/cp nnoremap <leader>lcd :tabdo lcd %:p:h<cr> suppose, i have 4 tabs opened in nvim via using nvim -p A.cpp B.cpp C.cpp D.cpp A.cpp B.cpp C.cpp D.cpp ...
Mega Bang's user avatar
  • 199
1 vote
3 answers
12k views

Short key mapping by lua for Neovim?

The simple way to remap key in lua is: vim.api.nvim_set_keymap('n', 'foo', 'bar', { noremap = true, silent = true }) But I want a simple syntax like vimScript: nnoremap foo bar n_keymap('foo','bar') ...
nextloop's user avatar
  • 113
3 votes
4 answers
10k views

Neovim lua config: how to append to listchars?

In a neovim init.lua config, I know that I can append to a string like so: vim.opt.wildignore:append("*/node_modules/*,*/vendor/*,*/venv/*,*/.venv/*,*/target/*") However, I'm getting errors ...
n8henrie's user avatar
  • 346
0 votes
2 answers
49 views

Cycle through a list of letters in multiple groups

So I have a case where I have some unicode letters say [B, Ḅ, Ḃ] and when I have my mouse selected over the B, (in normal mode) I want some way of cycling through the list. Like pressing some command ...
N3buchadnezzar's user avatar
7 votes
2 answers
5k views

Get value of $MYVIMRC from Lua

I am trying to retrieve the value of $MYVIMRC in my init.lua but I am coming up short because I don't understand what $MYVIMRC actually is. It is not a global variable, is it? None of these work: vim....
severin's user avatar
  • 173
1 vote
0 answers
685 views

Autoloaded vs lua functions: which is faster/more efficient?

I'm creating a neovim plugin written in Lua, and I have to react to the BufAdd and BufUnload events with a function call. I have 3 options: write the function in Lua (like the rest of the plugin) and ...
noibe's user avatar
  • 179
0 votes
0 answers
75 views

Cannot search for pairs with searchpairpos()

I am trying to search for the location of the start and the end of a pair with searchpairpos(). Given an example like this: *hel[]lo* And my code like this: local start_match = vim.api....
John Winston's user avatar
3 votes
2 answers
11k views

How to modify only the background colour of a colourscheme in neovim using lua

I am slowly switching my neovim configurations to Lua. I am currently using the colour scheme https://github.com/nightsense/snow. It sets the background colour to a light-grey, while I want it to be a ...
vixiv's user avatar
  • 51
13 votes
1 answer
20k views

How to get the filetype in lua in nvim

How to get the current file type in lua with neovim? I tried following but all of them returns nil. print(vim.g.filetype) print(vim.b.filetype) print(vim.w.filetype) print(vim.t.filetype) print(vim.v....
s1n7ax's user avatar
  • 485
5 votes
1 answer
10k views

Most efficient way to call a Vim script function with lua (Neovim)

What is the most efficient way to call a Neovim function using Lua. I am able to call the sign_define Vim script function using the nvim_command procedure. I struggle with calling it with the ...
tkolleh's user avatar
  • 169
4 votes
1 answer
2k views

Neovim Lua integration

I'm trying to understand how can I use Lua to extend Neovim, following a baby steps approach. Something like: -- ~/.config/nvim/lua/test.lua local api = vim.api local firstmodule = {} function ...
Bobby Wan-Kenobi's user avatar
0 votes
0 answers
1k views

Adding directories to Lua’s search path

I’m trying to run Fennel scripts in Vim 8.1 using the fennel-nvim plugin. (Fennel is a language that basically lets you write Lua with LISP syntax; you can use it from any Lua-supporting application ...
bdesham's user avatar
  • 2,923
5 votes
2 answers
4k views

How to use Lua in Vim?

I'm using MacVim snapshot 134 (on Mac OS X 10.9.5), which has support for Lua: $ vim --version | grep lua +dialog_con_gui +lua/dyn +rightleft +writebackup I've got Lua installed and ...
8bittree's user avatar
  • 1,487
5 votes
1 answer
2k views

Is it possible to write .nvimrc for NeoVim in Lua?

Is it possible to write .nvimrc for NeoVim in Lua? Is it planned for the future?
Michał Bendowski's user avatar