5

A simple way to do it is like this: local n_keymap = function(lhs, rhs) vim.api.nvim_set_keymap('n', lhs, rhs, { noremap = true, silent = true }) end n_keymap('foo','bar') But in my opinion that doesn't make any sense because the map function are quite powerful (they support different modes, recursive or not, silent or not, expression mappings, buffer ...


4

It must be vim.api.nvim_call_function("sign_define", {"LspDiagnosticsErrorSign", {text = "whatever", texthl = "LspDiagnosticsError"}}) as Lua has its own syntax for defining tables. Or, at least in 0.5, you can do vim.fn.sign_define("LspDiagnosticsErrorSign", {text = "whatever", texthl = &...


3

You can save and restore the current tab around the :tabdo operation. You can use tabpagenr() to get the position of the current tab and later you can pass that number to :tabnext to change back to this tab. This is better done in a function, since you can easily run multiple commands and also use a local variable to store the current tab number. function! ...


3

$MYVIMRC is an environment variable that Vim adds to the current environment. Environment variables are usually inherited by child processes from their parent process. For example, you can see $MYVIMRC in a shell that is a child process of Vim: :!printenv | grep MYVIMRC (I use this form rather than just :!echo "$MYVIMRC" to "prove" that ...


3

filetype is a buffer-local option, so you can access it with: vim.bo.filetype From :h lua-vim-options: From Lua you can work with editor |options| by reading and setting items in these Lua tables: vim.w ... vim.bo *vim.bo* Get or set buffer-scoped |local-options|. Invalid key is an error. ...


2

As of of June 2015, the lua to VimsSript transpiler integration is still being worked on, so currently you cannot use Lua to write .nvimrc, unfortunately. See this issue: https://github.com/neovim/neovim/issues/1536


2

The 'listchars' option is implemented as a Lua table (akin to a Dict in Vim, possibly more similar to an object in JavaScript), so what you need to only change the extends setting is: vim.opt.listchars.extends = "#" Or, also valid: vim.opt.listchars["extends"] = "#"


2

At least for single characters, here's what I would do. First, let's build a little function for an expression map. It takes a dictionary corresponding to the cycle, examines the character under the cursor, and returns the sequence of commands to do. This is either a r command or nothing. function CyclePair(which_pairs) abort let char_under_cursor = ...


2

This is already answered but I just wanted to add another way to access environment variables in lua using vim API. vim.env.whatever -- will give you the value of whatever vim.env.test = "test msg" -- sets env variable test to value "test msg" I believe this way is more readable and more pleasant to script than using os.getenv


2

I have found a slightly different solution here: local function map(mode, lhs, rhs, opts) local options = {noremap = true} if opts then options = vim.tbl_extend('force', options, opts) end vim.api.nvim_set_keymap(mode, lhs, rhs, options) end Bellow, you have some example mappings using the proposed function -- <Tab> to navigate the completion ...


2

:h nvim_win_get_cursor() will return a tuple containing the current cursor position, which you'll have to unpack to use. It takes an argument {window}, and you can use 0 to specify the current window. :h nvim_get_current_line() is the Neovim Lua analog to getline('.'). Here is an example: function check_back_space() -- get row and column local row, ...


1

disable_commands = true was disabling PackerInstall, PackerSync, etc., but not the plugin, so I switched to using packer.sync() inside plugins.lua, and it worked fine.


1

Incorporating @B Layer's feedback I came up with the following code, that is able to stop scrolling, make it slower/faster without creating global variables. local M = {sleep = 1000, timer = nil} function M.down() print(M.sleep) M.timer = vim.loop.new_timer() M.timer:start(1000, M.sleep, vim.schedule_wrap(function() local down = vim.api....


1

As of nvim 0.5.1, on MacOS and Linux, it appears that the vim.opt.listchars:append in my original question now works, and for some reason setting the map values as in vim.opt.listchars.extends = "e" or vim.opt.listchars.tab = "t" no longer works. vim.opt.listchars:append({ extends = "#" }) print(vim.inspect(vim.opt.listchars:get(...


1

This was how I sorted out my problem in the end vim.api.nvim_command([[ augroup ChangeBackgroudColour autocmd colorscheme * :hi normal guibg=#0a0a0a augroup END ]]) vim.o.termguicolors = true vim.cmd [[silent! colorscheme snow]]


1

The v:lua interface was only introduced to NeoVim in PR #11338, which has a milestone of 0.5, so it looks like it's not generally available in released versions of NeoVim just yet. (NeoVim 0.5 is still in Beta as of early May 2020.) You should use the luaeval() Vimscript function to evaluate a Lua expression (such as a function call) and use the returned ...


1

Christian Brabandt is correct, Vim requires the exact same version it was compiled for. In my case, however, Vim still failed to load liblua.5.2.dylib even after installing Lua 5.2. I fixed that by adding a line to my .vimrc to explicitly tell Vim where to look: set luadll=/path/to/liblua.5.2.dylib


1

Yes, you Vim was compiled in such a way, that Vim will be looking for the dynamic library liblua5.2.dylib. If Vim cannot find that library, it obviously cannot use the lua extension. This however is independent of usine :!lua which will shell out to the lua binary and run that command. For that, you do not need to compile Vim with +lua you just need to have ...


Only top voted, non community-wiki answers of a minimum length are eligible