This repository has no description
2.4 kB
60 lines
1function open_or_create_file(tfilename)
2 -- complete filepath from the file where this is called
3 local parent = vim.fn.expand('%:p:h')
4 local newfilepath = parent .. '/' .. vim.fn.expand(tfilename)
5
6 if vim.fn.filereadable(newfilepath) ~= 1 then
7 -- create parent directory
8 vim.fn.system('mkdir -p ' .. vim.fn.shellescape(parent))
9 vim.fn.system('touch ' .. vim.fn.shellescape(newfilepath))
10 end
11 vim.cmd(':e ' .. newfilepath)
12end
13
14
15-- Mapping data with "desc" stored directly by vim.keymap.set().
16--
17-- Please use this mappings table to set keyboard mapping since this is the
18-- lower level configuration and more robust one. (which-key will
19-- automatically pick-up stored data by this setting.)
20return {
21 -- first key is the mode
22 n = {
23 -- second key is the lefthand side of the map
24
25 -- navigate buffer tabs with `H` and `L`
26 -- L = {
27 -- function() require("astronvim.utils.buffer").nav(vim.v.count > 0 and vim.v.count or 1) end,
28 -- desc = "Next buffer",
29 -- },
30 -- H = {
31 -- function() require("astronvim.utils.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1)) end,
32 -- desc = "Previous buffer",
33 -- },
34 -- mappings seen under group name "Buffer"
35 ["<leader>bD"] = {
36 function()
37 require("astronvim.utils.status").heirline.buffer_picker(function(bufnr) require("astronvim.utils.buffer").close(bufnr) end)
38 end,
39 desc = "Pick to close",
40 },
41 -- tables with the `name` key will be registered with which-key if it's installed
42 -- this is useful for naming menus
43 ["<leader>b"] = { name = "Buffers" },
44 -- quick save
45 -- ["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command
46
47 -- Don't error if file doesn't exist
48 ["gf"] = { function() open_or_create_file(vim.fn.expand("<cfile>")) end, desc = "Create file" },
49 ["<leader>*"] = { function() require("telescope.builtin").grep_string() end, desc = "Find for word under cursor", },
50 ["<leader><leader>"] = { function() require("telescope.builtin").find_files() end, desc = "Find files" },
51 },
52 t = {
53 -- setting a mapping to false will disable it
54 -- ["<esc>"] = false,
55 },
56 c = {
57 -- setting a mapping to false will disable it
58 ["w!!"] = { "w !sudo tee > /dev/null %", desc = "Write as sudo" },
59 }
60}