From e8514ac83e552fc5840b6db2723ce6dde9a12155 Mon Sep 17 00:00:00 2001 From: max397574 Date: Sun, 5 Dec 2021 20:32:08 +0100 Subject: feat(init): added user mappings and check if file exists --- lua/startup/init.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lua/startup/init.lua b/lua/startup/init.lua index 2ce7997..daffaa5 100644 --- a/lua/startup/init.lua +++ b/lua/startup/init.lua @@ -7,6 +7,7 @@ startup.sections = {} startup.section_highlights = {} startup.open_sections = {} startup.good_lines = {} +startup.user_mappings = {} startup.settings = require("startup.themes.dashboard") local get_cur_line = vim.api.nvim_get_current_line @@ -105,6 +106,13 @@ local function create_mappings(mappings) end end +function startup.create_mappings(mappings) + for lhs, rhs in pairs(mappings) do + buf_map(lhs,rhs) + startup.user_mappings[lhs]=rhs + end +end + ---ask for a filename and create file function startup.new_file() local name = vim.fn.input("Filename: > ") @@ -123,16 +131,25 @@ function startup.check_line() end end +local function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end +end + ---open file under cursor function startup.open_file() local filename = get_cur_line() - vim.cmd("e " .. filename) + if file_exists(vim.trim(filename)) then + vim.cmd("e " .. filename) + end end ---open file under cursor in split function startup.open_file_vsplit() local filename = get_cur_line() - vim.cmd("vsplit " .. filename) + if file_exists(vim.trim(filename)) then + vim.cmd("vsplit " .. filename) + end end ---creates a table with the strings in it aligned -- cgit v1.2.3