diff options
Diffstat (limited to 'lua')
-rw-r--r-- | lua/tjk/keybindings.lua | 46 | ||||
-rw-r--r-- | lua/tjk/lazy.lua | 39 | ||||
-rw-r--r-- | lua/tjk/misc.lua | 75 | ||||
-rw-r--r-- | lua/tjk/options.lua | 38 | ||||
-rw-r--r-- | lua/tjk/plugins/autoclose.lua | 9 | ||||
-rw-r--r-- | lua/tjk/plugins/cmp.lua | 26 | ||||
-rw-r--r-- | lua/tjk/plugins/colorizer.lua | 12 | ||||
-rw-r--r-- | lua/tjk/plugins/colorscheme.lua | 81 | ||||
-rw-r--r-- | lua/tjk/plugins/manageself.lua | 3 | ||||
-rw-r--r-- | lua/tjk/plugins/treesitter.lua | 32 |
10 files changed, 361 insertions, 0 deletions
diff --git a/lua/tjk/keybindings.lua b/lua/tjk/keybindings.lua new file mode 100644 index 0000000..563d843 --- /dev/null +++ b/lua/tjk/keybindings.lua @@ -0,0 +1,46 @@ +local key = vim.keymap.set + +vim.g.mapleader = "," + +-- toggle spellcheck +key("n", "<leader>l", [[:setlocal spell! spelllang=en_us<CR>]]) +-- toggle cursorcolumn +key("n", "<leader>c", [[:set cursorcolumn!<CR>]]) + +-- scroll doc with ctrl+[jk] +key({ "n", "v" }, "<C-j>", "<C-e>") +key({ "n", "v" }, "<C-k>", "<C-y>") +-- go to begining or end of line with ctrl+[hl] +key({ "n", "v" }, "<C-h>", "zh") +key({ "n", "v" }, "<C-l>", "zl") + +-- split navigation with ctrl+shift+[hjkl] +key("n", "<C-S-h>", "<C-w>h") +key("n", "<C-S-j>", "<C-w>j") +key("n", "<C-S-k>", "<C-w>k") +key("n", "<C-S-l>", "<C-w>l") + +-- browser like tab shortcuts +key("n", "<C-Tab>", "gt") +key("n", "<C-S-Tab>", "gT") +--key("n", "<C-t>", [[:tabe<CR>]]) +--key("n", "<C-w>", [[:tabclose<CR>]]) -- <C-w> is already used lol +-- additional tab shortcuts +key("n", "<C-t>", "gt") +key("n", "<C-T>", "gT") + + +-- copy text to x11 buffer +key("", "<C-c>", [["+y]]) +key("", "<C-x>", [["+x]]) +key("", "<C-S-c>", [["+y]]) +key("", "<C-S-x>", [["+x]]) + +-- unmap ex mode +key("", "Q", "<NOP>") + +-- repeat commands with visual blocks using period +key("v", ".", [[:normal .<CR>]]) + +-- save files with root permissions with command `w!!` +key("c", "w!!", [[execute 'silent! write !doas tee % >/dev/null' <bar> edit!]]) diff --git a/lua/tjk/lazy.lua b/lua/tjk/lazy.lua new file mode 100644 index 0000000..164d968 --- /dev/null +++ b/lua/tjk/lazy.lua @@ -0,0 +1,39 @@ +-- install lazy.nvim via instructions from github +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +-- require lazy module with safety check +local success, lazy = pcall(require, "lazy") + +if not success then + vim.notify("Failed to load lazy.nvim plugin manager") + return +end + +-- setup lazy & enable plugins +return lazy.setup( + { + { import = "tjk.plugins" } + }, + { + -- auto update plugins + checker = { + enabled = true, + notify = false + }, + -- disable change notification + change_detection = { + notify = false + }, + } +) diff --git a/lua/tjk/misc.lua b/lua/tjk/misc.lua new file mode 100644 index 0000000..14c5bd8 --- /dev/null +++ b/lua/tjk/misc.lua @@ -0,0 +1,75 @@ +-- Use tabs instead of spaces for certain filetypes +local tabs_instead_of_spaces_filetypes = { + "sass", + "scss", +} + +local tabs_instead_of_spaces = function(args) + local o = vim.opt_local + o.expandtab = false + --o.cinoptions = true + o.preserveindent = true + o.softtabstop = 0 + o.shiftwidth = 4 + o.tabstop = 4 +end +vim.api.nvim_create_autocmd("FileType", { pattern = tabs_instead_of_spaces_filetypes, callback = tabs_instead_of_spaces }) + + +vim.cmd [[ + "" Extra functionality + + "" Functions for changing the terminal emulator's class name to 'Vim' + "function GetTermPID(temu) + " let pinfo = ['', getpid(), ''] + " while !(pinfo[2] =~ a:temu || pinfo[1] == '0') + " let pinfo = split(system('ps h -o pid,ppid,command= -p' . pinfo[1])) + " endwhile + " return pinfo[0] + "endfunction + + "function SetTermClassName(termpid, name) + " " Command chaining in xdotool doesn't work here for some reason + " silent exec "!xdotool set_window --class " . a:name . " $(xdotool search --pid " . a:termpid . ")" + "endfunction + + "" Behaviors exclusive to either a tty or a graphical terminal emulator + "if empty($DISPLAY) + " " Clear the tty screen after exiting vim + " autocmd VimLeave * :clear + "else + " " Highlight current line + " set cursorline + " " Change window title + " autocmd BufEnter * :set title + " let &titleold="st" + " " Change class name + " let temu = "st" + " let temupid = GetTermPID(temu) + " if (temupid != 1) + " autocmd VimEnter * call SetTermClassName(temupid, "Vim") + " autocmd VimLeave * call SetTermClassName(temupid, temu) + " endif + "endif + + " Automatically deletes all trailing whitespace on save + function DelWS() + let l:save_view = winsaveview() + :%s/\s*$//e + call winrestview(l:save_view) + endfunction + autocmd BufWritePre * call DelWS() + + + " vim -b : edit binary using xxd-format! + augroup Binary + au! + au BufReadPre *.bin let &bin=1 + au BufReadPost *.bin if &bin | %!xxd + au BufReadPost *.bin set ft=xxd | endif + au BufWritePre *.bin if &bin | %!xxd -r + au BufWritePre *.bin endif + au BufWritePost *.bin if &bin | %!xxd + au BufWritePost *.bin set nomod | endif + augroup END +]] diff --git a/lua/tjk/options.lua b/lua/tjk/options.lua new file mode 100644 index 0000000..989c6c7 --- /dev/null +++ b/lua/tjk/options.lua @@ -0,0 +1,38 @@ +local opt = vim.opt +local api = vim.api + +-- misc +opt.autochdir = true -- stay in current directory when opening a file +opt.splitright = true -- open splits on right instead of left +opt.splitbelow = true -- open splits on bottom instead of top +opt.termguicolors = true -- truecolor in terminal, will be disabled in tty +opt.wrap = false -- disable word wrapping +opt.cursorline = true -- highlight current line + +-- line numbers +opt.number = true -- enable line numbers +opt.relativenumber = true -- enable relative line numbers + +-- show whitespace characters +opt.list = true -- show whitespace characters defined in listchars +opt.listchars = "tab:▏ ,space:·" -- highlight tabs and spaces + +-- tabbing +opt.tabstop = 4 -- set tabwidth to 4 instead of 8 +opt.shiftwidth = 4 -- tab key will only insert one tab + +-- search +opt.ignorecase = true -- case-insensitive search... +opt.smartcase = true -- ...unless the search term is capital + +-- experimental +opt.smartindent = true +opt.wildmode = "longest:list:full" -- Better auto-complete + +-- dont continue comments on to new lines (:help fo-table) +api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() + opt.formatoptions:remove { "c", "r", "o" } +end}) + +-- ignore __pycache__ directories in file listings +opt.wildignore = "__pycache__/,*/__pycache__/" diff --git a/lua/tjk/plugins/autoclose.lua b/lua/tjk/plugins/autoclose.lua new file mode 100644 index 0000000..32afa9f --- /dev/null +++ b/lua/tjk/plugins/autoclose.lua @@ -0,0 +1,9 @@ +return { + "m4xshen/autoclose.nvim", -- autoclose parenthesis + opts = { + options = { + pair_spaces = true, + }, + }, + config = true, +} diff --git a/lua/tjk/plugins/cmp.lua b/lua/tjk/plugins/cmp.lua new file mode 100644 index 0000000..1a3cf2f --- /dev/null +++ b/lua/tjk/plugins/cmp.lua @@ -0,0 +1,26 @@ +return { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-path", + "hrsh7th/cmp-buffer", + "ray-x/cmp-treesitter", + }, + config = function() + local cmp = require("cmp") + cmp.setup { + sources = { + { name = "path" }, + { name = "buffer" }, + { name = "treesitter" }, + }, + mapping = cmp.mapping.preset.insert { + --['<C-b>'] = cmp.mapping.scroll_docs(-4), + --['<C-f>'] = cmp.mapping.scroll_docs(4), + --['<C-Space>'] = cmp.mapping.complete(), + --['<C-e>'] = cmp.mapping.abort(), + --['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + ['<Tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }, + } + end +} diff --git a/lua/tjk/plugins/colorizer.lua b/lua/tjk/plugins/colorizer.lua new file mode 100644 index 0000000..0d41dbc --- /dev/null +++ b/lua/tjk/plugins/colorizer.lua @@ -0,0 +1,12 @@ +return { + "norcalli/nvim-colorizer.lua", -- css color highlighter + config = function() + local colorizer = require("colorizer") + colorizer.setup { + "css", + "sass", + "javascript", + "html", + } + end +} diff --git a/lua/tjk/plugins/colorscheme.lua b/lua/tjk/plugins/colorscheme.lua new file mode 100644 index 0000000..2307097 --- /dev/null +++ b/lua/tjk/plugins/colorscheme.lua @@ -0,0 +1,81 @@ +local root_mode = os.getenv "USER" == "root" +local tty_mode = os.getenv "DISPLAY" == nil + +-- load condition +local enable_gruvbox = not root_mode and not tty_mode + +-- use another colorscheme if running as root +if root_mode then + vim.cmd.colorscheme "koehler" +end + +-- disable termguicolors when in a tty +if tty_mode then + vim.opt.termguicolors = false +end + +return { + "ellisonleao/gruvbox.nvim", + cond = enable_gruvbox, + priority = 9001, + config = function() + vim.o.background = "dark" + + local gruvbox = require("gruvbox") + local colors = gruvbox.palette + + gruvbox.setup({ + italic = { + strings = false, + emphasis = true, + comments = false, + operators = false, + folds = true, + }, + invert_selection = true, + contrast = "hard", + palette_overrides = { + light0 = "#ffffff", -- use white instead of the default off-white for text + light1 = "#ffffff", + dark2 = "#363636", -- darker whitespace characters + }, + overrides = { + CursorLine = { bg = "#282828" }, -- dark0 (non hard) + Directory = { link = "GruvboxGreenBold" }, + -- treesitter overrides (more similar to builtin python syntax highlighting) + -- treesitter selectors can be overridden per language using @selector.language + ["@variable"] = { link = "GruvboxFg0" }, + ["@punctuation.bracket"] = { link = "GruvboxFg0" }, + ["@punctuation.delimiter"] = { link = "GruvboxFg0" }, + ["@keyword.import"] = { link = "GruvboxBlue" }, + ["@function"] = { link = "GruvboxAqua" }, + ["@function.method"] = { link = "GruvboxAqua" }, + ["@function.method"] = { link = "GruvboxAqua" }, + ["@attribute.builtin"] = { link = "GruvboxGreenBold" }, + ["@attribute"] = { link = "GruvboxGreenBold" }, + ["@operator"] = { link = "GruvboxRed" }, + ["@variable.member"] = { link = "GruvboxFg0" }, + ["@variable.parameter"] = { link = "GruvboxFg0" }, + ["@function.call"] = { link = "GruvboxPurple" }, + ["@function.method.call"] = { link = "GruvboxPurple" }, + -- rainbow delimiters colors + RainbowDelimiterRed = { fg = "#ff4433" }, + RainbowDelimiterYellow = { fg = "#ffff22" }, + RainbowDelimiterBlue = { fg = "#66f3ff" }, + RainbowDelimiterOrange = { fg = "#ffaa00" }, + RainbowDelimiterGreen = { fg = "#99ff44" }, + RainbowDelimiterViolet = { fg = "#aa00ff" }, + RainbowDelimiterCyan = { fg = "#22ddff" }, + -- TODO italic string start / end + --["@string_start"] = { italic = true }, + --["@string_end"] = { italic = true }, + }, + }) + + -- set colorscheme + vim.cmd.colorscheme "gruvbox" + + -- fix todo comment highlighting (here instead of theme overrides since this replaces the bg w/ default) + vim.api.nvim_set_hl(0, "Todo", { fg = "#ffffff", bold = true }) + end, +} diff --git a/lua/tjk/plugins/manageself.lua b/lua/tjk/plugins/manageself.lua new file mode 100644 index 0000000..098c300 --- /dev/null +++ b/lua/tjk/plugins/manageself.lua @@ -0,0 +1,3 @@ +return { + "folke/lazy.nvim", -- so lazy can manage itself +} diff --git a/lua/tjk/plugins/treesitter.lua b/lua/tjk/plugins/treesitter.lua new file mode 100644 index 0000000..925fb13 --- /dev/null +++ b/lua/tjk/plugins/treesitter.lua @@ -0,0 +1,32 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + dependencies = { + --{ + -- "nvim-treesitter/playground", -- inspect treesitter structure + -- cmd = "TSPlaygroundToggle" + --}, + "HiPhish/rainbow-delimiters.nvim", -- colored delimiters per scope level + { + "windwp/nvim-ts-autotag", -- close tags in html/xml type languages + opts = { + per_filetype = { + ["html"] = { + enable_close = true + } + } + } + }, + }, + config = function() + local configs = require("nvim-treesitter.configs") + configs.setup({ + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "comment", + "javascript", "html", "css", "scss", "python", "php" }, + auto_install = true, -- install available parsers when entering new buffers + highlight = { enable = true, disable = { "yaml", "bash", "latex" } }, + indent = { enable = true, disable = { "yaml" } }, + --playground = { enable = true }, -- treesitter debug + }) + end +} |