I'm transitioning my neovim configuration from vimscript to lua. The following code is intended to change the color of the message area as the mode changes, as I did in the old configuration, but it is having no effect.
Changing the MsgArea any color I want outside the autocmd works fine
These debug messages print as expected when I change mode, so I know the autocmd is working
The MsgArea color does not change with the mode
I'm new to lua. Can you identify a syntax or conceptual problem here?
local normal_fg="#00ff00"
local normal_bg="#202020"
local insert_fg="#202020"
local insert_bg="#00ff00"
vim.api.nvim_set_hl(0,'MsgArea',{fg=normal_fg,bg=normal_bg,bold=true}) -- works fine
vim.api.nvim_create_autocmd( "InsertEnter",{ pattern="*",
callback=function()
vim.api.nvim_set_hl(0,'MsgArea',{fg=insert_fg,bg=insert_bg,bold=true}) -- no effect
print("inverted the colors") -- works fine
end
})
vim.api.nvim_create_autocmd( "InsertLeave",{ pattern="*",
callback=function()
vim.api.nvim_set_hl(0,'MsgArea',{fg=normal_fg,bg=normal_bg,bold=true}) -- no effect
print("back to normal") -- works fine
end
})
NVIM v0.7.2
Related
I want to make the Mason window transparent, in neovim, using lua.
Here was suggested to set winbled locally as autocommand but its not using the newer lua api: https://github.com/williamboman/mason.nvim/discussions/355.
autocmd FileType mason setlocal winblend=10
I am trying to do the same with lua:
vim.api.nvim_create_autocmd("FileType", {
pattern = "mason",
callback = function() vim.opt_local.winblend = 10 end,
})
Nothing is happening after sourcing this. No error and no transparent window.
I can't figure out how to copy from vim, and paste to another console tab.
For instance, I'm using the preconfigured nvimdocker / ansible-neovim-pyright container. I did try:
set mouse= I can copy/paste with middle click, but I get the column with line numbers in the clipboard. Makes it unpracticable to copy few lines of script.
set mouse=nv This is great, I can select the text without the line numbers. Potentially right-click->Copy. But none of the * (highlight clipboard) nor + (system clipboard) registers are working. (None of the middle-click or explicit paste will work).
Obviously, it's not possible to access the system clipboard from remote, and xclip cannot help. I think the problem is similar when using a remote nvim through SSH (with no X redirection).
But how could I have the 'highlight' clipboard ? Is there maybe a (n)vim command to temporarily disable the left column with numbers/git/modifs/coc-errors ?
Thanks,
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:netrw_browsex_viewer="-"
function! NFH_md(f)
call asyncrun#run("", "cwd", "typora " . a:f)
endfunction
First paragraph makes sure to choose the function based on suffix of the file ("URI under cursor"). Second paragraph shows a function whose name i.e. NFH_md implies that this is the function opened when .md file is in the "URI under the cursor". Inside this function there is an call that opens an external program typora asynchronously so that I am still able to continue using Vim.
If you want to know more use :help netrw_browsex_viewer.
I tried porting the mentioned Vim script to Neovim & Lua but I only managed to port first line:
vim.g.netrw_browsex_viewer="-"
For I don't know, how to properly port the second paragraph. This is why for now I just use Vimscript source code like this:
vim.api.nvim_exec(
[[
function! NFH_md(f)
call asyncrun#run("", "cwd", "marktext " . a:f)
endfunction
]],
false
)
But I would love to translate all the code to Lua - Could anyone help a bit to translate this remaining Vimscript code to Lua?
I have tried making a Garry's Mod lua file to look for messages containing "/discord" at the beginning of them and save that message as a text file in the same directory, I'm not familliar to lua files so I am unsure of syntax but when I look at console, nothing happens, when I look at the server command line, nothing happens and no new file is created, I even serached my entire PC.
I used the following page on the Garry's mod wiki: https://wiki.garrysmod.com/page/GM/PlayerSay and the code given there works but as soon as I added anything, it stopped working completely. Here is my code:
hook.Add( "PlayerSay", "GmodToDiscord", function( player, text, team )
if ( string.sub( string.lower( text ), 0, 7 ) == "/discord" ) then -- Makes message lowercase to be read by the program.
local file = io.open("message.txt", "w") -- Opens a text file in write mode.
file:write(message) -- Pastes in the message.
file:close() -- Closes the text file.
end
end)
Any help would be greatly appreciated.
You cannot use Lua's io library within Gary's mod. Use the Gary's Mod's file module instead.
https://wiki.garrysmod.com/page/file/Open
Example:
local f = file.Open( "cfg/mapcycle.txt", "r", "MOD" )
print( f:ReadLine() )
print( f:ReadLine() )
print( f:Tell() )
f:Close()
A thing to note about Lua, and what makes it a rather whacky language, is that it's arrays begin at index 1. You will need to check between 1 and 8 to get your tags; that should help you get started on #Piglet's implementation of the file IO.
Good luck, and happy modding!
Non-Latin characters are not truncated properly so I modified the fragmentText() function to truncate on white space. file is in:
"C:\CocosCreator\resources\engine\cocos2d\core\label\CCTextUtils.js"
fragmentText: function (stringToken, allWidth, maxWidth, measureText) {
return "function called";
}
The problem is that I see the changes in Cocos Creator editor and the text is truncated as I want, but I see no effect on the browser as the function is never called.
Why the function is not called when I build?
P.S: I use Cocos Creator 1.10 but also have 2.1.1 installed in C:\CocosCreator_2.1.1
I guess you forget to recompile the engine.
Check the step 1.3 on the website and try again.
1.3 Change and Build