Skip to content

Commit

Permalink
init self
Browse files Browse the repository at this point in the history
  • Loading branch information
subratappt committed Mar 1, 2024
0 parents commit 4500bb7
Show file tree
Hide file tree
Showing 27 changed files with 1,123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!*.lua
!**/**/
!.gitignore
6 changes: 6 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require("core.keymaps")
require("core.options")
require("lazysetup")

-- Design a custom status line
require("core.statusline")
12 changes: 12 additions & 0 deletions lua/core/keymaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- set leader key
vim.g.mapleader = " "

local keymap = vim.keymap

-- General keymaps
keymap.set("i", "jj", "<Esc>", {
desc = "jj to escape"
})
keymap.set("i", "jk", "<Esc>", {
desc = "jk to escape"
})
49 changes: 49 additions & 0 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local opt = vim.opt -- for conciseness

-- line numbers
opt.relativenumber = true -- show relative line numbers
opt.number = true -- shows absolute line number on cursor line (when relative number is on)

-- tabs & indentation
opt.tabstop = 2 -- 2 spaces for tabs (prettier default)
opt.shiftwidth = 2 -- 2 spaces for indent width
opt.expandtab = true -- expand tab to spaces
opt.autoindent = true -- copy indent from current line when starting new one

-- line wrapping
opt.wrap = false -- disable line wrapping

-- search settings
opt.ignorecase = true -- ignore case when searching
opt.smartcase = true -- if you include mixed case in your search, assumes you want case-sensitive

-- cursor line
opt.cursorline = true -- highlight the current cursor line

-- appearance

-- turn on termguicolors for nightfly colorscheme to work
-- (have to use iterm2 or any other true color terminal)
opt.termguicolors = true
opt.background = "dark" -- colorschemes that can be light or dark will be made dark
opt.signcolumn = "yes" -- show sign column so that text doesn't shift

-- backspace
opt.backspace = "indent,eol,start" -- allow backspace on indent, end of line or insert mode start position

-- clipboard
opt.clipboard:append("unnamedplus") -- use system clipboard as default register

-- split windows
opt.splitright = true -- split vertical window to the right
opt.splitbelow = true -- split horizontal window to the bottom

-- turn off swapfile
opt.swapfile = false

-- remove tilde on end of buffer
opt.fillchars = {
eob = " "
}

opt.ruler = false -- disable ruler
223 changes: 223 additions & 0 deletions lua/core/statusline.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
local modes = {
["n"] = "N",
["no"] = "N",
["v"] = "V",
["V"] = "VL",
[""] = "VB",
["s"] = "S",
["S"] = "SL",
[""] = "SB",
["i"] = "I",
["ic"] = "I",
["R"] = "R",
["Rv"] = "VR",
["c"] = "COMMAND",
["cv"] = "VIM EX",
["ce"] = "EX",
["r"] = "PROMPT",
["rm"] = "MOAR",
["r?"] = "CONFIRM",
["!"] = "SHELL",
["t"] = "T"
}

vim.cmd("highlight StatusLineNormal guifg=#038e18")
vim.cmd("highlight StatusLineVisual guifg=#17508e")
vim.cmd("highlight StatusLineInsert guifg=#cd2e2e")
vim.cmd("highlight StatusLineReplace guifg=#b98d0a")
vim.cmd("highlight StatusLineCmdLine guifg=#377690")
vim.cmd("highlight StatusLineTerminal guifg=#941358")
vim.cmd("highlight StatusLineExtra guifg=#c6ab52")

vim.cmd("highlight LspDiagnosticsSignError guifg=#991313")
vim.cmd("highlight LspDiagnosticsSignWarning guifg=#c49213")
vim.cmd("highlight LspDiagnosticsSignHint guifg=#13c9a1")
vim.cmd("highlight LspDiagnosticsSignInformation guifg=#1399c4")

local function mode()
local current_mode = vim.api.nvim_get_mode().mode
return string.format(" %s ", modes[current_mode]):upper()
end
local function update_mode_colors()
local current_mode = vim.api.nvim_get_mode().mode
local mode_color = "%#StatusLineNormal#"
if current_mode == "n" then
mode_color = "%#StatuslineNormal#"
elseif current_mode == "i" or current_mode == "ic" then
mode_color = "%#StatuslineInsert#"
elseif current_mode == "v" or current_mode == "V" or current_mode == "" then
mode_color = "%#StatuslineVisual#"
elseif current_mode == "R" then
mode_color = "%#StatuslineReplace#"
elseif current_mode == "c" then
mode_color = "%#StatuslineCmdLine#"
elseif current_mode == "t" then
mode_color = "%#StatuslineTerminal#"
end
return mode_color
end

local function filepath()
local fpath = vim.fn.fnamemodify(vim.fn.expand("%"), ":~:.:h")
if fpath == "" or fpath == "." then
return " "
end
return string.format(" %%<%s/", fpath)
end

local function filename()
local fname = vim.fn.expand("%:t")
if fname == "" then
return ""
end
return fname .. " "
end

local function lsp()
local count = {}
local levels = {
errors = "Error",
warnings = "Warn",
info = "Info",
hints = "Hint"
}
for k, level in pairs(levels) do
count[k] = vim.tbl_count(vim.diagnostic.get(0, {
severity = level
}))
end
local errors = ""
local warnings = ""
local hints = ""
local info = ""
if count["errors"] ~= 0 then
errors = " %#LspDiagnosticsSignError# " .. count["errors"]
end
if count["warnings"] ~= 0 then
warnings = " %#LspDiagnosticsSignWarning# " .. count["warnings"]
end
if count["hints"] ~= 0 then
hints = " %#LspDiagnosticsSignHint#💡 " .. count["hints"]
end
if count["info"] ~= 0 then
info = " %#LspDiagnosticsSignInformation# " .. count["info"]
end
return errors .. warnings .. hints .. info
end

local filetype_icons = {
["lua"] = "",
["python"] = "",
["javascript"] = "",
["typescript"] = "",
["html"] = "",
["css"] = "",
["json"] = "",
["yaml"] = "",
["markdown"] = "",
["sh"] = "",
["vim"] = "",
["java"] = "",
["c"] = "",
["cpp"] = "",
["haskell"] = "",
["rust"] = "",
["go"] = "",
["php"] = "",
["ruby"] = ""
-- add more filetypes and their corresponding icons here...
}

local function filetype_with_icon()
local filetype = vim.bo.filetype
local icon = filetype_icons[filetype] or "󰈙"
return icon .. " " .. filetype
end

local function filetype_only_icon()
local filetype = vim.bo.filetype
local icon = filetype_icons[filetype] or "󰈙"
return icon
end

local function filetype()
return string.format(" %s ", vim.bo.filetype):upper()
end

local function lineinfo()
if vim.bo.filetype == "alpha" then
return ""
end
return " %P %l:%c "
end
local vcs = function()
local git_info = vim.b.gitsigns_status_dict
if not git_info or git_info.head == "" then
return ""
end
local added = git_info.added and ("%#GitSignsAdd#+" .. git_info.added .. " ") or ""
local changed = git_info.changed and ("%#GitSignsChange#~" .. git_info.changed .. " ") or ""
local removed = git_info.removed and ("%#GitSignsDelete#-" .. git_info.removed .. " ") or ""
if git_info.added == 0 then
added = ""
end
if git_info.changed == 0 then
changed = ""
end
if git_info.removed == 0 then
removed = ""
end
return table.concat({
" ",
"%#GitSignsAdd# ",
git_info.head,
" ",
added,
changed,
removed
})
end
Statusline = {}
Statusline.active = function()
return table.concat({
"%#Statusline#",
update_mode_colors(),
mode(),
"%#Normal# ",
filetype_only_icon(),
filepath(),
filename(),
"%#Normal#",
vcs(),
"%#Normal# ",
lsp(),
"%#Normal# ",
"%=",
-- filetype_with_icon(),
"%#StatusLineExtra#",
lineinfo()
})
end
function Statusline.inactive()
return " %F"
end
function Statusline.short()
return " NvimTree"
end
function Statusline.terminal()
return " Terminal"
end

vim.api.nvim_exec([[
augroup Statusline
au!
au WinEnter,BufEnter * setlocal statusline=%!v:lua.Statusline.active()
au WinLeave,BufLeave * setlocal statusline=%!v:lua.Statusline.inactive()
au WinEnter,BufEnter,FileType NvimTree_* setlocal statusline=%!v:lua.Statusline.short()
au TermOpen * setlocal statusline=%!v:lua.Statusline.terminal()
augroup END
]], false)

-- vim.api.nvim_exec([[
-- au BufEnter,BufWinEnter,WinEnter,CmdwinEnter * if bufname('%') == "NvimTree_1" | set laststatus=0 | else | set laststatus=2 | endif
-- ]], false)
14 changes: 14 additions & 0 deletions lua/lazysetup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not 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").setup({{import="plugins"},{import="plugins.lsp"}})
13 changes: 13 additions & 0 deletions lua/plugins/bufferline.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
"akinsho/bufferline.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons"
},
version = "*",
opts = {
options = {
mode = "tabs",
separator_style = "thin"
}
}
}
16 changes: 16 additions & 0 deletions lua/plugins/colorscheme.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local M = {
-- "bluz71/vim-nightfly-guicolors",
"catppuccin/nvim",
name = "catppuccin",
priority = 1000,
config = function()
require("catppuccin").setup({
transparent_background = true
})
vim.cmd("colorscheme catppuccin") -- catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha
-- vim.cmd(
-- "highlight Normal guibg=NONE ctermbg=NONE | highlight LineNr guibg=NONE ctermbg=NONE | highlight CursorLineNr guibg=NONE ctermbg=NONE | highlight EndOfBuffer guibg=NONE ctermbg=NONE | highlight SignColumn guibg=NONE ctermbg=NONE")
end
}

return M
20 changes: 20 additions & 0 deletions lua/plugins/comment.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- add this to your lua/plugins.lua, lua/plugins/init.lua, or the file you keep your other plugins:
return {
'numToStr/Comment.nvim',
event = {
"BufReadPre",
"BufNewFile"
},
config = function()
require('Comment').setup({
ignore = '^$',
toggler = {
line = '<leader>/'
},
opleader = {
line = '<leader>/'
}
})
end

}
Loading

0 comments on commit 4500bb7

Please sign in to comment.