Skip to main content

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
0 votes
0 answers
17 views

How to make neovim's filetype awareness synchronous?

If my init.lua contains the following: vim.cmd('syntax enable') print("test") print(vim.bo.filetype) print("test") Then the output is: test test But if I put some other ...
Brett Holman's user avatar
0 votes
1 answer
23 views

Setting "g:jedi#use_tabs_not_buffers" option in lazy.nvim in lua

I've started recently to use lazy.nvim to load plugins. I'm also trying to move the configuration from vimscript to lua, as well. Most changes seem to be straightforward, but there's one that I am not ...
Jir's user avatar
  • 103
1 vote
1 answer
117 views

Why is vim.fs.joinpath() missing from neovim 0.9.5 on macOS?

The online documentation mentions vim.fs.joinpath() but I can't find that on my local Neovim with :help vim.fs.joinpath, it's not on :help lua at all. And :lua print(vim.fs.joinpath) says it's nil. I ...
RubenLaguna's user avatar
1 vote
1 answer
49 views

How can I accept a range in a Lua user command?

I want to optionally accept a range in a user-defined function: vim.api.nvim_create_user_command('Pizzafy', function(args) if args.range > 0 then -- visual mode, I think ...
Sasgorilla's user avatar
0 votes
2 answers
86 views

How do I switch modes inside a user-defined lua function?

I want to write a command to do the following: Make a visual selection. Call a command on the visual selection. By way of example, I'd like to call vat to visually select around the current tag, and ...
Sasgorilla's user avatar
0 votes
0 answers
180 views

What is the difference (if any) betweeen vim.fn.getcwd() and vim.loop.cwd()?

I saw that the harpoon2 plugin uses vim.loop.cwd() in here, and then it got me thinking what is the difference between using vim.fn.getcwd() and vim.loop.cwd(). The following code returns the same ...
RubenLaguna's user avatar
2 votes
1 answer
227 views

Conceal features in init.lua

The Neovim user guide says to issue these commands to show the concealed characters in the user guide: :set conceallevel=0 :hi link HelpBar Normal :hi link HelpStar Normal What would be the ...
robertspierre's user avatar
1 vote
1 answer
92 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
194 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,711
1 vote
1 answer
184 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
3k 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
3k 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
6k 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
586 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
176 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
1 vote
0 answers
943 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
  • 111
1 vote
1 answer
198 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
424 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
  • 175
0 votes
1 answer
3k 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,530
3 votes
2 answers
873 views

Detecting the Enter and Leave of Visual mode event

Are there any events similar to InsertEnter and InsertLeave that I could use for visual mode? Looking through the helpfiles, I did not fine any. If not, how would I be able to detect if Vim enters or ...
unrealapex'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
0 votes
1 answer
1k 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
268 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
5k 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
178 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
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
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 Herrera's user avatar
1 vote
0 answers
1k 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
94 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,530
0 votes
1 answer
2k 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,530
0 votes
0 answers
487 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
  • 223
0 votes
1 answer
375 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
  • 145
0 votes
1 answer
3k 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
  • 145
1 vote
1 answer
294 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
  • 145
0 votes
0 answers
232 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
208 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
363 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
  • 309
2 votes
3 answers
15k 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
  • 223
3 votes
4 answers
13k 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
  • 436
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
7k 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
710 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
  • 189
0 votes
0 answers
101 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
5 votes
2 answers
13k 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
  • 81
16 votes
1 answer
27k 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
  • 555
5 votes
1 answer
12k 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
5 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,983