diff --git a/init.lua b/init.lua index 81d7ef1..35ac108 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,13 @@ if vim.g.vscode then - vim.cmd([[source C:\\Users\\Asep\\AppData\\Local\\nvim\\settings.vim]]) + Map = vim.keymap.set + Cmd = vim.cmd + VSCodeNotify = vim.fn.VSCodeNotify + VSCodeCall = vim.fn.VSCodeCall + + -- require("vscode.options") + require("vscode.functions") + require("vscode.mappings") +-- vim.cmd([[source C:\\Users\\Asep\\AppData\\Local\\nvim\\settings.vim]]) else require("core") end diff --git a/lua/vscode/functions.lua b/lua/vscode/functions.lua new file mode 100644 index 0000000..1475837 --- /dev/null +++ b/lua/vscode/functions.lua @@ -0,0 +1,244 @@ +function Center_screen() + Cmd("call 3_reveal('center', 0)") +end + +function Top_screen() + Cmd("call 3_reveal('top', 0)") +end + +function Bottom_screen() + Cmd("call 3_reveal('bottom', 0)") +end + +function Move_to_top_screen() + Cmd("call 3_moveCursor('top')") +end + +function Move_to_bottom_screen() + Cmd("call 3_moveCursor('bottom')") +end + +function Scroll_line_down() + VSCodeCall("scrollLineDown") +end + +function Scroll_line_up() + VSCodeCall("scrollLineUp") +end + +function Vscode_ctrl_d() + VSCodeNotify("vscode-neovim.ctrl-d") +end + +function Vscode_ctrl_u() + VSCodeNotify("vscode-neovim.ctrl-u") +end + +function Move_to_bottom_screen__center_screen() + Move_to_bottom_screen() + Center_screen() +end + +function Move_to_top_screen__center_screen() + Move_to_top_screen() + Center_screen() +end + +function Trim_trailing_whitespace() + VSCodeCall("editor.action.trimTrailingWhitespace") +end + +function Save() + VSCodeCall("workbench.action.files.save") +end + +function Save_no_format() + VSCodeCall("workbench.action.files.saveWithoutFormatting") +end + +function Trim__save__no_format() + Trim_trailing_whitespace() + Save_no_format() +end + +function Trim__save__no_highlight() + Trim_trailing_whitespace() + Save() + Remove_highlighting() +end + +function Format() + VSCodeCall("editor.action.formatDocument") + print("formatted!") +end + +function Trim__save__format() + Trim_trailing_whitespace() + Format() + Save() +end + +function Reveal_definition_aside() + VSCodeNotify("editor.action.revealDefinitionAside") +end + +function Go_to_implementation() + VSCodeNotify("editor.action.goToImplementation") +end + +function Go_to_reference() + VSCodeNotify("editor.action.goToReferences") +end + +function Rename_symbol() + VSCodeNotify("editor.action.rename") +end + +function Outdent() + ---@diagnostic disable-next-line: unused-local + for i = 1, vim.v.count1 do + VSCodeNotify("editor.action.outdentLines") + end +end + +function Indent() + ---@diagnostic disable-next-line: unused-local + for i = 1, vim.v.count1 do + VSCodeNotify("editor.action.indentLines") + end +end + +function Outdent_vis() + VSCodeNotify("editor.action.outdentLines", false) +end + +function Indent_vis() + VSCodeNotify("editor.action.indentLines", false) +end + +function Comment() + VSCodeNotify("editor.action.commentLine") +end + +function Convert_to_spaces() + VSCodeNotify("editor.action.indentationToSpaces") +end + +function Convert_to_tabs() + VSCodeNotify("editor.action.indentationToTabs") +end + +function Indent_with_spaces() + VSCodeNotify("editor.action.indentUsingSpaces") +end + +function Indent_with_tabs() + VSCodeNotify("editor.action.indentUsingTabs") +end + +function CloseEditor() + VSCodeNotify("workbench.action.closeActiveEditor") +end + +function UndoCloseEditor() + VSCodeNotify("workbench.action.reopenClosedEditor") +end + +function Git_stage_file() + Trim_trailing_whitespace() + Save() + VSCodeNotify("git.stage") +end + +function Git_unstage_file() + Save() + VSCodeNotify("git.unstage") +end + +function Git_revert_change() + VSCodeNotify("git.revertSelectedRanges") +end + +function Git_stage_change() + VSCodeNotify("git.stageSelectedRanges") +end + +function Git_unstage_change() + VSCodeNotify("git.unstageSelectedRanges") +end + +function Git_open_changes() + VSCodeNotify("git.openChange") +end + +function Git_open_all_changes() + VSCodeNotify("git.openAllChanges") +end + +function Accept_merge_both() + VSCodeNotify("merge-conflict.accept.both") +end + +function Accept_merge_all_both() + VSCodeNotify("merge-conflict.accept.all-both") +end + +function Accept_merge_current() + VSCodeNotify("merge-conflict.accept.current") +end + +function Accept_merge_all_current() + VSCodeNotify("merge-conflict.accept.all-current") +end + +function Accept_merge_incoming() + VSCodeNotify("merge-conflict.accept.incoming") +end + +function Accept_merge_all_incoming() + VSCodeNotify("merge-conflict.accept.all-incoming") +end + +function Accept_merge_selection() + VSCodeNotify("merge-conflict.accept.selection") +end + +function Codesnap() + VSCodeNotify("codesnap.start", true) +end + +function Comment_vis() + VSCodeNotify("editor.action.commentLine", false) +end + +function Toggle_breakpoint() + VSCodeNotify("editor.debug.action.toggleBreakpoint") +end + +function Copy_path() + VSCodeNotify("copyFilePath") +end + +function Copy_relative_path() + VSCodeNotify("copyRelativeFilePath") +end + +function Active_whichkey() + VSCodeNotify("whichkey.show") +end + +function Navigation_down() + VSCodeNotify("workbench.action.navigateDown") +end + +function Navigation_up() + VSCodeNotify("workbench.action.navigateUp") +end + +function Navigation_left() + VSCodeNotify("workbench.action.navigateLeft") +end + +function Navigation_right() + VSCodeNotify("workbench.action.navigateRight") +end diff --git a/lua/vscode/mappings.lua b/lua/vscode/mappings.lua new file mode 100644 index 0000000..a501714 --- /dev/null +++ b/lua/vscode/mappings.lua @@ -0,0 +1,48 @@ +-- n = normal mode +-- i = insert mode +-- v = visual mode +-- x = visual block mode +-- t = terminal mode +-- c = command mode +-- o = operator pending mode + +-- Map("", "L", Move_to_bottom_screen) +-- Map("", "H", Move_to_top_screen) +-- Map("", "", Trim__save__no_highlight) +Map({ "n", "x" }, "", Active_whichkey) +-- Map({ "n", "x" }, "", Navigation_down) +-- Map({ "n", "x" }, "", Navigation_up) +-- Map({ "n", "x" }, "", Navigation_left) +-- Map({ "n", "x" }, "", Navigation_right) +Map("", "U", Trim__save__format) + +Map("n", "gD", Reveal_definition_aside) +Map("n", "gt", Go_to_implementation) +Map("n", "gq", Go_to_reference) +Map("n", ",r", Rename_symbol) +Map("n", "<<", Outdent) +Map("n", ">>", Indent) +Map("n", "gcc", Comment) +Map("n", "=s", Convert_to_spaces) +Map("n", "=t", Convert_to_tabs) +Map("n", "=d", Indent_with_spaces) +Map("n", "=g", Indent_with_tabs) +Map("n", "K", CloseEditor) +Map("n", ",K", UndoCloseEditor) +Map("n", "zk", Git_stage_file) +Map("n", "zK", Git_unstage_file) +Map("n", "zi", Git_open_changes) +Map("n", "zI", Git_open_all_changes) +Map("n", "zy", Toggle_breakpoint) +Map("n", "yr", Copy_relative_path) +Map("n", "yR", Copy_path) + +Map("v", "gs", Codesnap) +Map("v", "<", Outdent_vis) +Map("v", ">", Indent_vis) +Map("v", "gc", Comment_vis) + +Map({ "n", "v" }, "zJ", Git_revert_change) +Map({ "n", "v" }, "zj", Git_stage_change) +-- Map({ "n", "v" }, "zt", Vscode_ctrl_d) +-- Map({ "n", "v" }, "zb", Vscode_ctrl_u) diff --git a/lua/vscode/options.lua b/lua/vscode/options.lua new file mode 100644 index 0000000..2587920 --- /dev/null +++ b/lua/vscode/options.lua @@ -0,0 +1,23 @@ +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = false +vim.opt.smartindent = true +vim.opt.mouse = "a" +vim.opt.ignorecase = false +vim.opt.smartcase = true +vim.opt.hlsearch = true +vim.opt.colorcolumn = "" +vim.opt.syntax = "enable" +vim.opt.termguicolors = true +vim.opt.background = "dark" +vim.opt.backup = false +vim.opt.writebackup = false +vim.opt.swapfile = false +vim.opt.undofile = true +vim.opt.timeout = false +vim.g.mapleader = "," +vim.g.rust_recommended_style = true +vim.g.targets_nl = "nh" +vim.o.cpoptions = "aABceFs"