vim.opt["background"] = "light"
vim.g.VM_theme = "marked"
--- vim.g.rainbow_delimiters = { fill = { fill = false } }
--- vim.g.rainbow_delimiters = { fill = true }
-local rain = require 'rainbow-delimiters'
-vim.g.rainbow_delimiters = {
- priority = {
- [''] = 10,
- },
- query = {
- lua = "rainbow-blocks",
- },
-}
-
--- local use_rainbow = true
-
--- TODO:
--- Add todo colors to comments
--- Add Rainbow bracket colouring with full background
--- Complete scm files for syntactic highlighting
-
-
local p = {
black = "#000000",
-- markdownError = colors.default,
}
-local disable = {
- -- Enable
- String = colors.default,
- Constant = colors.default,
- Character = colors.default,
- Number = colors.default,
- Boolean = colors.default,
- Float = colors.default,
- TypeDef = colors.default,
-
- ["@string.escape"] = colors.default,
- ["@tag"] = colors.default,
- ["@tag.attribute"] = colors.default,
-
- -- Disable
- ["@branch"] = colors.default,
- ["@loop"] = colors.default,
- ["@goto"] = colors.default,
- ["@constant"] = colors.default,
- ["@type.builtin"] = colors.default,
- ["@type.created"] = colors.default,
- -- ["@module"] = colors.default,
-}
local default = {
-- Enable
["@tag.attribute"] = colors.nums,
["@type.builtin"] = colors.type,
["@type.created"] = colors.type,
- -- ["@module"] = colors.type,
["@constant"] = colors.const,
- ["@keyword.let"] = colors.type,
+ ["@declare"] = colors.type,
-- Disable
- ["@branch"] = colors.default,
+ ["@conditional"] = colors.default,
["@loop"] = colors.default,
["@goto"] = colors.default,
}
local control_flow = {
-- Enable
- ["@branch"] = colors.branch,
+ ["@conditional"] = colors.branch,
["@loop"] = colors.loop,
["@goto"] = colors.goto_,
Float = colors.default,
TypeDef = colors.default,
+ ["@declare"] = colors.default,
["@string.escape"] = colors.default,
["@tag"] = colors.default,
["@tag.attribute"] = colors.default,
["@constant"] = colors.default,
["@type.builtin"] = colors.default,
["@type.created"] = colors.default,
- -- ["@module"] = colors.default,
}
-- - `RainbowDelimiterRed`
require('lualine').setup { options = { theme = modes } }
local set_default = function()
- rain.disable(0)
for c_name, color in pairs(default) do
vim.api.nvim_set_hl(0, c_name, color)
end
- -- use_rainbow = false
end
-
+--
local set_control_flow = function()
- rain.disable(0)
for c_name, color in pairs(control_flow) do
vim.api.nvim_set_hl(0, c_name, color)
end
- -- use_rainbow = false
-end
-local set_brackets = function()
- -- use_rainbow = true
- rain.enable(0)
- for c_name, color in pairs(marked) do
- vim.api.nvim_set_hl(0, c_name, color)
- end
- for c_name, color in pairs(disable) do
- vim.api.nvim_set_hl(0, c_name, color)
- end
end
vim.keymap.set("n", "<F1>", set_default, {})
vim.keymap.set("n", "<F2>", set_control_flow, {})
-vim.keymap.set("n", "<F3>", set_brackets, {})
-vim.api.nvim_create_autocmd("BufNew", {
- callback = function(opts)
- rain.disable(opts.buf)
- end
-})
-vim.api.nvim_create_autocmd("BufEnter", {
- callback = function(opts)
- rain.disable(opts.buf)
- end
-})
-vim.api.nvim_create_autocmd("BufAdd", {
- callback = function(opts)
- rain.disable(opts.buf)
- end
-})
+-- vim.api.nvim_create_autocmd("BufNew", {
+-- callback = function(opts)
+-- rain.disable(opts.buf)
+-- end
+-- })
+-- vim.api.nvim_create_autocmd("BufEnter", {
+-- callback = function(opts)
+-- rain.disable(opts.buf)
+-- end
+-- })
+-- vim.api.nvim_create_autocmd("BufAdd", {
+-- callback = function(opts)
+-- rain.disable(opts.buf)
+-- end
+-- })
--- /dev/null
+vim.opt["background"] = "light"
+vim.g.VM_theme = "marked2"
+
+
+local p = {
+ black = "#000000",
+ white = "#ffffff",
+
+ background = "#ffffea",
+ float_background = "#eeeeda",
+ secondary_background = "#aeeeee",
+ selection = "#eeee9e",
+
+ comments = "#dddddd",
+
+ green = "#c0f0b0",
+ blue = "#b0c0f0",
+ red = "#f0c0b0",
+
+ -- Only use for special cases
+ magenta = "#f0f0b0",
+ yellow = "#f0b0f0",
+ cyan = "#b0f0f0",
+ gray = "#d0d0d0",
+
+ errors = "#a0342f",
+ warnings = "#f0ad4e",
+ hints = "#777777",
+ infos = "#3060a0",
+
+ diff_remove = "#a0342f",
+ diff_change = "#f0ad4e",
+ diff_add = "#30a060",
+
+}
+
+local colors = {
+ default = { fg = p.black, },
+
+ bgSecondary = { bg = p.secondary_background, },
+ selected = { fg = p.black, bg = p.selection, },
+
+ buffBG = { bg = p.secondary_background, },
+ buffSelected = { fg = p.secondary_background, },
+
+ diffAdd = { fg = p.white, bg = p.diff_add, },
+ diffChange = { fg = p.black, bg = p.diff_change, },
+ diffRemove = { fg = p.white, bg = p.diff_remove, },
+
+ errorMsg = { fg = p.errors, bg = p.white, bold = true, },
+ warnMsg = { fg = p.warnings, bg = p.white, bold = true, },
+ hintMsg = { fg = p.hints, bg = p.white, bold = true, },
+ infoMsg = { fg = p.infos, bg = p.white, bold = true, },
+
+ comment = { fg = p.black, bg = p.comments, },
+ nums = { fg = p.black, bg = p.blue, },
+ bool = { fg = p.black, bg = p.blue, },
+ char = { fg = p.black, bg = p.blue, },
+ const = { fg = p.black, },
+ string = { fg = p.black, bg = p.green, },
+ operator = { fg = p.black, },
+ keyword = { fg = p.black, },
+ identifier = { fg = p.black, },
+ func = { fg = p.black, },
+ include = { fg = p.black, },
+ type = { fg = p.black, bg = p.red , bold = false },
+
+ error = { fg = p.white, bg = p.errors, bold = true, },
+ warn = { fg = p.black, bg = p.warnings, bold = true, },
+ hint = { fg = p.white, bg = p.hints, bold = true, },
+ info = { fg = p.white, bg = p.infos, bold = true, },
+
+ uri = { underline = true, },
+ tag = { fg = p.black, bg = p.red, },
+
+
+ -- Control Flow
+ branch = { fg = p.black, bg = p.green, },
+ loop = { fg = p.black, bg = p.red, },
+ goto_ = { fg = p.black, bg = p.blue, },
+
+ -- Brackets
+ b_green = { fg = p.black, bg = p.green, },
+ b_red = { fg = p.black, bg = p.red, },
+ b_blue = { fg = p.black, bg = p.blue, },
+ b_magenta = { fg = p.black, bg = p.magenta, },
+ b_yellow = { fg = p.black, bg = p.yellow, },
+ b_cyan = { fg = p.black, bg = p.cyan, },
+ b_gray = { fg = p.black, bg = p.gray, },
+}
+
+local marked = {
+ -- Unchanged
+ Normal = { fg = p.black, bg = p.background },
+ NormalFloat = { fg = p.black, bg = p.float_background },
+ CursorColumn = colors.bgSecondary,
+ CursorLine = colors.bgSecondary,
+
+ Comment = colors.comment,
+
+ DiffAdd = colors.diffAdd,
+ DiffChange = colors.diffChange,
+ DiffDelete = colors.diffRemove,
+
+ ErrorMsg = colors.errorMsg,
+ VertSplit = colors.default,
+
+ Search = colors.selected,
+ IncSearch = colors.selected,
+
+ MatchParen = colors.selected,
+
+ NonText = { fg = "#2080a0" },
+
+ -- Popup Menu
+ Pmenu = { link = "NormalFloat" },
+ PmenuSel = colors.selected,
+ PmenuThumb = colors.bgSecondary,
+
+ Visual = colors.selected,
+ VisualNOS = colors.selected,
+
+ WinSeparator = colors.bgSecondary,
+
+
+ -- Diff
+ diffAdded = colors.diffAdd,
+ diffRemoved = colors.diffRemove,
+ diffNewFile = colors.diffAdd,
+ diffOldFile = colors.diffRemove,
+ gitcommitSelectedType = colors.diffChange,
+ gitcommitFile = colors.string,
+ gitcommitBranch = colors.string,
+ gitcommitHeader = colors.comment,
+ diffIndexLine = colors.nums,
+
+ -- Git Signs
+ GitSignsAdd = colors.diffAdd,
+ GitSignsChange = colors.diffChange,
+ GitSignsDelete = colors.diffRemove,
+ GitSignsCurrentLineBlame = colors.comment,
+
+ -- LSP
+ DiagnosticError = colors.errorMsg,
+ DiagnosticWarn = colors.warnMsg,
+ DiagnosticHint = colors.hintMsg,
+ DiagnosticInfo = colors.infoMsg,
+ DiagnosticSignError = colors.error,
+ DiagnosticSignWarn = colors.warn,
+ DiagnosticSignHint = colors.hint,
+ DiagnosticSignInfo = colors.info,
+ DiagnosticUnderlineError = colors.error,
+ DiagnosticUnderlineWarn = colors.warn,
+ DiagnosticUnderlineHint = colors.hint,
+ DiagnosticUnderlineInfo = colors.info,
+
+ -- Leap
+ LeapLabelPrimary = colors.info,
+
+ -- Nvim Tree
+ NvimTreeWinSeparator = colors.bgSecondary,
+ NvimTreeRootFolder = colors.default,
+ NvimTreeFolderName = colors.nums,
+ NvimTreeExecFile = colors.string,
+ NvimTreeSpecialFile = colors.string,
+ NvimTreeSymlink = colors.uri,
+ NvimTreeGitNew = colors.diffAdd,
+ nvimTreeGitDirty = colors.diffChange,
+ NvimTreeGitDeleted = colors.diffRemove,
+ NvimTreeGitRenamed = colors.diffChange,
+
+
+ -- Removed
+ Operator = colors.default,
+ Keyword = colors.default,
+ Keywords = colors.default,
+ Identifier = colors.default,
+ Function = colors.default,
+ Statement = colors.default,
+ Conditional = colors.default,
+ Repeat = colors.default,
+ Label = colors.default,
+ Exception = colors.default,
+ PreProc = colors.default,
+ Include = colors.default,
+ Define = colors.default,
+ Title = colors.default,
+ Macro = colors.default,
+ PreCondit = colors.default,
+ StorageClass = colors.default,
+ Structure = colors.default,
+ Special = colors.default,
+ SpecialComment = colors.default,
+
+ SignColumn = colors.default,
+ Conceal = colors.default,
+ CursorLineNr = colors.default,
+ ColorColumn = colors.default,
+ StatusLine = colors.default,
+ StatusLineNC = colors.default,
+ StatusLineTerm = colors.default,
+ StatusLineTermNC = colors.default,
+ Directory = colors.default,
+ MoreMsg = colors.default,
+ ModeMsg = colors.default,
+
+ LineNr = colors.default,
+
+ ["@text.uri"] = colors.uri,
+
+ Type = colors.default,
+}
+
+
+local default = {
+ -- Enable
+ String = colors.string,
+ Constant = colors.const,
+ Character = colors.char,
+ Number = colors.nums,
+ Boolean = colors.bool,
+ Float = colors.nums,
+ -- TypeDef = colors.type,
+
+ -- ["@type.builtin"] = colors.type,
+ -- ["@type.created"] = colors.type,
+ ["@string.escape"] = colors.nums,
+ ["@tag"] = colors.tag,
+ ["@tag.attribute"] = colors.nums,
+}
+
+
+
+
+for c_name, color in pairs(marked) do
+ vim.api.nvim_set_hl(0, c_name, color)
+end
+for c_name, color in pairs(default) do
+ vim.api.nvim_set_hl(0, c_name, color)
+end
+
+local modes = {
+ normal = {
+ a = colors.bgSecondary,
+ b = colors.bgSecondary,
+ c = colors.bgSecondary,
+ },
+}
+require('lualine').setup { options = { theme = modes } }
})
end
vim.opt.rtp:prepend(lazypath)
-
require("plugins")
git_ignored = true,
}
})
+require("treesitter")
require("telescope").load_extension("frecency")
-vim.cmd [[colorscheme marked]]
+vim.cmd [[colorscheme marked2]]
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp-vsnip": { "branch": "main", "commit": "989a8a73c44e926199bfd05fa7a516d51f2d2752" },
"dashboard-nvim": { "branch": "master", "commit": "fabf5feec96185817c732d47d363f34034212685" },
- "gitsigns.nvim": { "branch": "main", "commit": "f4928ba14eb6c667786ac7d69927f6aee6719f1e" },
- "lazy.nvim": { "branch": "main", "commit": "5473e3d77c13e40fc4758fa977a1f2c14d0b4ceb" },
- "leap-ast.nvim": { "branch": "main", "commit": "1a21b70505ebb868a1e196c0d63797e1426b53a5" },
- "leap.nvim": { "branch": "main", "commit": "c099aecaf858574909bd38cbadb8543c4dd16611" },
- "lualine.nvim": { "branch": "master", "commit": "544dd1583f9bb27b393f598475c89809c4d5e86b" },
- "mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" },
+ "gitsigns.nvim": { "branch": "main", "commit": "1ef74b546732f185d0f806860fa5404df7614f28" },
+ "lazy.nvim": { "branch": "main", "commit": "48b52b5cfcf8f88ed0aff8fde573a5cc20b1306d" },
+ "leap.nvim": { "branch": "main", "commit": "c6bfb191f1161fbabace1f36f578a20ac6c7642c" },
+ "lualine.nvim": { "branch": "master", "commit": "b431d228b7bbcdaea818bdc3e25b8cdbe861f056" },
+ "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
"mason-null-ls.nvim": { "branch": "main", "commit": "de19726de7260c68d94691afb057fa73d3cc53e7" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
- "none-ls.nvim": { "branch": "main", "commit": "8b5d4170a602d7b257704eef77b0539ddfd02589" },
- "nvim-autopairs": { "branch": "master", "commit": "78a4507bb9ffc9b00f11ae0ac48243d00cb9194d" },
- "nvim-cmp": { "branch": "main", "commit": "d818fd0624205b34e14888358037fb6f5dc51234" },
- "nvim-lspconfig": { "branch": "master", "commit": "01e08d4bf1c35e5126b2ad5209725e4c552289ab" },
+ "none-ls.nvim": { "branch": "main", "commit": "9b98991e15dce8fc502993e23caac2528b8b667f" },
+ "nvim-autopairs": { "branch": "master", "commit": "ffc139f2a96640ca6c4d3dff9b95b7b9eace87ae" },
+ "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
+ "nvim-lspconfig": { "branch": "master", "commit": "46ce5fd8c081f179a509da423077f8372e63ffc4" },
"nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" },
- "nvim-tree.lua": { "branch": "master", "commit": "f9ff00bc06d7cb70548a3847d7a2a05e928bc988" },
- "nvim-treesitter": { "branch": "master", "commit": "0758155d4dfacfa959ad82ffa3879cb69c82e719" },
- "nvim-treesitter-context": { "branch": "master", "commit": "2aba92ceb1479485953007f4d5adf34d0b66917e" },
- "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
- "nvim-ts-autotag": { "branch": "main", "commit": "1624866a1379fc1861797f0ed05899a9c1d2ff61" },
- "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" },
- "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" },
- "rainbow-delimiters.nvim": { "branch": "master", "commit": "b29da4a6061a88270e875b38367d82c04c856128" },
- "rustaceanvim": { "branch": "master", "commit": "047f9c9d8cd2861745eb9de6c1570ee0875aa795" },
- "syntax-tree-surfer": { "branch": "master", "commit": "732ea6d0f868bcccd2f526be73afa46997d5a2fb" },
- "telescope-frecency.nvim": { "branch": "master", "commit": "bb2c63ee5375ede81c1945b58638412af42b2d62" },
- "telescope.nvim": { "branch": "master", "commit": "bfcc7d5c6f12209139f175e6123a7b7de6d9c18a" },
- "toggleterm.nvim": { "branch": "main", "commit": "8ed0f52006d3207ec6c94de7db62da840937ef2a" },
+ "nvim-tree.lua": { "branch": "master", "commit": "45a93d99794fff3064141d5b3a50db98ce352697" },
+ "nvim-treesitter": { "branch": "master", "commit": "b7160e87aadbb3f5f6ee87ce139406fe3433044e" },
+ "nvim-treesitter-textobjects": { "branch": "master", "commit": "bf8d2ad35d1d1a687eae6c065c3d524f7ab61b23" },
+ "nvim-ts-autotag": { "branch": "main", "commit": "e239a560f338be31337e7abc3ee42515daf23f5e" },
+ "nvim-web-devicons": { "branch": "master", "commit": "9154484705968658e9aab2b894d1b2a64bf9f83d" },
+ "plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" },
+ "rustaceanvim": { "branch": "master", "commit": "5610d5e01dc803717cc0b6b87625f2fbb548b49e" },
+ "telescope-frecency.nvim": { "branch": "master", "commit": "f67baca08423a6fd00167801a54db38e0b878063" },
+ "telescope.nvim": { "branch": "master", "commit": "927c10f748e49c543b2d544c321a1245302ff324" },
+ "toggleterm.nvim": { "branch": "main", "commit": "137d06fb103952a0fb567882bb8527e2f92d327d" },
"undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" },
"vim-bufsurf": { "branch": "master", "commit": "e6dbc7ad66c7e436e5eb20d304464e378bd7f28c" },
- "vim-visual-multi": { "branch": "master", "commit": "38b0e8d94a5499ccc17d6159763d32c79f53417b" },
+ "vim-visual-multi": { "branch": "master", "commit": "a6975e7c1ee157615bbc80fc25e4392f71c344d4" },
"vim-vsnip": { "branch": "master", "commit": "02a8e79295c9733434aab4e0e2b8c4b7cea9f3a9" },
- "which-key.nvim": { "branch": "main", "commit": "e8b454fb03e3cab398c894e5d462c84595ee57ca" }
+ "which-key.nvim": { "branch": "main", "commit": "bfec3d6bc0a9b0b2cb11644642f78c2c3915eef0" }
}
vim.keymap.set("t", shortcut, command, opts)
end
-local telescope = require("telescope.builtin")
+local gs = require("gitsigns")
+
+-- Verbs
+LEADER = "<leader>"
+SEARCH = "s"
+VIEW = "v"
+TOGGLE = "t"
+GOTO = "g"
+RENAME = "r"
+FORMAT = "f"
+CODE_ACTION = "a"
+MOVE = "m"
+
+-- Adverbs
+NEXT = "n"
+PREV = "p"
+INNER = "i"
+OUTER = "a"
+LHS = "h"
+RHS = "l"
+
+-- Nouns
+DECL = "D"
+DEF = "d"
+IMPL = "i"
+ERROR = "e"
+SYMBOL = "s"
+FUNC = "f"
+LOOP = "l"
+CALL = "c"
+ASSIGN = "q"
+COND = "m"
+PARAM = "p"
+VAR = "v"
+CLASS = "t"
+REF = "r"
+MAN_PAGES = "M"
+ALL = "a"
+BUF = "b"
+UNDO = "u"
+EXPLORER = "x"
+INSPECTOR = "I"
+
+-- Namespaces
+GIT = "g"
+
+DIFF = "d"
+HUNK = "h"
+STAGE = "s"
+RESET = "r"
+COMMITS = "c"
+BLAME = "b"
+DELETED = "d"
+BRANCHES = "b"
+
+
+-- local telescope = require("telescope.builtin")
-- Map Leader
-vim.g.mapleader = "\\"
-vim.g.maplocalleader = "\\"
+nnoremap(" ", "<Nop>")
+vim.g.mapleader = " "
+vim.g.maplocalleader = " "
+
+
+-- Helper
+nnoremap("yi_", "T_yt_")
+nnoremap("ya_", "F_yf_")
+nnoremap("di_", "T_dt_")
+nnoremap("da_", "F_df_")
+nnoremap("ci_", "T_ct_")
+nnoremap("ca_", "F_cf_")
+
+-- Move text up and down
+xnoremap("J", ":move '>+1<CR>gv-gv")
+xnoremap("K", ":move '<-2<CR>gv-gv")
+-- nnoremap("<leader>x", ":%!xxd<CR>")
+-- nnoremap("<leader>X", ":%!xxd -r<CR>")
+
+
+-- Multikey
+nnoremap("<C-c>", ":<C-u>call vm#commands#add_cursor_down(0, v:count1)<CR>")
+nnoremap("<M-c>", ":<C-u>call vm#commands#add_cursor_up(0, v:count1)<CR>")
+
+
+-- Switch between C code and Header
+local function swap_c()
+ if (vim.fn.expand('%:t'):match("^.+(%..+)$") == ".c") then
+ vim.cmd.e("%<.h")
+ elseif (vim.fn.expand('%:t'):match("^.+(%..+)$") == ".h") then
+ vim.cmd.e("%<.c")
+ end
+end
+nnoremap("<M-q>", swap_c)
--- Normal Y behaviour
-nnoremap("Y", "y$")
-- Window navigation
nnoremap("<C-h>", "<C-w>h")
nnoremap("<C-k>", "<C-w>k")
nnoremap("<C-l>", "<C-w>l")
+
-- Window resize
nnoremap("<M-h>", "<CMD>vertical resize -2<CR>")
nnoremap("<M-j>", "<CMD>resize +2<CR>")
nnoremap("<M-k>", "<CMD>resize -2<CR>")
nnoremap("<M-l>", "<CMD>vertical resize +2<CR>")
+
-- File navigation
nnoremap("<C-s>", "<CMD>Telescope live_grep theme=ivy<CR>")
nnoremap("<C-b>", "<CMD>Telescope buffers theme=ivy<CR>")
nnoremap("<C-f>", "<CMD>Telescope frecency workspace=CWD theme=ivy<CR>")
nnoremap("L", "<CMD>BufSurfForward<CR>")
nnoremap("H", "<CMD>BufSurfBack<CR>")
-
--- Buffer Navigation
nnoremap("`", "<CMD>Telescope marks theme=ivy<CR>")
-nnoremap("<M-r>", "<CMD>Telescope lsp_references theme=ivy<CR>")
-nnoremap("<M-b>", "<CMD>Telescope current_buffer_fuzzy_find theme=ivy<CR>")
-nnoremap("<M-d>", "<CMD>Telescope treesitter theme=ivy<CR>")
-nnoremap("<M-m>", "<CMD>Telescope man_pages sections={'3'} theme=ivy<CR>")
-
--- Project Management
--- local create_project = function ()
--- local project_name = vim.fn.input("Project name: ")
--- vim.loop.fs_mkdir("/home/georgios/Projects/" .. project_name, 448)
--- end
--- nnoremap("<leader>c", create_project)
--- -- nnoremap("<leader>c", ":mkdir ~/Projects/")
--- nnoremap("<leader>o", "<CMD>Telescope neovim-project discover<CR>")
--- Move text up and down
-xnoremap("J", ":move '>+1<CR>gv-gv")
-xnoremap("K", ":move '<-2<CR>gv-gv")
-nnoremap("<leader>x", ":%!xxd<CR>")
-nnoremap("<leader>X", ":%!xxd -r<CR>")
+-- Search
+nnoremap(LEADER .. SEARCH .. REF, "<CMD>Telescope lsp_references theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. SYMBOL, "<CMD>Telescope lsp_document_symbols theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. FUNC, "<CMD>Telescope treesitter symbols={'function'} theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. VAR, "<CMD>Telescope treesitter symbols={'var'} theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. CLASS, "<CMD>Telescope treesitter symbols={'type'} theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. ALL, "<CMD>Telescope current_buffer_fuzzy_find theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. MAN_PAGES, "<CMD>Telescope man_pages sections={'3'} theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. ERROR, "<CMD>Telescope diagnostics theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. BUF .. GIT .. COMMITS, "<CMD>Telescope git_bcommits theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. GIT .. COMMITS, "<CMD>Telescope git_commits theme=ivy<CR>")
+nnoremap(LEADER .. SEARCH .. GIT .. BRANCHES, "<CMD>Telescope git_branches theme=ivy<CR>")
--- Folding
--- nnoremap("<CR>", "za")
-vnoremap("<M-\\>", require("leap-ast").leap)
--- vim.keymap.set({ 'n', 'x', 'o', 'v' }, "-", require("leap-ast").leap, { noremap = true, silent = true })
-vim.keymap.set({ 'n' }, "<M-s>", "v<M-\\>", { remap = true })
--- vim.cmd("nmap <M-s> V-")
--- Multikey
-nnoremap("<C-c>", ":<C-u>call vm#commands#add_cursor_down(0, v:count1)<CR>")
-nnoremap("<M-c>", ":<C-u>call vm#commands#add_cursor_up(0, v:count1)<CR>")
+-- Views
+nnoremap("K", vim.lsp.buf.hover)
+nnoremap(LEADER .. VIEW .. ERROR, vim.diagnostic.open_float)
+nnoremap(LEADER .. VIEW .. HUNK, gs.preview_hunk)
+nnoremap(LEADER .. VIEW .. BLAME, gs.blame_line)
-local wk = require("which-key")
+nnoremap(LEADER .. TOGGLE .. BLAME, gs.toggle_current_line_blame)
+nnoremap(LEADER .. TOGGLE .. DELETED, gs.toggle_current_line_blame)
+nnoremap(LEADER .. TOGGLE .. UNDO, vim.cmd.UndotreeToggle)
+nnoremap(LEADER .. TOGGLE .. EXPLORER, vim.cmd.NvimTreeToggle)
+nnoremap(LEADER .. TOGGLE .. INSPECTOR, vim.cmd.InspectTree)
--- Tree
-wk.add({
- { "<leader>e", vim.cmd.NvimTreeToggle, desc = "File Tree" },
- { "<leader>u", vim.cmd.UndotreeToggle, desc = "Undo Tree" },
- { "<leader>i", vim.cmd.InspectTree, desc = "Inspect Tree" },
-})
--- Telescope
-wk.add({
- { "<leader>s", group = "Search" },
- { "<leader>sf", "<CMD>Telescope frecency workspace=CWD<CR>", desc = "Search Files" },
- { "<leader>ss", telescope.live_grep, desc = "Grep" },
- { "<leader>sg", telescope.grep_string, desc = "Grep String Under Cursor" },
- { "<leader>sM", telescope.man_pages, desc = "Man Pages" },
- { "<leader>sm", telescope.marks, desc = "List Marks" },
- { "<leader>sh", telescope.help_tags, desc = "Help Tags" },
- { "<leader>sb", telescope.buffers, desc = "Buffers" },
- { "<leader>sr", telescope.lsp_references, desc = "References" },
- { "<leader>sG", telescope.git_files, desc = "Find Git Files" },
- { "<leader>sS", telescope.treesitter, desc = "Symbols" },
-})
+-- Movement
+nnoremap(GOTO .. NEXT .. ERROR, vim.diagnostic.goto_next)
+nnoremap(GOTO .. PREV .. ERROR, vim.diagnostic.goto_prev)
+nnoremap(GOTO .. DECL, vim.lsp.buf.declaration)
+nnoremap(GOTO .. DEF, vim.lsp.buf.definition)
+nnoremap(GOTO .. IMPL, vim.lsp.buf.implementation)
--- LSP Keymaps
-wk.add({
- { "<leader>l", group = "LSP" },
- { "<leader>lD", vim.lsp.buf.declaration, desc = "Goto Declarations" },
- { "<leader>ld", vim.lsp.buf.definition, desc = "Goto Definition" },
- { "<leader>li", vim.lsp.buf.implementation, desc = "Goto Implementation" },
- { "<leader>lh", vim.lsp.buf.hover, desc = "Show Documentation" },
- { "<leader>lr", vim.lsp.buf.rename, desc = "Rename" },
- { "<leader>lR", telescope.lsp_references, desc = "Goto References" },
- { "<leader>la", vim.lsp.buf.code_action, desc = "Code Action" },
- { "<leader>lf", vim.lsp.buf.format, desc = "Format Code" },
-})
-wk.add({
- { "<leader>d", group = "Diagnostics" },
- { "<leader>df", vim.diagnostic.open_float(), desc = "Show Diagnostics in Line" },
- { "<leader>dp", function() vim.diagnostic.goto_prev({ border = "rounded" }) end, desc = "Goto Prev Diagnostic" },
- { "<leader>dn", function() vim.diagnostic.goto_next({ border = "rounded" }) end, desc = "Goto Next Diagnostic" },
- { "<leader>da", telescope.diagnostics, desc = "Show Open Diagnostics" },
- -- ["<leader>da"] = { vim.diagnostic.setloclist(), "Show All Diagnostics in Buffer" },
-})
-nnoremap("gD", vim.lsp.buf.declaration)
-nnoremap("gd", vim.lsp.buf.definition)
-nnoremap("gi", vim.lsp.buf.implementation)
-nnoremap("gr", vim.lsp.buf.references)
-nnoremap("K", vim.lsp.buf.hover)
-nnoremap("[d", function() vim.diagnostic.goto_prev({ border = "rounded" }) end)
-nnoremap("]d", function() vim.diagnostic.goto_next({ border = "rounded" }) end)
+nnoremap(GOTO .. NEXT .. HUNK, gs.next_hunk)
+nnoremap(GOTO .. PREV .. HUNK, gs.prev_hunk)
+nnoremap(LEADER .. GIT .. STAGE .. HUNK, gs.stage_hunk)
+nnoremap(LEADER .. GIT .. STAGE .. UNDO .. HUNK, gs.undo_stage_hunk)
+nnoremap(LEADER .. GIT .. STAGE .. RESET .. HUNK, gs.reset_hunk)
+nnoremap(LEADER .. GIT .. STAGE .. BUF, gs.stage_buffer)
+nnoremap(LEADER .. GIT .. STAGE .. RESET .. BUF, gs.reset_buffer)
+nnoremap(LEADER .. GIT .. DIFF .. BUF, gs.diffthis)
+nnoremap(LEADER .. GIT .. DIFF .. PREV .. BUF, function() gs.diffthis("~") end)
--- Gitsigns
-local gs = require("gitsigns")
-wk.add({
- { "<leader>g", group = "Git" },
- { "<leader>gj", gs.next_hunk, desc = "Next Hunk" },
- { "<leader>gk", gs.prev_hunk, desc = "Prev Hunk" },
- { "<leader>gs", function() gs.stage_hunk { vim.fn.line("."), vim.fn.line("v") } end, desc = "Stage Hunk" },
- { "<leader>gr", function() gs.reset_hunk { vim.fn.line("."), vim.fn.line("v") } end, desc = "Reset Hunk" },
- { "<leader>gp", gs.preview_hunk, desc = "Preview Hunk" },
- { "<leader>gu", gs.undo_stage_hunk, desc = "Undo Stage Hunk" },
- { "<leader>gS", gs.stage_buffer, desc = "Stage Buffer" },
- { "<leader>gb", function() gs.blame_line { vim.fn.line("."), vim.fn.line("v") } end, desc = "Blame Line" },
- { "<leader>gB", gs.toggle_current_line_blame, desc = "Toggle Blame Line" },
- { "<leader>gR", gs.reset_buffer, desc = "Reset Buffer" },
- { "<leader>gd", gs.diffthis, desc = "Diff" },
- { "<leader>gD", function() gs.diffthis("~") end, desc = "Diff2" },
- { "<leader>gx", gs.toggle_deleted, desc = "Toggle Deleted" },
- { "<leader>gc", telescope.git_bcommits, desc = "Buffer Commits" },
- { "<leader>gC", telescope.git_commits, desc = "Commits" },
- { "<leader>gn", telescope.git_branches, desc = "Branches" },
+
+-- Transform
+nnoremap(LEADER .. RENAME, vim.lsp.buf.rename)
+nnoremap(LEADER .. CODE_ACTION, vim.lsp.buf.code_action)
+nnoremap(LEADER .. FORMAT, vim.lsp.buf.format)
+
+
+require("nvim-treesitter.configs").setup({
+ textobjects = {
+ enable = true,
+ select = {
+ enable = true,
+
+ -- Automatically jump forward to textobj, similar to targets.vim
+ lookahead = true,
+
+ keymaps = {
+ -- You can use the capture groups defined in textobjects.scm
+ [OUTER .. ASSIGN] = { query = "@assignment.outer", desc = "Select outer part of an assignment" },
+ [INNER .. ASSIGN] = { query = "@assignment.inner", desc = "Select inner part of an assignment" },
+ [LHS .. ASSIGN] = { query = "@assignment.lhs", desc = "Select left hand side of an assignment" },
+ [RHS .. ASSIGN] = { query = "@assignment.rhs", desc = "Select right hand side of an assignment" },
+
+ [OUTER .. PARAM] = { query = "@parameter.outer", desc = "Select outer part of a parameter/argument" },
+ [INNER .. PARAM] = { query = "@parameter.inner", desc = "Select inner part of a parameter/argument" },
+
+ [OUTER .. COND] = { query = "@conditional.outer", desc = "Select outer part of a conditional" },
+ [INNER .. COND] = { query = "@conditional.inner", desc = "Select inner part of a conditional" },
+
+ [OUTER .. LOOP] = { query = "@loop.outer", desc = "Select outer part of a loop" },
+ [INNER .. LOOP] = { query = "@loop.inner", desc = "Select inner part of a loop" },
+
+ [OUTER .. CALL] = { query = "@call.outer", desc = "Select outer part of a function call" },
+ [INNER .. CALL] = { query = "@call.inner", desc = "Select inner part of a function call" },
+
+ [OUTER .. FUNC] = {
+ query = "@function.outer",
+ desc =
+ "Select outer part of a method/function definition"
+ },
+ [INNER .. FUNC] = {
+ query = "@function.inner",
+ desc =
+ "Select inner part of a method/function definition"
+ },
+
+ [OUTER .. CLASS] = { query = "@class.outer", desc = "Select outer part of a class" },
+ [INNER .. CLASS] = { query = "@class.inner", desc = "Select inner part of a class" },
+ },
+ },
+ swap = {
+ enable = true,
+ swap_next = {
+ [LEADER .. MOVE .. PARAM] = "@parameter.inner",
+ [LEADER .. MOVE .. FUNC] = "@function.outer",
+ [LEADER .. MOVE .. COND] = "@conditional.inner",
+ [LEADER .. MOVE .. CLASS] = "@class.outer",
+ },
+ swap_previous = {
+ [LEADER .. MOVE .. string.upper(PARAM)] = "@parameter.inner",
+ [LEADER .. MOVE .. string.upper(FUNC)] = "@function.outer",
+ [LEADER .. MOVE .. string.upper(COND)] = "@conditional.inner",
+ [LEADER .. MOVE .. string.upper(CLASS)] = "@class.outer",
+ },
+ },
+ move = {
+ enable = true,
+ set_jumps = true, -- whether to set jumps in the jumplist
+ goto_next_start = {
+ [GOTO .. NEXT .. CALL] = { query = "@call.outer", desc = "Next function call start" },
+ [GOTO .. NEXT .. FUNC] = { query = "@function.outer", desc = "Next method/function def start" },
+ [GOTO .. NEXT .. CLASS] = { query = "@class.outer", desc = "Next class start" },
+ [GOTO .. NEXT .. COND] = { query = "@conditional.outer", desc = "Next conditional start" },
+ [GOTO .. NEXT .. LOOP] = { query = "@loop.outer", desc = "Next loop start" },
+ [GOTO .. NEXT .. PARAM] = { query = "@parameter.inner", desc = "Next parameter start" },
+ [GOTO .. NEXT .. ASSIGN] = { query = "@assignment.outer", desc = "Next assignment start" },
+
+ -- You can pass a query group to use query from `queries/<lang>/<query_group>.scm file in your runtime path.
+ -- Below example nvim-treesitter's `locals.scm` and `folds.scm`. They also provide highlights.scm and indent.scm.
+ -- ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
+ -- ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" },
+ },
+ goto_next_end = {
+ [GOTO .. NEXT .. string.upper(CALL)] = { query = "@call.outer", desc = "Next function call end" },
+ [GOTO .. NEXT .. string.upper(FUNC)] = { query = "@function.outer", desc = "Next method/function def end" },
+ [GOTO .. NEXT .. string.upper(CLASS)] = { query = "@class.outer", desc = "Next class end" },
+ [GOTO .. NEXT .. string.upper(COND)] = { query = "@conditional.outer", desc = "Next conditional end" },
+ [GOTO .. NEXT .. string.upper(LOOP)] = { query = "@loop.outer", desc = "Next loop end" },
+ [GOTO .. NEXT .. string.upper(PARAM)] = { query = "@parameter.inner", desc = "Next parameter end" },
+ [GOTO .. NEXT .. string.upper(ASSIGN)] = { query = "@assignment.outer", desc = "Next assignment start" },
+ },
+ goto_previous_start = {
+ [GOTO .. PREV .. CALL] = { query = "@call.outer", desc = "Prev function call start" },
+ [GOTO .. PREV .. FUNC] = { query = "@function.outer", desc = "Prev method/function def start" },
+ [GOTO .. PREV .. CLASS] = { query = "@class.outer", desc = "Prev class start" },
+ [GOTO .. PREV .. COND] = { query = "@conditional.outer", desc = "Prev conditional start" },
+ [GOTO .. PREV .. LOOP] = { query = "@loop.outer", desc = "Prev loop start" },
+ [GOTO .. PREV .. PARAM] = { query = "@parameter.inner", desc = "Prev parameter start" },
+ [GOTO .. PREV .. ASSIGN] = { query = "@assignment.outer", desc = "Next assignment start" },
+ },
+ goto_previous_end = {
+ [GOTO .. PREV .. string.upper(CALL)] = { query = "@call.outer", desc = "Prev function call end" },
+ [GOTO .. PREV .. string.upper(FUNC)] = { query = "@function.outer", desc = "Prev method/function def end" },
+ [GOTO .. PREV .. string.upper(CLASS)] = { query = "@class.outer", desc = "Prev class end" },
+ [GOTO .. PREV .. string.upper(COND)] = { query = "@conditional.outer", desc = "Prev conditional end" },
+ [GOTO .. PREV .. string.upper(LOOP)] = { query = "@loop.outer", desc = "Prev loop end" },
+ [GOTO .. PREV .. string.upper(PARAM)] = { query = "@parameter.inner", desc = "Prev parameter end" },
+ [GOTO .. PREV .. string.upper(ASSIGN)] = { query = "@assignment.outer", desc = "Next assignment start" },
+ },
+ },
+ },
})
--- -- Text object
--- map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
-nnoremap("yi_", "T_yt_")
-nnoremap("ya_", "F_yf_")
-nnoremap("di_", "T_dt_")
-nnoremap("da_", "F_df_")
-nnoremap("ci_", "T_ct_")
-nnoremap("ca_", "F_cf_")
+local ts_repeat_move = require("nvim-treesitter.textobjects.repeatable_move")
--- Switch between C code and Header
-local function swap_c()
- if (vim.fn.expand('%:t'):match("^.+(%..+)$") == ".c") then
- vim.cmd.e("%<.h")
- elseif (vim.fn.expand('%:t'):match("^.+(%..+)$") == ".h") then
- vim.cmd.e("%<.c")
- end
-end
-nnoremap("<M-q>", swap_c)
+-- vim way: ; goes to the direction you were moving.
+vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)
+vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite)
+
+-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
+vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f)
+vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F)
+vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t)
+vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T)
ensure_installed = {
"cmake",
"bashls",
- "tsserver",
"cssls",
"html",
"pyright",
require("lazy").setup({
-- Lib
- "nvim-lua/plenary.nvim",
- "nvim-tree/nvim-web-devicons",
+ -- "nvim-lua/plenary.nvim",
-- UI
- "nvim-lualine/lualine.nvim",
- "nvim-tree/nvim-tree.lua",
- "akinsho/toggleterm.nvim",
+ {
+ "nvim-lualine/lualine.nvim",
+ dependencies = { "nvim-tree/nvim-web-devicons" },
+ },
+ {
+ "nvim-tree/nvim-tree.lua",
+ dependencies = { "nvim-tree/nvim-web-devicons" },
+ },
"folke/which-key.nvim",
{
- 'nvimdev/dashboard-nvim',
- event = 'VimEnter',
+ "nvimdev/dashboard-nvim",
+ event = "VimEnter",
config = function()
- require('dashboard').setup {
+ require("dashboard").setup {
-- config
}
end,
- dependencies = { { 'nvim-tree/nvim-web-devicons' } }
+ dependencies = { { "nvim-tree/nvim-web-devicons" } },
},
- -- {
- -- "coffebar/neovim-project",
- -- opts = {
- -- projects = { -- define project roots
- -- "~/Projects/*",
- -- "~/.config/*",
- -- },
- -- },
- -- init = function()
- -- -- enable saving the state of plugins in the session
- -- vim.opt.sessionoptions:append("globals") -- save global variables that start with an uppercase letter and contain at least one lowercase letter.
- -- end,
- -- dependencies = {
- -- { "nvim-lua/plenary.nvim" },
- -- { "nvim-telescope/telescope.nvim", tag = "0.1.4" },
- -- { "Shatur/neovim-session-manager" },
- -- },
- -- lazy = false,
- -- priority = 100,
- -- },
+ "akinsho/toggleterm.nvim",
-- Lsp
- -- Snippets
"neovim/nvim-lspconfig",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"jay-babu/mason-null-ls.nvim",
"nvimtools/none-ls.nvim",
"nvim-treesitter/nvim-treesitter",
- "nvim-treesitter/nvim-treesitter-textobjects",
+ {
+ "nvim-treesitter/nvim-treesitter-textobjects",
+ dependencies = { "nvim-treesitter/nvim-treesitter" },
+ },
-- Other
"windwp/nvim-autopairs",
"windwp/nvim-ts-autotag",
- -- "CJYLZS/nvim-bufsurf",
"ton/vim-bufsurf",
"numToStr/Comment.nvim",
"lewis6991/gitsigns.nvim",
"ggandor/leap.nvim",
- "ggandor/leap-ast.nvim",
"kylechui/nvim-surround",
- "ziontee113/syntax-tree-surfer",
- "nvim-telescope/telescope.nvim",
- "nvim-telescope/telescope-frecency.nvim",
- "nvim-treesitter/nvim-treesitter-context",
+ {
+ "nvim-telescope/telescope.nvim",
+ dependencies = { "nvim-lua/plenary.nvim" },
+ },
+ {
+ "nvim-telescope/telescope-frecency.nvim",
+ dependencies = { "nvim-telescope/telescope.nvim", "nvim-tree/nvim-web-devicons" },
+ },
"mbbill/undotree",
"mg979/vim-visual-multi",
- -- "hiphish/rainbow-delimiters.nvim",
- { "HiPhish/rainbow-delimiters.nvim" },
-
{
- 'mrcjkb/rustaceanvim',
- version = '^4', -- Recommended
- ft = { 'rust' },
+ "mrcjkb/rustaceanvim",
+ version = "^5", -- Recommended
},
})
+++ /dev/null
---[[
- Copyright 2020-2022 Chinmay Dalal
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
---]]
-
-local queries = require("nvim-treesitter.query")
-local parsers = require("nvim-treesitter.parsers")
-local configs = require("nvim-treesitter.configs")
-local api = vim.api
-
-local add_predicate = vim.treesitter.query.add_predicate
-local nsid = vim.api.nvim_create_namespace("rainbow_ns")
-local extended_languages = { "latex", "html", "verilog", "jsx" }
-local colors = configs.get_module("rainbow").colors
-local termcolors = configs.get_module("rainbow").termcolors
-
---- Maps a buffer ID to the buffer's parser; retaining a reference prevents the
---- parser from getting garbage-collected.
-local buffer_parsers = {}
-
---- Find the nesting level of a node.
---- @param node table # Node to find the level of
---- @param len number # Number of colours
---- @param levels table # Levels for the language
-local function color_no(node, len, levels)
- local counter = 0
- local current = node
- local found = false
- while current:parent() ~= nil do
- if levels then
- if levels[current:type()] then
- counter = counter + 1
- found = true
- end
- else
- counter = counter + 1
- found = true
- end
- current = current:parent()
- end
- if not found then
- return 1
- elseif counter % len == 0 then
- return len
- else
- return (counter % len)
- end
-end
-
---- Update highlights for a range. Called every time text is changed.
---- @param bufnr number # Buffer number
---- @param changes table # Range of text changes
---- @param tree table # Syntax tree
---- @param lang string # Language
-local function update_range(bufnr, changes, tree, lang)
- if vim.fn.pumvisible() ~= 0 or not lang then
- return
- end
-
- for _, change in ipairs(changes) do
- local root_node = tree:root()
- local query = queries.get_query(lang, "parens")
- local levels = require("rainbow.levels")[lang]
- if query ~= nil then
- for _, node, _ in query:iter_captures(root_node, bufnr, change[1], change[3] + 1) do
- -- set colour for this nesting level
- if not node:has_error() then
- local color_no_ = color_no(node, #colors, levels)
- local startRow, startCol, endRow, endCol = node:range() -- range of the capture, zero-indexed
- if vim.fn.has("nvim-0.7") == 1 then
- vim.highlight.range(
- bufnr,
- nsid,
- ("rainbowcol" .. color_no_),
- { startRow, startCol },
- { endRow, endCol - 1 },
- {
- regtype = "b",
- inclusive = true,
- priority = 210,
- }
- )
- else
- vim.highlight.range(
- bufnr,
- nsid,
- ("rainbowcol" .. color_no_),
- { startRow, startCol },
- { endRow, endCol - 1 },
- "blockwise",
- true,
- 210
- )
- end
- end
- end
- end
- end
-end
-
---- Update highlights for every tree in given buffer.
---- @param bufnr number # Buffer number
-local function full_update(bufnr)
- local parser = buffer_parsers[bufnr]
- parser:for_each_tree(function(tree, sub_parser)
- update_range(bufnr, { { tree:root():range() } }, tree, sub_parser:lang())
- end)
-end
-
---- Register predicates for extended mode.
---- @param config table # Configuration for the `rainbow` module in nvim-treesitter
-local function register_predicates(config)
- local extended_mode
-
- if type(config.extended_mode) == "table" then
- extended_mode = {}
- for _, lang in pairs(config.extended_mode) do
- extended_mode[lang] = true
- end
- elseif type(config.extended_mode) == "boolean" then
- extended_mode = config.extended_mode
- else
- vim.api.nvim_err_writeln("nvim-ts-rainbow: `extended_mode` can be a boolean or a table")
- end
-
- for _, lang in ipairs(extended_languages) do
- local enable_extended_mode
- if type(extended_mode) == "table" then
- enable_extended_mode = extended_mode[lang]
- else
- enable_extended_mode = extended_mode
- end
- add_predicate(lang .. "-extended-rainbow-mode?", function()
- return enable_extended_mode
- end, true)
- end
-end
-
-local state_table = {}
-
-local M = {}
-
---- Define highlight groups. This had to be a function to allow an autocmd doing this at colorscheme change.
-function M.defhl()
- for i = 1, math.max(#colors, #termcolors) do
- local s = string.format("highlight default rainbowcol%d", i)
- if #colors > 0 then
- s = s .. " guifg=" .. colors[(i % #colors == 0) and #colors or (i % #colors)]
- end
- if #termcolors > 0 then
- s = s
- .. " ctermfg="
- .. termcolors[(i % #termcolors == 0) and #termcolors or (i % #termcolors)]
- end
- vim.cmd(s)
- end
-end
-
-M.defhl()
-
---- Attach module to buffer. Called when new buffer is opened or `:TSBufEnable rainbow`.
---- @param bufnr number # Buffer number
---- @param lang string # Buffer language
-function M.attach(bufnr, lang)
- local config = configs.get_module("rainbow")
- local max_file_lines = config.max_file_lines
- if max_file_lines ~= nil and vim.api.nvim_buf_line_count(bufnr) > max_file_lines then
- return
- end
- register_predicates(config)
- local parser = parsers.get_parser(bufnr, lang)
- parser:register_cbs({
- on_changedtree = function(changes, tree)
- if state_table[bufnr] then
- update_range(bufnr, changes, tree, lang)
- else
- return
- end
- end,
- })
- buffer_parsers[bufnr] = parser
- state_table[bufnr] = true
- full_update(bufnr)
-end
-
---- Detach module from buffer. Called when `:TSBufDisable rainbow`.
---- @param bufnr number # Buffer number
-function M.detach(bufnr)
- state_table[bufnr] = false
- if vim.treesitter.highlighter.hl_map then
- vim.treesitter.highlighter.hl_map["punctuation.bracket"] = "TSPunctBracket"
- else
- vim.api.nvim_set_hl(0, "@punctuation.bracket", { link = "TSPunctBracket" })
- end
- vim.api.nvim_buf_clear_namespace(bufnr, nsid, 0, -1)
- buffer_parsers[bufnr] = nil
-end
-
-if vim.fn.has("nvim-0.7") == 1 then
- api.nvim_create_augroup("RainbowParser", {})
- api.nvim_create_autocmd("FileType", {
- group = "RainbowParser",
- pattern = "*",
- callback = function()
- local bufnr = api.nvim_get_current_buf()
- if state_table[bufnr] then
- local lang = parsers.get_buf_lang(bufnr)
- local parser = parsers.get_parser(bufnr, lang)
- buffer_parsers[bufnr] = parser
- end
- end,
- })
-end
-
-return M
+++ /dev/null
--- -- Syntax Tree Surfer
--- local opts = {noremap = true, silent = true}
---
---
--- -- Normal Mode Swapping:
--- -- Swap The Master Node relative to the cursor with it's siblings, Dot Repeatable
--- vim.keymap.set("n", "vU", function()
--- vim.opt.opfunc = "v:lua.STSSwapUpNormal_Dot"
--- return "g@l"
--- end, { silent = true, expr = true })
--- vim.keymap.set("n", "vD", function()
--- vim.opt.opfunc = "v:lua.STSSwapDownNormal_Dot"
--- return "g@l"
--- end, { silent = true, expr = true })
---
--- -- Swap Current Node at the Cursor with it's siblings, Dot Repeatable
--- vim.keymap.set("n", "vd", function()
--- vim.opt.opfunc = "v:lua.STSSwapCurrentNodeNextNormal_Dot"
--- return "g@l"
--- end, { silent = true, expr = true })
--- vim.keymap.set("n", "vu", function()
--- vim.opt.opfunc = "v:lua.STSSwapCurrentNodePrevNormal_Dot"
--- return "g@l"
--- end, { silent = true, expr = true })
---
--- --> If the mappings above don't work, use these instead (no dot repeatable)
--- -- vim.keymap.set("n", "vd", '<cmd>STSSwapCurrentNodeNextNormal<cr>', opts)
--- -- vim.keymap.set("n", "vu", '<cmd>STSSwapCurrentNodePrevNormal<cr>', opts)
--- -- vim.keymap.set("n", "vD", '<cmd>STSSwapDownNormal<cr>', opts)
--- -- vim.keymap.set("n", "vU", '<cmd>STSSwapUpNormal<cr>', opts)
---
--- -- Visual Selection from Normal Mode
--- vim.keymap.set("n", "vx", '<cmd>STSSelectMasterNode<cr>', opts)
--- vim.keymap.set("n", "vn", '<cmd>STSSelectCurrentNode<cr>', opts)
---
--- -- Select Nodes in Visual Mode
--- vim.keymap.set("x", "J", '<cmd>STSSelectNextSiblingNode<cr>', opts)
--- vim.keymap.set("x", "K", '<cmd>STSSelectPrevSiblingNode<cr>', opts)
--- vim.keymap.set("x", "H", '<cmd>STSSelectParentNode<cr>', opts)
--- vim.keymap.set("x", "L", '<cmd>STSSelectChildNode<cr>', opts)
---
--- -- Swapping Nodes in Visual Mode
--- vim.keymap.set("x", "<A-j>", 'STSSwapNextVisual', opts)
--- vim.keymap.set("x", "<A-k>", 'STSSwapPrevVisual', opts)
-require("nvim-treesitter.configs").setup({
- textobjects = {
- select = {
- enable = true,
+-- OUTER = "a"
+-- INNER = "i"
+-- NEXT = "<M-n>"
+-- PREV = "<M-p>"
+-- LHS = "h"
+-- RHS = "l"
+-- SWAP = "<M-s>"
+--
+-- STRUCT = "s"
+-- ASSIGN = "q"
+-- PARAM = "p"
+-- COND = "i"
+-- LOOP = "l"
+-- CALL = "c"
+-- FUNC = "f"
- -- Automatically jump forward to textobj, similar to targets.vim
- lookahead = true,
-
- keymaps = {
- -- You can use the capture groups defined in textobjects.scm
- ["a="] = { query = "@assignment.outer", desc = "Select outer part of an assignment" },
- ["i="] = { query = "@assignment.inner", desc = "Select inner part of an assignment" },
- ["l="] = { query = "@assignment.lhs", desc = "Select left hand side of an assignment" },
- ["r="] = { query = "@assignment.rhs", desc = "Select right hand side of an assignment" },
-
- ["aa"] = { query = "@parameter.outer", desc = "Select outer part of a parameter/argument" },
- ["ia"] = { query = "@parameter.inner", desc = "Select inner part of a parameter/argument" },
-
- ["ai"] = { query = "@conditional.outer", desc = "Select outer part of a conditional" },
- ["ii"] = { query = "@conditional.inner", desc = "Select inner part of a conditional" },
-
- ["al"] = { query = "@loop.outer", desc = "Select outer part of a loop" },
- ["il"] = { query = "@loop.inner", desc = "Select inner part of a loop" },
-
- ["am"] = { query = "@call.outer", desc = "Select outer part of a function call" },
- ["im"] = { query = "@call.inner", desc = "Select inner part of a function call" },
-
- ["af"] = { query = "@function.outer", desc =
- "Select outer part of a method/function definition" },
- ["if"] = { query = "@function.inner", desc =
- "Select inner part of a method/function definition" },
-
- ["ac"] = { query = "@class.outer", desc = "Select outer part of a class" },
- ["ic"] = { query = "@class.inner", desc = "Select inner part of a class" },
- },
- },
- swap = {
- enable = true,
- swap_next = {
- ["<localleader>pn"] = "@parameter.inner", -- swap parameters/argument with next
- ["<localleader>fn"] = "@function.outer", -- swap function with next
- ["<localleader>in"] = "@conditional.inner", -- swap function with next
- },
- swap_previous = {
- ["<localleader>pp"] = "@parameter.inner", -- swap parameters/argument with prev
- ["<localleader>fp"] = "@function.outer", -- swap function with previous
- ["<localleader>ip"] = "@conditional.inner", -- swap function with next
- },
- },
- move = {
- enable = true,
- set_jumps = true, -- whether to set jumps in the jumplist
- goto_next_start = {
- ["]m"] = { query = "@call.outer", desc = "Next function call start" },
- ["]f"] = { query = "@function.outer", desc = "Next method/function def start" },
- ["]c"] = { query = "@class.outer", desc = "Next class start" },
- ["]i"] = { query = "@conditional.outer", desc = "Next conditional start" },
- ["]l"] = { query = "@loop.outer", desc = "Next loop start" },
- ["]p"] = { query = "@parameter.inner", desc = "Next parameter start" },
-
- -- You can pass a query group to use query from `queries/<lang>/<query_group>.scm file in your runtime path.
- -- Below example nvim-treesitter's `locals.scm` and `folds.scm`. They also provide highlights.scm and indent.scm.
- ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
- ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" },
- },
- goto_next_end = {
- ["]M"] = { query = "@call.outer", desc = "Next function call end" },
- ["]F"] = { query = "@function.outer", desc = "Next method/function def end" },
- ["]C"] = { query = "@class.outer", desc = "Next class end" },
- ["]I"] = { query = "@conditional.outer", desc = "Next conditional end" },
- ["]L"] = { query = "@loop.outer", desc = "Next loop end" },
- },
- goto_previous_start = {
- ["[m"] = { query = "@call.outer", desc = "Prev function call start" },
- ["[f"] = { query = "@function.outer", desc = "Prev method/function def start" },
- ["[c"] = { query = "@class.outer", desc = "Prev class start" },
- ["[i"] = { query = "@conditional.outer", desc = "Prev conditional start" },
- ["[l"] = { query = "@loop.outer", desc = "Prev loop start" },
- },
- goto_previous_end = {
- ["[M"] = { query = "@call.outer", desc = "Prev function call end" },
- ["[F"] = { query = "@function.outer", desc = "Prev method/function def end" },
- ["[C"] = { query = "@class.outer", desc = "Prev class end" },
- ["[I"] = { query = "@conditional.outer", desc = "Prev conditional end" },
- ["[L"] = { query = "@loop.outer", desc = "Prev loop end" },
- },
- },
- },
-})
-
-local ts_repeat_move = require("nvim-treesitter.textobjects.repeatable_move")
-
--- vim way: ; goes to the direction you were moving.
-vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)
-vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite)
-
--- Optionally, make builtin f, F, t, T also repeatable with ; and ,
-vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f)
-vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F)
-vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t)
-vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T)
(type_identifier) @type.created
-(if_statement) @branch
-(case_statement) @branch
+(if_statement) @conditional
+(case_statement) @conditional
(for_statement) @loop
(while_statement) @loop
(do_statement) @loop
;; extends
(type_identifier) @type.created
-"let" @keyword.let
+"let" @declare
+
+
+; conditionals
+(if_expression) @conditional
+
+(match_expression) @conditional
+
+; loops
+(loop_expression) @loop
+
+(while_expression) @loop
+
+(for_expression) @loop
+
+
+; jumps
+(break_expression) @goto
+
+(return_expression) @goto