From 18edf9861d1b38591b51b42465b224d77736db04 Mon Sep 17 00:00:00 2001 From: listout Date: Tue, 2 Aug 2022 01:10:05 +0530 Subject: nvim: moving init to lua Signed-off-by: listout --- lua/core/appearance.lua | 52 ++++++++++++++++++++++++++++ lua/core/colorscheme.lua | 10 ++++++ lua/core/keymaps.lua | 52 ++++++++++++++++++++++++++++ lua/core/options.lua | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ lua/core/settings.lua | 19 +++++++++++ lua/core/utils.lua | 17 +++++++++ 6 files changed, 239 insertions(+) create mode 100644 lua/core/appearance.lua create mode 100644 lua/core/colorscheme.lua create mode 100644 lua/core/keymaps.lua create mode 100644 lua/core/options.lua create mode 100644 lua/core/settings.lua create mode 100644 lua/core/utils.lua (limited to 'lua/core') diff --git a/lua/core/appearance.lua b/lua/core/appearance.lua new file mode 100644 index 0000000..452c4b9 --- /dev/null +++ b/lua/core/appearance.lua @@ -0,0 +1,52 @@ +local opt = vim.opt -- Set options (global/buffer/windows-scoped) + +----------------------------------------------------------- +-- Neovim UI +----------------------------------------------------------- +opt.number = true -- Show line number +opt.relativenumber = true -- Show relative line number +opt.showmatch = true -- Highlight matching parenthesis +opt.foldmethod = 'marker' -- Enable folding (default 'foldmarker') +opt.splitright = true -- Vertical split to the right +opt.splitbelow = true -- Horizontal split to the bottom +opt.ignorecase = true -- Ignore case letters when search +opt.smartcase = true -- Ignore lowercase for the whole pattern +opt.linebreak = true -- Wrap on word boundary +opt.termguicolors = true -- Enable 24-bit RGB colors +opt.laststatus = 2 -- Set global statusline +opt.splitbelow = true +opt.splitright = true +opt.scrolloff = 2 +opt.sidescrolloff = 5 +opt.foldlevelstart = 99 +opt.ruler = false +opt.list = true +opt.showtabline = 0 +opt.winwidth = 30 +opt.winminwidth = 10 +opt.pumheight = 15 +opt.helpheight = 12 +opt.previewheight = 12 +opt.showcmd = false +opt.listchars = 'tab:▸ ,extends:›,precedes:‹,nbsp:·,trail:·' +opt.background = 'dark' +opt.cmdheight = 2 +opt.fillchars = { + diff = "╱", + vert = "│", + fold = "⠀", + eob = " ", -- suppress ~ at EndOfBuffer + --diff = "⣿", -- alternatives = ⣿ ░ ─ ╱ + msgsep = "‾", + foldopen = "▾", + foldsep = "│", + foldclose = "▸", +} + +vim.cmd [[ + " Function, identifier and comments in italic + highlight Function cterm=italic gui=italic + highlight Indentifier cterm=none gui=italic + highlight Comment cterm=italic gui=italic +]] + diff --git a/lua/core/colorscheme.lua b/lua/core/colorscheme.lua new file mode 100644 index 0000000..f8c782b --- /dev/null +++ b/lua/core/colorscheme.lua @@ -0,0 +1,10 @@ +-- Config in lua +vim.g.nord_contrast = true +vim.g.nord_borders = true +vim.g.nord_disable_background = false +vim.g.nord_italic = true +vim.g.nord_uniform_diff_background = true + +-- Load the colorscheme +require('nord').set() +vim.cmd[[colorscheme nord]] diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 0000000..ca80862 --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,52 @@ +----------------------------------------------------------- +-- Define keymaps of Neovim and installed plugins. +----------------------------------------------------------- + +local function map(mode, lhs, rhs, opts) + local options = { noremap = true, silent = true } + if opts then + options = vim.tbl_extend('force', options, opts) + end + vim.api.nvim_set_keymap(mode, lhs, rhs, options) +end + +-- Change leader to a comma +vim.g.mapleader = ',' + +----------------------------------------------------------- +-- Neovim shortcuts +----------------------------------------------------------- + +-- Disable arrow keys +map('', '', '') +map('', '', '') +map('', '', '') +map('', '', '') + +-- Reload configuration without restart nvim +map('n', 'r', ':so %') + +-- Change split orientation +map('n', 'tk', 'tK') -- change vertical to horizontal +map('n', 'th', 'tH') -- change horizontal to vertical + +map('n', 'M-j', ':resize -2') +map('n', 'M-k', ':resize +2') +map('n', 'M-l', ':vertical resize -2') +map('n', 'M-h', ':vertical resize +2') + +map('t', 'C-w', '') + +map('n', 'b', ':Buffers'); +map('n', 'n', ':Files'); + +vim.cmd([[ + let $FZF_DEFAULT_COMMAND = "find * -path + \ '*/\.*' -prune -o -path 'node_modules/**' + \ -prune -o -path 'target/**' -prune -o -path + \'dist/**' -prune -o -type f -print -o -type + \ l -print 2> /dev/null" +]]) + +map('n', 'l', ':Buffers') + diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..6a5cc30 --- /dev/null +++ b/lua/core/options.lua @@ -0,0 +1,89 @@ +----------------------------------------------------------- +-- General Neovim settings and configuration +----------------------------------------------------------- + +local g = vim.g -- Global variables +local opt = vim.opt -- Set options (global/buffer/windows-scoped) +local cache_dir = os.getenv('HOME') .. '/.cache/nvim/' + +----------------------------------------------------------- +-- General +----------------------------------------------------------- +opt.mouse = 'a' -- Enable mouse support +opt.clipboard = 'unnamedplus' -- Copy/paste to system clipboard +opt.swapfile = false -- Don't use swapfile +opt.completeopt = 'menuone,noinsert,noselect' -- Autocomplete options +opt.history = 500 -- Lines vim should remember +opt.backup = false +opt.writebackup = false +opt.shell = 'zsh' +opt.magic = true -- Vim's regular expression magic +opt.mat = 2 -- How many tenths of seconds ro blink +opt.fileformats = 'unix,mac,dos' -- Unix as standard file format +opt.encoding = 'utf-8' -- Encoding +opt.viewoptions = 'folds,cursor,curdir,slash,unix' +opt.wildignorecase = true +opt.wildignore = + '.git,.hg,.svn,*.pyc,*.o,*.out,*.jpg,*.jpeg,*.png,*.gif,*.zip,**/tmp/**,*.DS_Store,**/node_modules/**,**/bower_modules/**' +opt.hlsearch = false -- No highlight search +opt.incsearch = true +opt.ignorecase = true +opt.backspace = 'indent,eol,start' + +----------------------------------------------------------- +-- Tabs, indent +----------------------------------------------------------- +opt.shiftwidth = 4 -- Shift 4 spaces when tab +opt.tabstop = 4 -- 1 tab == 4 spaces +opt.softtabstop = 4 -- 1 tab == 4 spaces +opt.expandtab = false -- Use spaces instead of tabs +opt.smartindent = true -- Autoindent new lines +opt.autoindent = true -- Copy indent from current line when starting new line +opt.cindent = true -- C programming indentation + +----------------------------------------------------------- +-- Memory, CPU +----------------------------------------------------------- +opt.hidden = true -- Enable background buffers +opt.lazyredraw = true -- Faster scrolling +opt.synmaxcol = 240 -- Max column for syntax highlight +opt.updatetime = 300 -- ms to wait for trigger an event +opt.timeoutlen = 500 -- ms to wait for a mapped sequence to complete. + +----------------------------------------------------------- +-- Startup +----------------------------------------------------------- +-- Disable nvim intro +opt.shortmess:append "csI" + +-- -- Disable builtin plugins +local disabled_built_ins = { + "2html_plugin", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "synmenu", + "optwin", + "compiler", + "bugreport", +} + +for _, plugin in pairs(disabled_built_ins) do + g["loaded_" .. plugin] = 1 +end diff --git a/lua/core/settings.lua b/lua/core/settings.lua new file mode 100644 index 0000000..20858b1 --- /dev/null +++ b/lua/core/settings.lua @@ -0,0 +1,19 @@ +-- +-- Mainly filetype settings +-- + +local cmd = vim.cmd +local u = require('core/utils') + +u.create_augroup({ + { 'BufRead,BufNewFile', '/tmp/nail-*', 'setlocal', 'ft=mail' }, + { 'BufRead,BufNewFile', '*s-nail-*', 'setlocal', 'ft=mail' }, + { 'BufRead,BufNewFile', '*mutt-*', 'setlocal', 'ft=mail' }, + { 'BufRead', '/tmp/*mutt-*', 'setlocal', 'tw=72' }, +}, 'ftmail') + +-- Autoremove unwanted whitespaces +cmd [[ + au BufWritePre * %s/\s\+$//e + au BufRead,BufNewFile *mutt-* setfiletype mail +]] diff --git a/lua/core/utils.lua b/lua/core/utils.lua new file mode 100644 index 0000000..7c8a7bf --- /dev/null +++ b/lua/core/utils.lua @@ -0,0 +1,17 @@ +-- +-- Auto group utilites +-- + +local M = {} +local cmd = vim.cmd + +function M.create_augroup(autocmds, name) + cmd('augroup ' .. name) + cmd('autocmd!') + for _, autocmd in ipairs(autocmds) do + cmd('autocmd ' .. table.concat(autocmd, ' ')) + end + cmd('augroup END') +end + +return M -- cgit v1.2.3