Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nvim-tree and oil for better file system interaction #34

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

require('options')
require('keymaps')
require('autocmds')
require('lazy-nvim')

vim.cmd[[ colorscheme tokyonight]]
7 changes: 7 additions & 0 deletions nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
"catppuccin": { "branch": "main", "commit": "048c18fc531703815f5e10765ea46ce9b2c75ae4" },
"fidget.nvim": { "branch": "main", "commit": "3a93300c076109d86c7ce35ec67a8034ae6ba9db" },
"gitsigns.nvim": { "branch": "main", "commit": "0a2a93f687ec051292943a4d139366332ac93688" },
"lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" },
"lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "3ba1b92b771f33256b4969d696b82c8ae7075364" },
"mason.nvim": { "branch": "main", "commit": "9c9416817c9f4e6f333c749327a1ed5355cfab61" },
"neodev.nvim": { "branch": "main", "commit": "64b2a51b02c6f2ae177c745e4d8bc801a339fe09" },
"nordtheme": { "branch": "main", "commit": "f13f5dfbb784deddbc1d8195f34dfd9ec73e2295" },
"nvim-lspconfig": { "branch": "master", "commit": "8917d2c830e04bf944a699b8c41f097621283828" },
"nvim-treesitter": { "branch": "master", "commit": "cd4e0909948eb33d3959e133c16f837e4db122c6" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "19a91a38b02c1c28c14e0ba468d20ae1423c39b2" },
"nvim-web-devicons": { "branch": "master", "commit": "b427ac5f9dff494f839e81441fb3f04a58cbcfbc" },
"oil.nvim": { "branch": "master", "commit": "bf753c3e3f8736939ad5597f92329dfe7b1df4f5" },
"plenary.nvim": { "branch": "master", "commit": "663246936325062427597964d81d30eaa42ab1e4" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"toggleterm.nvim": { "branch": "main", "commit": "cbd041d91b90cd3c02df03fe6133208888f8e008" },
"tokyonight.nvim": { "branch": "main", "commit": "67c6050e1ca41260c919236a098ba278472c7520" },
"vim-commentary": { "branch": "master", "commit": "f67e3e67ea516755005e6cccb178bc8439c6d402" },
"vim-fugitive": { "branch": "master", "commit": "854a8df0d06b8d3fcb30fa7f2b08c62b553eee3b" },
Expand Down
9 changes: 9 additions & 0 deletions nvim/lua/autocmds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local api = vim.api

api.nvim_create_augroup("custom_buffer", { clear = true })
api.nvim_create_autocmd("TextYankPost", {
group = "custom_buffer",
pattern = "*",
callback = function() vim.highlight.on_yank { timeout = 200 } end
})

18 changes: 18 additions & 0 deletions nvim/lua/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ k.set('n', '<c-l>', ':wincmd l<CR>', { desc = 'Move to window right' })

-- plugins set their own keymaps in ~/.config/nvim/lua/plugins/*.lua
--
--
k.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })

k.set("n", "<leader>fp", "<cmd>echo expand('%:p')<cr>", { desc = "Show full path of current buffer"})

local nvimTreeFocusOrToggle = function ()
local nvimTree=require("nvim-tree.api")
local currentBuf = vim.api.nvim_get_current_buf()
local currentBufFt = vim.api.nvim_get_option_value("filetype", { buf = currentBuf })
if currentBufFt == "NvimTree" then
nvimTree.tree.toggle()
else
nvimTree.tree.focus()
end
end


vim.keymap.set("n", "<leader>e", nvimTreeFocusOrToggle, { desc = "Toggle tree explorer"})
5 changes: 1 addition & 4 deletions nvim/lua/lazy-nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ end
vim.opt.rtp:prepend(lazypath)

local opts = {
-- defaults = {
-- lazy = true,
-- },
install = {
colorscheme = { "catppuccin" },
colorscheme = { "tokyonight" },
},
}

Expand Down
6 changes: 5 additions & 1 deletion nvim/lua/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

local g, opt = vim.g, vim.opt

-- nvim-tree: disable netrw at the very start of your init.lua
g.loaded_netrw = 1
g.loaded_netrwPlugin = 1

g.mapleader = ' '
g.maplocalleader = ' '

Expand Down Expand Up @@ -46,7 +50,7 @@ opt.virtualedit = 'onemore'
opt.joinspaces = false
opt.formatoptions = 'crqnj'

opt.completeopt = 'menuone,noselect,preview'
opt.completeopt = 'menuone,preview'

opt.incsearch = true
opt.ignorecase = true
Expand Down
20 changes: 11 additions & 9 deletions nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

return {
{
"folke/neodev.nvim",
-- neodev needs to start before nvim-lspconfig
priority = 1000,
config = function()
require("neodev").setup({})
end,
},

{
"williamboman/mason.nvim",
config = function()
Expand All @@ -15,21 +25,13 @@ return {
end
},

{
-- neodev needs to start before nvim-lspconfig
"folke/neodev.nvim",
config = function()
require("neodev").setup({})
end,
},

{
"neovim/nvim-lspconfig",
dependencies = {
"folke/neodev.nvim",
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"j-hui/fidget.nvim",
"folke/neodev.nvim",
},
config = function()
local lspconfig = require('lspconfig')
Expand Down
41 changes: 41 additions & 0 deletions nvim/lua/plugins/nvim-tree.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
return {
"nvim-tree/nvim-tree.lua",
version = "*",
lazy = "false",
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
local HEIGHT_RATIO = 0.8 -- You can change this
local WIDTH_RATIO = 0.5
require("nvim-tree").setup({
view = {
float = {
enable = true,
open_win_config = function()
local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local window_w = screen_w * WIDTH_RATIO
local window_h = screen_h * HEIGHT_RATIO
local window_w_int = math.floor(window_w)
local window_h_int = math.floor(window_h)
local center_x = (screen_w - window_w) / 2
local center_y = ((vim.opt.lines:get() - window_h) / 2)
- vim.opt.cmdheight:get()
return {
border = 'rounded',
relative = 'editor',
row = center_y,
col = center_x,
width = window_w_int,
height = window_h_int,
}
end,
},
width = function()
return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
end,
},
})
end
}
9 changes: 9 additions & 0 deletions nvim/lua/plugins/oil.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return {
'stevearc/oil.nvim',
opts = {},
-- Optional dependencies
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("oil").setup()
end,
}
Loading