diff --git a/init.lua b/init.lua index 13b4fe9..49bc3ed 100644 --- a/init.lua +++ b/init.lua @@ -1,26 +1,9 @@ -require "options" - local chad_modules = { - "pluginList", - "plugins.bufferline", + "options", "mappings", "utils" } -local async -async = - vim.loop.new_async( - vim.schedule_wrap( - function() - for i = 1, #chad_modules, 1 do - local ok, res = xpcall(require, debug.traceback, chad_modules[i]) - if not (ok) then - print("Error loading module : " .. chad_modules[i]) - print(res) -- print stack traceback of the error - end - end - async:close() - end - ) -) -async:send() +for i = 1, #chad_modules, 1 do + pcall(require, chad_modules[i]) +end diff --git a/install.sh b/install.sh index 84b5e8d..9f7b382 100755 --- a/install.sh +++ b/install.sh @@ -21,7 +21,7 @@ _check_install_dependencies() { printf "%s\n" "Error: Install ${1} before proceeding." exit 1 } - _GIT="$(command -v git)" || _error_dependencies git + command -v git 1>/dev/null || _error_dependencies git _SED="$(command -v sed)" || _error_dependencies sed return 0 } @@ -71,26 +71,29 @@ _setup_terminal_shell() { _mappings_file="${_CONFIG_PATH}/lua/mappings.lua" # only ask for shellname if running in terminal if [ -t 1 ]; then - printf "\n%s\n" "Which shell do you want to use? (Eg. 2)" - printf "\t%s\n" "[ Enter nothing for current shell ( $_CURRENT_SHELL ) ]" - grep '^/bin/' '/etc/shells' | nl - read -r shellNUM + if chsh -l 2>/dev/null 1>&2; then + printf "\nAvailable Shells:\n" + chsh -l | nl + printf "\n%s\n" "Which shell do you want to use? (Eg. 2)" + printf "\t%s\n" "[ Enter nothing for current shell ( $_CURRENT_SHELL ) ]" + read -r shellnum + [ "${shellnum}" -gt 0 ] 2>/dev/null && _SHELLPATH="$(chsh -l | sed -n "$shellnum p")" + fi fi # don't try to do any changes user wants their default shell in nvim - if [ -n "$shellNUM" ]; then - shellpath=$(grep '^/bin/' '/etc/shells' | sed -n "$shellNUM p") + if [ -n "$_SHELLPATH" ]; then # Reference: https://stackoverflow.com/a/4247319 # \( & \) will use regex brackets (for later reference with \1) # ( & ) will match text brackets - if "${_SED}" --posix -i'.bak' -e "s=^\(map(.* \+*terminal\) \(.*)\)=\1$shellpath \2=g" "${_mappings_file}"; then - printf "%s\n" "=> Neovim shell changed to $shellpath successfully!" + if "${_SED}" --posix -i'.bak' -e "s=^\(map(.* \+*terminal\) \(.*)\)=\1$_SHELLPATH \2=g" "${_mappings_file}"; then + printf "%s\n" "=> Neovim shell changed to $_SHELLPATH successfully!" else - printf "%s\n" "Cannot edit with sed, edit ${_mappings_file} manually to replace bash with $shellpath." + printf "%s\n" "Cannot edit with sed, edit ${_mappings_file} manually to replace bash with $_SHELLPATH." fi rm -f "${_mappings_file}".bak # delete backup file created by sed fi - printf "%s\n\n" "=> Neovim shell will be ${shellpath:-${_CURRENT_SHELL}}" + printf "%s\n" "=> Neovim shell will be ${_SHELLPATH:-${_CURRENT_SHELL}}" return 0 } _setup_arguments() { diff --git a/lua/highlights.lua b/lua/highlights.lua index 08ad42b..42255d5 100644 --- a/lua/highlights.lua +++ b/lua/highlights.lua @@ -115,6 +115,5 @@ bg("NormalFloat", black2) bg("FloatBorder", black2) fg("FloatBorder", black2) --- set bg color for nvim ( so nvim wont use terminal bg) - -bg("Normal", black) +-- set bg color for nvim +-- bg("Normal", black) diff --git a/lua/mappings.lua b/lua/mappings.lua index f5cb5ea..364a021 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -18,24 +18,27 @@ map("v", "x", [=[ "_x ]=], opt) this line too ]] -- --- escape with 'jk' mapping -vim.api.nvim_set_keymap("i", "jk", "", {}) -vim.api.nvim_set_keymap("v", "jk", "", {}) -vim.api.nvim_set_keymap("t", "jk", "", {}) - -- Don't copy the replaced text after pasting in visual mode map("v", "p", '"_dP', opt) +-- Allow moving the cursor through wrapped lines with j, k, and +-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ +-- empty mode is same as using :map +map("", "j", 'v:count ? "j" : "gj"', {expr = true}) +map("", "k", 'v:count ? "k" : "gk"', {expr = true}) +map("", "", 'v:count ? "j" : "gj"', {expr = true}) +map("", "", 'v:count ? "k" : "gk"', {expr = true}) + -- OPEN TERMINALS -- -map("n", "", [[ vnew +terminal | setlocal nobuflisted ]], opt) -- term over right -map("n", "", [[ 10new +terminal | setlocal nobuflisted ]], opt) -- term bottom -map("n", "t", [[ terminal ]], opt) -- term buffer +map("n", "", ":vnew +terminal | setlocal nobuflisted ", opt) -- term over right +map("n", "", ":10new +terminal | setlocal nobuflisted ", opt) -- term bottom +map("n", "t", ": terminal ", opt) -- term buffer -- copy whole file content -map("n", "", [[ %y+]], opt) +map("n", "", ":%y+", opt) -- toggle numbers -map("n", "n", [[ set nu!]], opt) +map("n", "n", ":set nu!", opt) -- Truezen.nvim map("n", "zz", ":TZAtaraxis", opt) @@ -113,24 +116,24 @@ map("i", "", "v:lua.completions()", {expr = true}) map("n", "", ":NvimTreeToggle", opt) -- format code -map("n", "fm", [[ Neoformat]], opt) +map("n", "fm", ":Neoformat", opt) -- dashboard stuff -map("n", "fw", [[ Telescope live_grep]], opt) -map("n", "db", [[ Dashboard]], opt) -map("n", "fn", [[ DashboardNewFile]], opt) -map("n", "bm", [[ DashboardJumpMarks]], opt) -map("n", "l", [[ SessionLoad]], opt) -map("n", "s", [[ SessionSave]], opt) +map("n", "db", ":Dashboard", opt) +map("n", "fn", ":DashboardNewFile", opt) +map("n", "bm", ":DashboardJumpMarks", opt) +map("n", "l", ":SessionLoad", opt) +map("n", "s", ":SessionSave", opt) -- Telescope -map("n", "gt", [[ Telescope git_status ]], opt) -map("n", "cm", [[ Telescope git_commits ]], opt) -map("n", "ff", [[ Telescope find_files ]], opt) -map("n", "fp", [[lua require('telescope').extensions.media_files.media_files()]], opt) -map("n", "fb", [[Telescope buffers]], opt) -map("n", "fh", [[Telescope help_tags]], opt) -map("n", "fo", [[Telescope oldfiles]], opt) +map("n", "fw", ":Telescope live_grep", opt) +map("n", "gt", ":Telescope git_status ", opt) +map("n", "cm", ":Telescope git_commits ", opt) +map("n", "ff", ":Telescope find_files ", opt) +map("n", "fp", ":Telescope media_files ", opt) +map("n", "fb", ":Telescope buffers", opt) +map("n", "fh", ":Telescope help_tags", opt) +map("n", "fo", ":Telescope oldfiles", opt) -- bufferline tab stuff map("n", "", ":enew", opt) -- new buffer @@ -138,11 +141,24 @@ map("n", "b", ":tabnew", opt) -- new tab map("n", "", ":bd!", opt) -- close tab -- move between tabs -map("n", "", [[BufferLineCycleNext]], opt) -map("n", "", [[BufferLineCyclePrev]], opt) +map("n", "", ":BufferLineCycleNext", opt) +map("n", "", ":BufferLineCyclePrev", opt) -- use ESC to turn off search highlighting map("n", "", ":noh", opt) -- get out of terminal with jk map("t", "jk", "", opt) + +-- Packer commands till because we are not loading it at startup +vim.cmd("silent! command PackerCompile lua require 'pluginList' require('packer').compile()") +vim.cmd("silent! command PackerInstall lua require 'pluginList' require('packer').install()") +vim.cmd("silent! command PackerStatus lua require 'pluginList' require('packer').status()") +vim.cmd("silent! command PackerSync lua require 'pluginList' require('packer').sync()") +vim.cmd("silent! command PackerUpdate lua require 'pluginList' require('packer').update()") + +-- Vim Fugitive +map("n", "gs", ":Git", opt) +map("n", "gh", ":diffget //2", opt) +map("n", "gl", ":diffget //3", opt) +map("n", "gb", ":Git blame", opt) diff --git a/lua/options.lua b/lua/options.lua index 704a4e8..a8ad934 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,13 +1,6 @@ local opt = vim.opt local g = vim.g --- Turn these off at startup, will be enabled later just before loading the theme -vim.cmd([[ - syntax off - filetype off - filetype plugin indent off -]]) - opt.ruler = false opt.hidden = true opt.ignorecase = true @@ -71,9 +64,5 @@ for _, plugin in pairs(disabled_built_ins) do vim.g["loaded_" .. plugin] = 1 end -local M = {} - -- file extension specific tabbing -- vim.cmd([[autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4]]) - -return M diff --git a/lua/pluginList.lua b/lua/pluginList.lua index 56f197f..b7b79d8 100644 --- a/lua/pluginList.lua +++ b/lua/pluginList.lua @@ -16,9 +16,20 @@ return packer.startup( event = "VimEnter" } + use { + "jdhao/better-escape.vim", + event = "InsertEnter", + config = function() + require "plugins.others".escape() + end + } + use { "akinsho/nvim-bufferline.lua", - after = "nvim-base16.lua" + after = "nvim-base16.lua", + config = function() + require "plugins.bufferline" + end } use { @@ -195,7 +206,7 @@ return packer.startup( } use { - "tweekmonster/startuptime.vim", + "dstein64/vim-startuptime", cmd = "StartupTime" } @@ -240,5 +251,12 @@ return packer.startup( require("plugins.others").blankline() end } + + use { + "tpope/vim-fugitive", + cmd = { + "Git" + } + } end ) diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index 8e94849..18c07ae 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -104,12 +104,14 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { - -- prefix = "", prefix = "", spacing = 0 }, signs = true, - underline = true + underline = true, + + -- set this to true if you want diagnostics to show in insert mode + update_in_insert = false } ) diff --git a/lua/plugins/others.lua b/lua/plugins/others.lua index 2278d09..0a060a6 100644 --- a/lua/plugins/others.lua +++ b/lua/plugins/others.lua @@ -15,6 +15,11 @@ M.comment = function() end end +M.escape = function() + vim.g.better_escape_interval = 300 + vim.g.better_escape_shortcut = {"jk"} +end + M.lspkind = function() local present, lspkind = pcall(require, "lspkind") if present then diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua index 8f543c8..07af61e 100644 --- a/lua/plugins/statusline.lua +++ b/lua/plugins/statusline.lua @@ -117,7 +117,14 @@ gls.right[1] = { provider = function() local clients = vim.lsp.get_active_clients() if next(clients) ~= nil then - return " " .. "  " .. " LSP " + local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return " " .. "  " .. " LSP " + end + end + return "" else return "" end diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 26f97e7..915689f 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -79,5 +79,6 @@ if print("After completion of PackerSync, restart neovim.") -- Trigger packer compile on PackerComplete, so it properly waits for PackerSync vim.cmd 'autocmd User PackerComplete ++once lua require("packer").compile()' + require "pluginList" require("packer").sync("telescope-fzf-native.nvim", "telescope-media-files.nvim") end diff --git a/lua/theme.lua b/lua/theme.lua index 85bf895..5356706 100644 --- a/lua/theme.lua +++ b/lua/theme.lua @@ -3,13 +3,6 @@ vim.g.nvchad_theme = "onedark" local present, base16 = pcall(require, "base16") if present then - -- enabled these options, was disabled in options.lua - vim.cmd([[ - syntax on - filetype on - filetype plugin indent on - ]]) - base16(base16.themes["onedark"], true) require "highlights" return true diff --git a/lua/themes/javacafe.lua b/lua/themes/javacafe.lua new file mode 100644 index 0000000..5785290 --- /dev/null +++ b/lua/themes/javacafe.lua @@ -0,0 +1,33 @@ +local colors = { + white = "#b5bcc9", + darker_black = "#10171e", + black = "#131a21", -- nvim bg + black2 = "#1a2128", + one_bg = "#1e252c", + one_bg2 = "#272e35", + one_bg3 = "#2a3138", + grey = "#363d44", + grey_fg = "#4e555c", + grey_fg2 = "#51585f", + light_grey = "#545b62", + red = "#ef8891", + baby_pink = "#fca2aa", + pink = "#fca2af", + line = "#20272e", -- for lines like vertsplit + green = "#9ce5c0", + vibrant_green = "#a5d4af", + blue = "#99aee5", + nord_blue = "#9aa8cf", + yellow = "#fbdf90", + sun = "#fbdf9a", + purple = "#d7c1ed", + dark_purple = "#ccaced", + teal = "#92dbb6", + orange = "#EDA685", + cyan = "#b5c3ea", + statusline_bg = "#181f26", + lightbg = "#222930", + lightbg2 = "#1d242b" +} + +return colors diff --git a/lua/utils.lua b/lua/utils.lua index f829114..271928b 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -1,8 +1,7 @@ -- hide line numbers , statusline in specific buffers! vim.api.nvim_exec( [[ - au TermOpen term://* setlocal nonumber laststatus=0 - au TermClose term://* bd! + au TermOpen term://* setlocal nonumber laststatus=0 au BufEnter,BufWinEnter,WinEnter,CmdwinEnter * if bufname('%') == "NvimTree" | set laststatus=0 | else | set laststatus=2 | endif ]], false