From 0cc4ed7dd6fc5b06de245246723138996d449571 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Fri, 14 Jul 2023 22:49:04 +0530 Subject: nvim: Adding basic neovim config --- .config/nvim/lua/justsaumit/bufferline-config.lua | 71 +++++++++++++++++ .config/nvim/lua/justsaumit/colorizer-config.lua | 27 +++++++ .config/nvim/lua/justsaumit/colorscheme.lua | 33 ++++++++ .config/nvim/lua/justsaumit/keymaps.lua | 72 +++++++++++++++++ .config/nvim/lua/justsaumit/lastplace-config.lua | 5 ++ .config/nvim/lua/justsaumit/lualine-config.lua | 40 ++++++++++ .config/nvim/lua/justsaumit/nvim-tree-config.lua | 75 ++++++++++++++++++ .config/nvim/lua/justsaumit/options.lua | 46 +++++++++++ .config/nvim/lua/justsaumit/plugins.lua | 97 +++++++++++++++++++++++ .config/nvim/lua/justsaumit/treesitter-config.lua | 20 +++++ .config/nvim/lua/justsaumit/which-key-config.lua | 11 +++ 11 files changed, 497 insertions(+) create mode 100644 .config/nvim/lua/justsaumit/bufferline-config.lua create mode 100644 .config/nvim/lua/justsaumit/colorizer-config.lua create mode 100644 .config/nvim/lua/justsaumit/colorscheme.lua create mode 100644 .config/nvim/lua/justsaumit/keymaps.lua create mode 100644 .config/nvim/lua/justsaumit/lastplace-config.lua create mode 100644 .config/nvim/lua/justsaumit/lualine-config.lua create mode 100644 .config/nvim/lua/justsaumit/nvim-tree-config.lua create mode 100644 .config/nvim/lua/justsaumit/options.lua create mode 100644 .config/nvim/lua/justsaumit/plugins.lua create mode 100644 .config/nvim/lua/justsaumit/treesitter-config.lua create mode 100644 .config/nvim/lua/justsaumit/which-key-config.lua (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/justsaumit/bufferline-config.lua b/.config/nvim/lua/justsaumit/bufferline-config.lua new file mode 100644 index 0000000..493bafc --- /dev/null +++ b/.config/nvim/lua/justsaumit/bufferline-config.lua @@ -0,0 +1,71 @@ +--vim.opt.termguicolors = true + +local status, bufferline = pcall(require, "bufferline") +if not status then + return +end + +require('bufferline').setup { + options = { + mode = "buffers", + numbers = "none", + close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + indicator = { + icon = '▎', + style = 'icon', + }, + buffer_close_icon = '󰠳', + modified_icon = '●', + close_icon = '', + -- close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + max_name_length = 30, + max_prefix_length = 30, -- prefix used when a buffer is de-duplicated + tab_size = 22, + diagnostics = false, + diagnostics_update_in_insert = false, + offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, + color_icons = true, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + persist_buffer_sort = true, + separator_style = "thin", -- | "thick" | "thin" | slant, + enforce_regular_tabs = true, + always_show_bufferline = true, + name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr" + -- remove extension from markdown files for example + if buf.name:match('%.md') then + return vim.fn.fnamemodify(buf.name, ':t:r') + end + end + } +} + +local opts = { noremap = true, silent = true } +local keymap = vim.keymap.set +keymap("", "", "", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +--Leader+number -> tab change +for i = 1, 9 do + keymap("n", "" .. i, function() + require("bufferline").go_to_buffer(i, true) + end, opts) +end + +--Ctrl+W to close a buffer +keymap("n", "W", ":bdelete!", opts) + + +--Tab or Ctrl+Tab for Forward Cycle //terminals don't see a difference between and +--Shift+Tab for Backward Cycle +keymap("n", "", ":BufferLineCycleNext", opts) +keymap("n", "", ":BufferLineCyclePrev", opts) + diff --git a/.config/nvim/lua/justsaumit/colorizer-config.lua b/.config/nvim/lua/justsaumit/colorizer-config.lua new file mode 100644 index 0000000..569021d --- /dev/null +++ b/.config/nvim/lua/justsaumit/colorizer-config.lua @@ -0,0 +1,27 @@ +require("colorizer").setup { + filetypes = { "*" }, + user_default_options = { + RGB = true, -- #RGB hex codes + RRGGBB = true, -- #RRGGBB hex codes + names = true, -- "Name" codes like Blue or blue + RRGGBBAA = false, -- #RRGGBBAA hex codes + AARRGGBB = false, -- 0xAARRGGBB hex codes + rgb_fn = false, -- CSS rgb() and rgba() functions + hsl_fn = false, -- CSS hsl() and hsla() functions + css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn + -- Available modes for `mode`: foreground, background, virtualtext + mode = "background", -- Set the display mode. + -- Available methods are false / true / "normal" / "lsp" / "both" + -- True is same as normal + tailwind = false, -- Enable tailwind colors + -- parsers can contain values used in |user_default_options| + sass = { enable = false, parsers = { "css" }, }, -- Enable sass colors + virtualtext = "■", + -- update color values even if buffer is not focused + -- example use: cmp_menu, cmp_docs + always_update = false + }, + -- all the sub-options of filetypes apply to buftypes + buftypes = {}, +} diff --git a/.config/nvim/lua/justsaumit/colorscheme.lua b/.config/nvim/lua/justsaumit/colorscheme.lua new file mode 100644 index 0000000..67c166f --- /dev/null +++ b/.config/nvim/lua/justsaumit/colorscheme.lua @@ -0,0 +1,33 @@ +--configuration needs to be set BEFORE loading the color scheme with colorscheme tokyonight +vim.g.tokyonight_style = "night" +tokyonight_terminal_colors=true +tokyonight_italic_comments=true +tokyonight_italic_keywords=true +tokyonight_italic_functions=false +tokyonight_italic_variables=false +tokyonight_transparent=false +tokyonight_hide_inactive_statusline=false +tokyonight_sidebars={} +tokyonight_transparent_sidebar=false +tokyonight_dark_sidebar=true +tokyonight_dark_float=true +tokyonight_colors={} +tokyonight_lualine_bold=false + +--protected call +local colorscheme = "tokyonight" +local pywal = require('pywal') + +local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) +if not status_ok then + vim.notify("colorscheme " .. colorscheme .. " not found! :(") + pywal.setup() + return +end + +-- init.lua +vim.g.tokyodark_transparent_background = false +vim.g.tokyodark_enable_italic_comment = true +vim.g.tokyodark_enable_italic = true +vim.g.tokyodark_color_gamma = "1.0" +vim.cmd("colorscheme tokyodark") diff --git a/.config/nvim/lua/justsaumit/keymaps.lua b/.config/nvim/lua/justsaumit/keymaps.lua new file mode 100644 index 0000000..ebe355a --- /dev/null +++ b/.config/nvim/lua/justsaumit/keymaps.lua @@ -0,0 +1,72 @@ +local opts = { noremap = true, silent = true } + +-- Shorten function name +local keymap = vim.keymap.set + +--Remap space as leader key +keymap("", "", "", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +---Autocompile and Execute +--ANSI C +vim.cmd([[autocmd BufEnter *.c map :w :!gcc % -ansi -o %< && ./%< ]]) +--C99 +vim.cmd([[autocmd BufEnter *.c map :w :!gcc -std=c99 % -o %< && ./%< ]]) +--C +vim.cmd([[autocmd BufEnter *.c map :w :!gcc % -o %< && ./%< ]]) + +--C++ +vim.cmd([[autocmd BufEnter *.cpp map :w :!g++ % -o %< && ./%< ]]) + +-- Modes +-- normal_mode = "n", +-- insert_mode = "i", +-- visual_mode = "v", +-- visual_block_mode = "x", +-- command_mode = "c", + +-- Normal -- +-- +-- +--Save file with Ctrl+S +keymap("n", "", ":w", opts) +--Toggle nvim-tree +keymap("n", "", ":NvimTreeToggle", opts) +--Disable C-e +keymap("n", "", ":", opts) + +-- Better window navigation for split +keymap("n", "", "h", opts) +keymap("n", "", "j", opts) +keymap("n", "", "k", opts) +keymap("n", "", "l", opts) + +-- Resize with arrows +keymap("n", "", ":resize +2", opts) +keymap("n", "", ":resize -2", opts) +keymap("n", "", ":vertical resize +2", opts) +keymap("n", "", ":vertical resize -2", opts) + +-- Move text up and down(better implementation in visual mode) +--keymap("n", "", ":m .+1==gi", opts) +--keymap("n", "", ":m .-2==gi", opts) + +-- Insert -- + +-- Visual -- +-- Stay in indent mode +keymap("v", "<", "", ">gv", opts) + +-- Move text up and down +keymap("v", "", ":m .+1==", opts) +keymap("v", "", ":m .-2==", opts) +keymap("v", "p", '"_dP', opts) + +-- Visual Block -- +-- Move text up and down +keymap("x", "J", ":move '>+1gv-gv", opts) +keymap("x", "K", ":move '<-2gv-gv", opts) +keymap("x", "", ":move '>+1gv-gv", opts) +keymap("x", "", ":move '<-2gv-gv", opts) diff --git a/.config/nvim/lua/justsaumit/lastplace-config.lua b/.config/nvim/lua/justsaumit/lastplace-config.lua new file mode 100644 index 0000000..4fa6a83 --- /dev/null +++ b/.config/nvim/lua/justsaumit/lastplace-config.lua @@ -0,0 +1,5 @@ +require'nvim-lastplace'.setup { + lastplace_ignore_buftype = {"quickfix", "nofile", "help"}, + lastplace_ignore_filetype = {"gitcommit", "gitrebase", "svn", "hgcommit"}, + lastplace_open_folds = true +} diff --git a/.config/nvim/lua/justsaumit/lualine-config.lua b/.config/nvim/lua/justsaumit/lualine-config.lua new file mode 100644 index 0000000..56c426a --- /dev/null +++ b/.config/nvim/lua/justsaumit/lualine-config.lua @@ -0,0 +1,40 @@ +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} +} diff --git a/.config/nvim/lua/justsaumit/nvim-tree-config.lua b/.config/nvim/lua/justsaumit/nvim-tree-config.lua new file mode 100644 index 0000000..c83a1b7 --- /dev/null +++ b/.config/nvim/lua/justsaumit/nvim-tree-config.lua @@ -0,0 +1,75 @@ +-- disable netrw at the very start of your init.lua +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +-- set termguicolors to enable highlight groups +vim.opt.termguicolors = true + +-- empty setup using defaults +require("nvim-tree").setup() + +-- OR setup with some options +require("nvim-tree").setup({ + sort_by = "case_sensitive", + view = { + adaptive_size = true, + }, + renderer = { + group_empty = true, + highlight_git = false, + full_name = false, + highlight_opened_files = "none", + root_folder_modifier = ":~", + indent_width = 2, + indent_markers = { + enable = true, + inline_arrows = true, + icons = { + corner = "└", + edge = "│", + item = "│", + bottom = "─", + none = " ", + }, + }, + icons = { + webdev_colors = true, + git_placement = "before", + padding = " ", + symlink_arrow = " ➛ ", + show = { + file = true, + folder = true, + folder_arrow = true, + git = true, + }, + glyphs = { + default = "", + symlink = "", + bookmark = "", + folder = { + arrow_closed = "", + arrow_open = "", + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + symlink_open = "", + }, + git = { + unstaged = "✗", + staged = "✓", + unmerged = "", + renamed = "➜", + untracked = "★", + deleted = "", + ignored = "◌", + }, + }, + }, + }, + filters = { + dotfiles = true, + }, +}) diff --git a/.config/nvim/lua/justsaumit/options.lua b/.config/nvim/lua/justsaumit/options.lua new file mode 100644 index 0000000..4eae867 --- /dev/null +++ b/.config/nvim/lua/justsaumit/options.lua @@ -0,0 +1,46 @@ +local options = { + number=true, -- Shows absolute linenumber + relativenumber=true, -- Shows linenumber relative to cursor + --combination of both^ for hybrid linenumber +-- textwidth=100, + numberwidth=4, + scrolloff=8, -- keeps cursor in middle of screen/scrolls 8lines in advance + sidescroll=18, + mouse="a", -- enable mouse support + splitbelow=true, -- on horizontal split instead of opening window to left open it at right + splitright=true, -- on vertical split instead of opening window to left open it at right + termguicolors=true, + showmode=false, -- lualine does the job + cmdheight=1, + wrap=false, + whichwrap='b,s,<,>,[,],h,l', + clipboard="unnamedplus", -- allows neovim to access system clipboard using yank + fileencoding="UTF-8", + --spaces/tabs/indents + softtabstop=4, -- No. of spaces per tab + shiftwidth=4, -- No. of auto-indent space + expandtab=true, -- spaces inplace of tabs + autoindent=true, -- New line copies indentation from past line + smartindent=true, -- Indents in accordance to the syntax/style of the code extension + --searches + ignorecase=true, -- Ignore case-sensitivity during search + smartcase=true, -- If searching capital search only capital + hlsearch=false, -- no perma highlight post search + incsearch=true, -- searches for strings incrementally + showmatch=true, -- Highlight matching braces + --git integration/lsp/diagnostic + signcolumn="yes", + --undo/backup + backup=false, + swapfile=false, + undodir=os.getenv("HOME") .. "/.local/state/nvim/undodir", + undofile=true +-- showbreak="+++", -- wrap broken line prefix +} +--forloop for table 'options' +for key, value in pairs(options) do + vim.opt[key] = value +end + +--to 'cw/'dw' a word containing '-' in between +vim.cmd [[set iskeyword+=-]] diff --git a/.config/nvim/lua/justsaumit/plugins.lua b/.config/nvim/lua/justsaumit/plugins.lua new file mode 100644 index 0000000..6a34a50 --- /dev/null +++ b/.config/nvim/lua/justsaumit/plugins.lua @@ -0,0 +1,97 @@ +local fn = vim.fn + +-- Automatically install packer +local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim" +if fn.empty(fn.glob(install_path)) > 0 then + PACKER_BOOTSTRAP = fn.system { + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + } + print "Installing packer close and reopen Neovim..." + vim.cmd [[packadd packer.nvim]] +end + +-- Autocommand that reloads neovim whenever you save (:w) the plugins.lua file +vim.cmd [[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]] + +-- Use a protected call so we don't error out! +local status_ok, packer = pcall(require, "packer") +if not status_ok then + return +end + +-- Have packer use a popup window +packer.init { + display = { + open_fn = function() + return require("packer.util").float { border = "rounded" } + end, + }, +} + +--Actual good stuff +--Install all your plugins here +return packer.startup(function(use) +--Necessities + use "wbthomason/packer.nvim" -- Have packer manage itself + use "nvim-lua/popup.nvim" -- An implementation of the Popup API from vim in Neovim + use "nvim-lua/plenary.nvim" -- Useful lua functions used ny lots of plugins + use "ethanholz/nvim-lastplace" -- Preserve last editing position in nvim +--TreeSitter + use {'nvim-treesitter/nvim-treesitter',run = ':TSUpdate'} +--ColorSchemes + use "folke/tokyonight.nvim" + use "tiagovla/tokyodark.nvim" + use { 'AlphaTechnolog/pywal.nvim', as = 'pywal' } +--Web-devicons + use "kyazdani42/nvim-web-devicons" +--Lualine + use {'nvim-lualine/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true }} +--Bufferline + use {'akinsho/bufferline.nvim', tag = "v2.*", requires = 'kyazdani42/nvim-web-devicons'} +--Nvim-tree File explorer for nvim + use {'nvim-tree/nvim-tree.lua', requires = { 'nvim-tree/nvim-web-devicons'}} +--Whick-key - displays a popup with possible key bindings + use 'folke/which-key.nvim' +--HTML +-- use 'windwp/nvim-ts-autotag' +--Markdown + Zenmode +--Telescope +-- use {'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = { {'nvim-lua/plenary.nvim'} }} +--cmp +-- use 'hrsh7th/nvim-cmp' +--cmp plugins +-- use 'hrsh7th/cmp-buffer' +-- use 'hrsh7th/cmp-path' +-- use 'hrsh7th/cmp-cmdline' +-- use 'hrsh7th/cmp-nvim-lsp' + -- use 'neovim/nvim-lspconfig' + +-- use "saadparwaiz1/cmp_luasnip" -- snippet completions + + -- snippets +-- use "L3MON4D3/LuaSnip" --snippet engine +-- use "rafamadriz/friendly-snippets" -- a bunch of snippets to use + +--Autopairs for HTML + --use {"windwp/nvim-autopairs", wants = "nvim-treesitter", module = { "nvim-autopairs.completion.cmp", "nvim-autopairs" }, config = function() + --require("config.autopairs").setup() end,} +--CSS + use 'NvChad/nvim-colorizer.lua' + + +-- Automatically set up your configuration after cloning packer.nvim +-- Put this at the end after all plugins + if PACKER_BOOTSTRAP then + require("packer").sync() + end +end) diff --git a/.config/nvim/lua/justsaumit/treesitter-config.lua b/.config/nvim/lua/justsaumit/treesitter-config.lua new file mode 100644 index 0000000..17dbc62 --- /dev/null +++ b/.config/nvim/lua/justsaumit/treesitter-config.lua @@ -0,0 +1,20 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" + ensure_installed = { "bash", "c", "cpp","lua", "rust", "python", "go","html", "javascript", "latex", "markdown", "solidity", "sxhkdrc" }, + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + auto_install = true, + + -- List of parsers to ignore installing (for "all") + highlight = { + -- `false` will disable the whole extension + enable = true, + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + autotag = { + enable = true, + } +} diff --git a/.config/nvim/lua/justsaumit/which-key-config.lua b/.config/nvim/lua/justsaumit/which-key-config.lua new file mode 100644 index 0000000..b438f7e --- /dev/null +++ b/.config/nvim/lua/justsaumit/which-key-config.lua @@ -0,0 +1,11 @@ +local wk = require("which-key") +local mappings = { + q = {":q", "Quit"}, + Z = {":wq", "Save and Quit"}, + w = {":w", "Save"}, + x ={":bdelete", "Close"}, + f = { ":Telescope find_files", "Telescope Find Files" }, + g = { ":Telescope live_grep", "Telescope Live Grep" } +} +local opts = {prefix = ''} +wk.register(mappings, opts) -- cgit v1.2.3