From 0c6103c6f219f8c773e6ab73c272021d385f4bda Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Fri, 18 Nov 2022 12:57:13 -0500 Subject: [PATCH] use jetbrainsmono font to enable luatree with dev icons --- .config/kitty/kitty.conf | 2 +- .config/nvim/init.lua | 115 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/.config/kitty/kitty.conf b/.config/kitty/kitty.conf index 0b187f2..fe3417d 100644 --- a/.config/kitty/kitty.conf +++ b/.config/kitty/kitty.conf @@ -6,7 +6,7 @@ #: individual font faces and even specify special fonts for particular #: characters. -font_family Source Code Pro for Powerline +font_family JetBrainsMono Nerd Font # bold_font auto # italic_font auto # bold_italic_font auto diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 386cd13..fb7c967 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,4 +1,6 @@ -- Basics +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 vim.g.mapleader = " " vim.opt.incsearch = true vim.opt.hlsearch = true @@ -23,12 +25,10 @@ vim.call('plug#begin', '~/.config/nvim/plugged') Plug 'tpope/vim-sensible' -- some good default configs, we love tpope :) Plug 'tpope/vim-surround' -- add surround motion (s), example: to change the surrounding double quotes to single quotes type: cs"' Plug 'tpope/vim-repeat' -Plug('scrooloose/nerdtree', { on = { 'NERDTreeToggle', 'NERDTree' } }) -- file browser Plug 'junegunn/goyo.vim' -- zen mode Plug('junegunn/fzf', { ['do'] = vim.fn['fzf#install'] }) Plug('nvim-treesitter/nvim-treesitter', { ['do'] = vim.fn['TSUpdate'] }) -- add support for text objects Plug 'JoosepAlviste/nvim-ts-context-commentstring' -Plug 'tiagofumo/vim-nerdtree-syntax-highlight' -- Plug 'ctrlpvim/ctrlp.vim' -- minimal fuzzyfinder Plug 'wadackel/vim-dogrun' -- colorscheme Plug 'tribela/vim-transparent' -- clear background @@ -42,6 +42,8 @@ Plug 'kshenoy/vim-signature' Plug 'phaazon/hop.nvim' Plug 'terrortylor/nvim-comment' Plug 'dense-analysis/ale' -- async runtime for formatting +Plug 'nvim-tree/nvim-tree.lua' +Plug 'nvim-tree/nvim-web-devicons' --Plug 'kyazdani42/nvim-web-devicons' --Plug('akinsho/bufferline.nvim', { ['tag'] = 'v3.*' }) @@ -270,12 +272,107 @@ local on_attach = function(_, bufnr) vim.keymap.set('n', 'F', vim.lsp.buf.formatting, bufopts) end --- Auto-exit if it is the last buffer open -vim.api.nvim_create_autocmd( - { "BufEnter" }, - { pattern = { "*" }, - command = "if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif" } -) +-- setup file browser +require'nvim-web-devicons'.setup { + -- your personnal icons can go here (to override) + -- you can specify color or cterm_color instead of specifying both of them + -- DevIcon will be appended to `name` + -- override = { + -- zsh = { + -- icon = "", + -- color = "#428850", + -- cterm_color = "65", + -- name = "Zsh" + -- } + -- }; + -- globally enable different highlight colors per icon (default to true) + -- if set to false all icons will have the default icon's color + color_icons = true; + -- globally enable default icons (default to false) + -- will get overriden by `get_icons` option + default = true; +} +local lib = require("nvim-tree.lib") +local view = require("nvim-tree.view") + +local git_add = function() + local node = lib.get_node_at_cursor() + local gs = node.git_status + + -- If the file is untracked, unstaged or partially staged, we stage it + if gs == "??" or gs == "MM" or gs == "AM" or gs == " M" then + vim.cmd("silent !git add " .. node.absolute_path) + + -- If the file is staged, we unstage + elseif gs == "M " or gs == "A " then + vim.cmd("silent !git restore --staged " .. node.absolute_path) + end + + lib.refresh_tree() +end +local function collapse_all() + require("nvim-tree.actions.tree-modifiers.collapse-all").fn() +end + +local function edit_or_open() + -- open as vsplit on current node + local action = "edit" + local node = lib.get_node_at_cursor() + + -- Just copy what's done normally with vsplit + if node.link_to and not node.nodes then + require('nvim-tree.actions.node.open-file').fn(action, node.link_to) + view.close() -- Close the tree if file was opened + + elseif node.nodes ~= nil then + lib.expand_or_collapse(node) + + else + require('nvim-tree.actions.node.open-file').fn(action, node.absolute_path) + view.close() -- Close the tree if file was opened + end + +end + +local function vsplit_preview() + -- open as vsplit on current node + local action = "vsplit" + local node = lib.get_node_at_cursor() + + -- Just copy what's done normally with vsplit + if node.link_to and not node.nodes then + require('nvim-tree.actions.node.open-file').fn(action, node.link_to) + + elseif node.nodes ~= nil then + lib.expand_or_collapse(node) + + else + require('nvim-tree.actions.node.open-file').fn(action, node.absolute_path) + + end + + -- Finally refocus on tree if it was lost + view.focus() +end +require("nvim-tree").setup({ + view = { + mappings = { + custom_only = false, + list = { + { key = "l", action = "edit", action_cb = edit_or_open }, + { key = "L", action = "vsplit_preview", action_cb = vsplit_preview }, + { key = "h", action = "close_node" }, + { key = "H", action = "collapse_all", action_cb = collapse_all }, + { key = "ga", action = "git_add", action_cb = git_add }, + } + }, + }, + actions = { + open_file = { + quit_on_open = false + } + } +}) require("nvim-lsp-installer").setup { automatic_installation = false @@ -455,7 +552,7 @@ vim.cmd [[let g:ale_linters_ignore = { -- keymaps local loud_opts = { noremap = true } vim.keymap.set("n", "", ":wa:echo 'File saved.'", loud_opts) -vim.keymap.set("n", "", ":NERDTreeToggle", opts) +vim.api.nvim_set_keymap("n", "", ":NvimTreeToggle" ,{silent = true, noremap = true}) vim.keymap.set("n", "tt", ":TransparentToggle", opts) vim.keymap.set("n", "tzz", ":Goyo", opts) vim.keymap.set("n", "tzw", ":Goyo 160", opts)