diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2024-02-22 13:42:19 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2024-02-22 13:42:19 +0300 |
commit | e72256be161a60a0671b2ed2868f4d3e99559645 (patch) | |
tree | 4010dd2d0e76288147b024f25a305b8fd3ca60e9 | |
parent | e23f36ec3fc9f026be73550b66a6a7a8b66aafb1 (diff) |
added coderunner and toggleterm functionality to nvim
for fuck's sake JUST LOOK AT VARIABLE `local script` IN
`.config/nvim/lua/user/coderunner.lua`
That shit's RIDICULOUS
-rw-r--r-- | .config/nvim/init.lua | 2 | ||||
-rw-r--r-- | .config/nvim/lua/user/\ | 13 | ||||
-rw-r--r-- | .config/nvim/lua/user/coderunner.lua | 20 | ||||
-rw-r--r-- | .config/nvim/lua/user/plugins.lua | 9 | ||||
-rw-r--r-- | .config/nvim/lua/user/remaps.lua | 11 | ||||
-rw-r--r-- | .config/nvim/lua/user/toggleterm.lua | 92 |
6 files changed, 131 insertions, 16 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 67190b4..76b4b98 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,7 +2,9 @@ require "user.beautiful" require "user.options" require "user.plugins" require "user.remaps" +require "user.toggleterm" require "user.lspinit" require "user.treesitter" +require "user.coderunner" -- autocmd to load lsp seems to break it diff --git a/.config/nvim/lua/user/\ b/.config/nvim/lua/user/\ deleted file mode 100644 index 2baf779..0000000 --- a/.config/nvim/lua/user/\ +++ /dev/null @@ -1,13 +0,0 @@ -lsp = require 'lspconfig' - -lsp.clangd.setup { - cmd = {"clangd", "--background-index", "--suggest-missing-includes", "--clang-tidy"}, - filetypes = {"c", "cpp", "cxx", "h", "hpp", "hxx", "inc", "objc", "objcpp"}, - root_dir = lspconfig.utill.root_pattern("CMakeLists.txt", "Makefile", "qmake.pro", ".git"), - init_options = { - clangdFileStatus = true, - usePlaceholders = true, - completeUnimported = true, - semanticHighlighting = true, - }, -} diff --git a/.config/nvim/lua/user/coderunner.lua b/.config/nvim/lua/user/coderunner.lua new file mode 100644 index 0000000..3049893 --- /dev/null +++ b/.config/nvim/lua/user/coderunner.lua @@ -0,0 +1,20 @@ +local term = require'toggleterm' + +-- Define the code runner configuration +require('code_runner').setup({ + mode = "toggleterm", + focus = true, + startinsert = true, + filetype = { + rust = 'cargo check; if [ \\$? -ne 0 ]; then echo cargo check failed; else cargo run; if [ \\$? -ne 0 ]; then cargo test --test-threads=1; sleep 1; fi; fi; echo $file > /dev/null', + cpp = function() + local script = + 'echo $file > /dev/null;' .. + 'while [[ ! -f CMakeLists.txt && \\\"\\$PWD\\\" != / ]]; do cd ..; done;' .. + 'if [[ -f CMakeLists.txt ]]; then mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && make -j24 && ' .. + './\\$(sed -nr \\\"/add_executable/s/.*add_executable\\\\((\\\\S+).+/\\\\1/p\\\" ../CMakeLists.txt); fi;' .. + 'cd ..' + vim.cmd(string.format("TermExec cmd='%s'", script)) + end, + }, +}) diff --git a/.config/nvim/lua/user/plugins.lua b/.config/nvim/lua/user/plugins.lua index da0d366..94b1035 100644 --- a/.config/nvim/lua/user/plugins.lua +++ b/.config/nvim/lua/user/plugins.lua @@ -53,6 +53,14 @@ plugins = { event = { "InsertEnter" }, }, + { + "CRAG666/code_runner.nvim", + config = true, + }, + { + "akinsho/toggleterm.nvim", + config = true, + }, -- Autocompletion framework { @@ -127,4 +135,3 @@ lazy.setup(plugins, opts) -- miscellanous plugin setup require('bufferline').setup{} - diff --git a/.config/nvim/lua/user/remaps.lua b/.config/nvim/lua/user/remaps.lua index 6400957..ad1e2eb 100644 --- a/.config/nvim/lua/user/remaps.lua +++ b/.config/nvim/lua/user/remaps.lua @@ -68,9 +68,12 @@ map("n", "<C-A-Down>", ":.,.t.<CR>==", opt) -- leader remaps map("n", "<leader>/", ":nohlsearch<CR>", opt) -- discard search highlighting -map("n", "<leader>t", ":split<CR>:terminal<CR>:resize 4<CR>", opt) -- open terminal fullscreen with \T -map("n", "<leader>T", ":vsplit<CR>:terminal<CR>", opt) -- split to terminal with \t map("n", "<leader>pl", ":Lazy<CR>", opt) -- open plugin manager +-- Old mappings for the terminal +-- map("n", "<leader>t", ":split<CR>:terminal<CR>:resize 4<CR>", opt) -- open terminal fullscreen with \T +-- map("n", "<leader>T", ":vsplit<CR>:terminal<CR>", opt) -- split to terminal with \t +map("", "<leader>t", ":ToggleTerm<CR>", opt) -- open ToggleTerm +map("t", "<leader>t", ":ToggleTerm<CR>", opt) -- close ToggleTerm -- miscellaneous map("c", "w!!", "w !sudo tee % > /dev/null", opt) @@ -91,6 +94,10 @@ lmap("n", "<leader>d", vim.diagnostic.open_float) lmap("n", "d[", vim.diagnostic.goto_prev) lmap("n", "d]", vim.diagnostic.goto_next) +-- Code Runner remaps +map("n", "<F5>", ":RunCode<CR>", opt) +map("n", "<F2>", ":echo 'time: ' . strftime('%c')<CR>", opt) + -- language server remaps -- enable only after attaching language server to buffer vim.api.nvim_create_autocmd('LspAttach', { diff --git a/.config/nvim/lua/user/toggleterm.lua b/.config/nvim/lua/user/toggleterm.lua new file mode 100644 index 0000000..567c12f --- /dev/null +++ b/.config/nvim/lua/user/toggleterm.lua @@ -0,0 +1,92 @@ +require("toggleterm").setup { + autochdir = true, + shade_terminals = true, + shading_factor = -100, + start_in_insert = true, + insert_mappings = true, + terminal_mappings = true, + persist_size = true, + persist_mode = false, + direction = 'float', + close_on_exit = true, + auto_scroll = true, + float_opts = { + border = 'single', + title_pos = 'left' + }, + winbar = { + enabled = true, + }, +} + +-- from documentation: +-- +--[[ +require("toggleterm").setup{ + -- size can be a number or function which is passed the current terminal + size = 20 | function(term) + if term.direction == "horizontal" then + return 15 + elseif term.direction == "vertical" then + return vim.o.columns * 0.4 + end + end, + on_create = fun(t: Terminal), -- function to run when the terminal is first created + on_open = fun(t: Terminal), -- function to run when the terminal opens + on_close = fun(t: Terminal), -- function to run when the terminal closes + on_stdout = fun(t: Terminal, job: number, data: string[], name: string) -- callback for processing output on stdout + on_stderr = fun(t: Terminal, job: number, data: string[], name: string) -- callback for processing output on stderr + on_exit = fun(t: Terminal, job: number, exit_code: number, name: string) -- function to run when terminal process exits + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + autochdir = false, -- when neovim changes it current directory the terminal will change it's own when next it's opened + highlights = { + -- highlights which map to a highlight group name and a table of it's values + -- NOTE: this is only a subset of values, any group placed here will be set for the terminal window split + Normal = { + guibg = "<VALUE-HERE>", + }, + NormalFloat = { + link = 'Normal' + }, + FloatBorder = { + guifg = "<VALUE-HERE>", + guibg = "<VALUE-HERE>", + }, + }, + shade_terminals = true, -- NOTE: this option takes priority over highlights specified so if you specify Normal highlights you should set this to false + shading_factor = '<number>', -- the percentage by which to lighten terminal background, default: -30 (gets multiplied by -3 if background is light) + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + terminal_mappings = true, -- whether or not the open mapping applies in the opened terminals + persist_size = true, + persist_mode = true, -- if set to true (default) the previous terminal mode will be remembered + direction = 'vertical' | 'horizontal' | 'tab' | 'float', + close_on_exit = true, -- close the terminal window when the process exits + -- Change the default shell. Can be a string or a function returning a string + shell = vim.o.shell, + auto_scroll = true, -- automatically scroll to the bottom on terminal output + -- This field is only relevant if direction is set to 'float' + float_opts = { + -- The border key is *almost* the same as 'nvim_open_win' + -- see :h nvim_open_win for details on borders however + -- the 'curved' border is a custom border type + -- not natively supported but implemented in this plugin. + border = 'single' | 'double' | 'shadow' | 'curved' | ... other options supported by win open + -- like `size`, width, height, row, and col can be a number or function which is passed the current terminal + width = <value>, + height = <value>, + row = <value>, + col = <value>, + winblend = 3, + zindex = <value>, + title_pos = 'left' | 'center' | 'right', position of the title of the floating window + }, + winbar = { + enabled = false, + name_formatter = function(term) -- term: Terminal + return term.name + end + }, +} +]]-- |