Open11
nvim and init.lua, lua scripting
.vimrc
PS C:\Users\sakai> cd $home
PS C:\Users\sakai> ls .vimrc
Directory: C:\Users\sakai
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 7/08/2023 5:13 AM 86 .vimrc
PS C:\Users\sakai>
:source %
init.vim
init.vim
PS C:\Users\sakai\AppData\Local\nvim> ls
Directory: C:\Users\sakai\AppData\Local\nvim
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 22/08/2023 8:14 PM 12 init.vim
PS C:\Users\sakai\AppData\Local\nvim> type .\init.vim
source ~\.vimrc
.vimrc
syntax on
set noerrorbells
set number
" indent setting
set expandtab
set tabstop=2 softtabstop=2
set shiftwidth=2
set smartindent
nvim -version
PS C:\Users\sakai\.config\nvim> nvim -version
NVIM v0.7.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compiled by runneradmin@fv-az276-503
Features: -acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM\sysinit.vim"
fall-back for $VIM: "C:/Program Files/nvim/share/nvim"
Run :checkhealth for more info
PS C:\Users\sakai\.config\nvim>
PS C:\Users\sakai\.config\nvim> nvim +Tutor
nvim - C:\Users\sakai\AppData\Local\nvim\init.lua
require('base')
require('options')
nvim\lua\options.lua
local options = {
encoding = "utf-8",
fileencoding = "utf-8",
title = true,
backup = false,
clipboard = "unnamedplus",
cmdheight = 2,
completeopt = { "menuone", "noselect" },
conceallevel = 0,
hlsearch = true,
ignorecase = true,
mouse = "a",
pumheight = 10,
showmode = false,
showtabline = 2,
smartcase = true,
smartindent = true,
swapfile = false,
termguicolors = true,
timeoutlen = 300,
undofile = true,
updatetime = 300,
writebackup = false,
shell = "fish",
backupskip = { "/tmp/*", "/private/tmp/*" },
expandtab = true,
shiftwidth = 2,
tabstop = 2,
cursorline = true,
number = true,
relativenumber = false,
numberwidth = 4,
signcolumn = "yes",
wrap = false,
winblend = 0,
wildoptions = "pum",
pumblend = 5,
background = "dark",
scrolloff = 8,
sidescrolloff = 8,
guifont = "monospace:h17",
splitbelow = false,
splitright = false,
}
for k, v in pairs(options) do
vim.opt[k] = v
end
lua scripting
01_hello.lua
--[[
01_hello.lua
--]]
-- -------------------------- local functions
function getMessage(name)
local str = 'Hello, '
return str .. name .. " !!"
end
-- --------------------------- Entry point
print 'Hello, world!'
-- call a function
local msg = getMessage("Lua")
print(msg)
io.write("Hello, world, from ", _VERSION, "!!\n")
-- number
local f = 70.0/3.0
print("value of f", f)
print(type(msg))
print(type(f))
print(type({}))
print("message:", msg)
print("Length :", #msg)
table
05_table.lua
--[[
05_table.lua
--]]
-- -------------------------- local functions
loopIndexTable = function(ary)
for k,v in ipairs(ary)
do
print(k, v)
end
end
loopTable = function(ary)
for k,v in pairs(ary)
do
print(k, v)
end
end
-- --------------------------- Entry point
local ary = {"lua", "lui", "luu", "lue", "luo"}
loopIndexTable(ary)
-- local hash = { 1 = "lua", 2 = "lui" }
-- local hash = { "lua" = "Lua", "lui" = "Lui" }
local hash = { lua = "Lua", lui = "Lui" }
local hash2 = { [1] = "Lua", [2] = "Lui" }
local hash3 = { ["lua"] = "Lua3", ["lui"] = "Lui3" }
local hash4 = {
lua = "Lua4",
lui = "Lui4",
luu = "Luu4",
}
print(hash["lui"])
print(hash2[1])
-- print(hash3["lua"])
-- print(hash4["luu"])
-- print(ary[5])
print(type(hash4))
loopTable(hash4)
string module
string.byte - Converts a character into its ASCII (decimal) equivalent
string.char - Converts ASCII codes into their equivalent characters
string.dump - Converts a function into binary
string.find - Searches a string for a pattern
string.format - Formats a string
string.gfind - Iterate over a string (obsolete in Lua 5.1)
string.gmatch - Iterate over a string
string.gsub - Substitute strings inside another string
string.len - Return the length of a string
string.lower - Converts a string to lower-case
string.match - Searches a string for a pattern
string.rep - Returns repeated copies of a string
string.reverse - Reverses the order of characters in a string
string.sub - Returns a substring of a string
string.upper - Converts a string to upper-case
04_string.lua
--[[
04_string.lua
--]]
-- -------------------------- local functions
convertTitle = function(str)
ret = ""
-- start = string.upper(string.char(string.byte(str, 1)))
start = string.sub(string.upper(str),1, 1)
temp = string.sub(string.lower(str),2, #str)
ret = start .. temp
return ret
end
-- --------------------------- Entry point
local title = convertTitle("memm-MeMoRu")
print(title)
print(string.char(string.byte("Lua")))
---
string = "Lua Tutorial Tutorial"
-- replacing strings
newstring = string.gsub(string,"Tutorial","Language")
print("The new string is "..newstring)
msg = string.format("%s, %s !!", "hello", "world")
print(msg)
d = 5; m = 1; y = 2021
date = string.format("%02d/%02d/%04d",d,m,y)
print(date)
str = [[
Hello, %s !!
Hello, %s !!!
]]
msg = string.format(str, "lua", "Neovim")
print(msg)
basic built-in function
assert -- Asserts that condition is not nil and not false
collectgarbage -- Collects garbage
dofile -- Executes a Lua file
error -- Raises an error message
gcinfo -- Returns amount of dynamic memory in use
getfenv -- Returns the current environment table
getmetatable -- Returns the metatable for the object
ipairs -- Iterates over a numerically keyed table
load -- Loads a chunk by calling a function repeatedly
loadfile -- Loads a Lua file and parses it
loadlib -- Loads a DLL (obsolete in Lua 5.1)
loadstring -- Compiles a string of Lua code
module -- Creates a Lua module
next -- Returns next key / value pair in a table
pairs -- Traverse all items in a table
pcall -- Calls a function in protected mode
print -- Prints its arguments
rawequal -- Compares two values for equality without invoking metamethods
rawget -- Gets the value of a table item without invoking metamethods
rawset -- Sets the value of a table item without invoking metamethods
require -- Loads a module
select -- Returns items in a list
setfenv -- Sets a function's environment
setmetatable -- Sets the metatable for a table
tonumber -- Converts a string (of the given base) to a number
tostring -- Converts its argument to a string
type -- Returns the type of a variable
unpack -- Unpacks a table into individual items
xpcall -- Calls a function with a custom error handler
installation