-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.lua
65 lines (56 loc) · 2.02 KB
/
hello.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local content = vim.g.content
for line in content:gmatch("[^\r\n]+") do
local status, filePath = line:match("^.(.).(.*)")
print(string.format("status: %s, filePath: %s", status, filePath))
end
local s = "world world from Lua"
for w in string.gmatch(s, "%a+") do
print(w)
end
local t = {}
s = "from=world, to=Lua"
for k, v in string.gmatch(s, "(%w+)=(%w+)") do
t[k] = v
end
print(t.from, t.to)
local function find_git_root()
local current_file = vim.api.nvim_buf_get_name(0)
for dir in vim.fs.parents(current_file) do
if vim.fn.isdirectory(dir .. "/.git") == 1 then
return dir
end
end
return nil
end
local root_dir = find_git_root()
if root_dir then
print("Found git repository at", root_dir)
end
-- Hey you can use pylance with lspconfig with some little trick.
-- ```cd ~/.vscode/extensions/ms-python.vscode-pylance-*/dist &&awk 'BEGIN{RS=ORS=";"} /if\(!process/ && !found {sub(/return!0x1/, "return!0x0"); found=1} 1' server.bundle.js |awk 'BEGIN{RS=ORS=";"} /throw new/ && !found {sub(/throw new/, ""); found=1} 1' > server_nvim.js```
-- Then create folder in your `~/.config/nvim` as my repo https://github.com/nullchilly/vscode-lsp.nvim You can now call `require'lspconfig'.pylance.setup {}`
local M = {}
M.file_path = vim.fn.stdpath("config") .. "/hello1.lua"
function M.replace_word(old, new)
local file, err = io.open(M.file_path, "r")
if not file then
file, _ = io.open(M.file_path, "w")
file, err = io.write(file, "Hello World")
file:close()
vim.notify(err .. ", so new file has been created", vim.log.levels.ERROR)
end
local content = file:read("*all")
file:close()
-- local added_pattern = string.gsub(old, "-", "%%-") -- add % before - if exists
local new_content = content:gsub(old, new)
file, err = io.open(M.file_path, "w")
if not file then
vim.notify("Failed to open file for writing: " .. err, vim.log.levels.ERROR)
return
end
file:write(new_content)
file:close()
end
M.replace_word("world", "yay")
require("utils").custome_notfiy("hellllllllo", 1)
return M