Skip to content

Commit 1ee13a9

Browse files
committed
Feat: harpoon, neotree, comments and other keybinds
1 parent b4cf743 commit 1ee13a9

File tree

1 file changed

+173
-3
lines changed

1 file changed

+173
-3
lines changed

init.lua

Lines changed: 173 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ vim.opt.cursorline = true
157157
-- Minimal number of screen lines to keep above and below the cursor.
158158
vim.opt.scrolloff = 10
159159

160+
vim.o.tabstop = 2
161+
vim.o.softtabstop = 2
162+
vim.o.shiftwidth = 2
163+
vim.o.expandtab = true
164+
160165
-- [[ Basic Keymaps ]]
161166
-- See `:help vim.keymap.set()`
162167

@@ -174,6 +179,11 @@ vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagn
174179
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
175180
-- or just use <C-\><C-n> to exit terminal mode
176181
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
182+
vim.keymap.set('n', '<leader>q', '<cmd>q<CR>', { desc = 'Quit' })
183+
vim.keymap.set('n', '<leader>w', '<cmd>w<CR>', { desc = 'Write (save)' })
184+
185+
vim.keymap.set('n', '<C-Left>', '<cmd>bprevious<CR>', { desc = 'Go to the previous buffer' })
186+
vim.keymap.set('n', '<C-Right>', '<cmd>bnext<CR>', { desc = 'Go to the next buffer' })
177187

178188
-- TIP: Disable arrow keys in normal mode
179189
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
@@ -271,6 +281,12 @@ require('lazy').setup({
271281
-- after the plugin has been loaded:
272282
-- config = function() ... end
273283

284+
{
285+
'ThePrimeagen/harpoon',
286+
branch = 'harpoon2',
287+
dependencies = { 'nvim-lua/plenary.nvim' },
288+
},
289+
274290
{ -- Useful plugin to show you pending keybinds.
275291
'folke/which-key.nvim',
276292
event = 'VimEnter', -- Sets the loading event to 'VimEnter'
@@ -611,7 +627,8 @@ require('lazy').setup({
611627
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
612628
local servers = {
613629
-- clangd = {},
614-
-- gopls = {},
630+
-- go?
631+
gopls = {},
615632
-- pyright = {},
616633
-- rust_analyzer = {},
617634
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
@@ -620,9 +637,16 @@ require('lazy').setup({
620637
-- https://github.com/pmizio/typescript-tools.nvim
621638
--
622639
-- But for many setups, the LSP (`ts_ls`) will work just fine
623-
-- ts_ls = {},
640+
ts_ls = {},
624641
--
625642

643+
eslint = {
644+
settings = {
645+
-- Specify your ESLint config preferences here
646+
workingDirectory = { mode = 'auto' },
647+
},
648+
},
649+
626650
lua_ls = {
627651
-- cmd = {...},
628652
-- filetypes = { ...},
@@ -652,6 +676,9 @@ require('lazy').setup({
652676
local ensure_installed = vim.tbl_keys(servers or {})
653677
vim.list_extend(ensure_installed, {
654678
'stylua', -- Used to format Lua code
679+
680+
'eslint-lsp',
681+
'prettier',
655682
})
656683
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
657684

@@ -708,7 +735,8 @@ require('lazy').setup({
708735
-- python = { "isort", "black" },
709736
--
710737
-- You can use 'stop_after_first' to run the first available formatter from the list
711-
-- javascript = { "prettierd", "prettier", stop_after_first = true },
738+
javascript = { 'prettierd', 'prettier', stop_after_first = true },
739+
jsx = { 'prettier' },
712740
},
713741
},
714742
},
@@ -781,6 +809,7 @@ require('lazy').setup({
781809
-- This will auto-import if your LSP supports it.
782810
-- This will expand snippets if the LSP sent a snippet.
783811
['<C-y>'] = cmp.mapping.confirm { select = true },
812+
['<enter>'] = cmp.mapping.confirm { select = true },
784813

785814
-- If you prefer more traditional completion keymaps,
786815
-- you can uncomment the following lines
@@ -887,6 +916,28 @@ require('lazy').setup({
887916
-- Check out: https://github.com/echasnovski/mini.nvim
888917
end,
889918
},
919+
{
920+
'numToStr/Comment.nvim',
921+
config = function()
922+
require('Comment').setup()
923+
end,
924+
},
925+
{
926+
'nvim-neo-tree/neo-tree.nvim',
927+
branch = 'v3.x',
928+
dependencies = {
929+
'nvim-lua/plenary.nvim',
930+
'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended
931+
'MunifTanjim/nui.nvim',
932+
-- {"3rd/image.nvim", opts = {}}, -- Optional image support in preview window: See `# Preview Mode` for more information
933+
},
934+
lazy = false, -- neo-tree will lazily load itself
935+
---@module "neo-tree"
936+
---@type neotree.Config?
937+
opts = {
938+
-- fill any relevant options here
939+
},
940+
},
890941
{ -- Highlight, edit, and navigate code
891942
'nvim-treesitter/nvim-treesitter',
892943
build = ':TSUpdate',
@@ -959,3 +1010,122 @@ require('lazy').setup({
9591010

9601011
-- The line beneath this is called `modeline`. See `:help modeline`
9611012
-- vim: ts=2 sts=2 sw=2 et
1013+
--
1014+
1015+
local harpoon = require 'harpoon'
1016+
1017+
harpoon:setup()
1018+
1019+
vim.keymap.set('n', '<leader>a', function()
1020+
harpoon:list():add()
1021+
end)
1022+
vim.keymap.set('n', '<C-e>', function()
1023+
harpoon.ui:toggle_quick_menu(harpoon:list())
1024+
end)
1025+
1026+
vim.keymap.set('n', '<C-h>', function()
1027+
harpoon:list():select(1)
1028+
end)
1029+
vim.keymap.set('n', '<C-t>', function()
1030+
harpoon:list():select(2)
1031+
end)
1032+
vim.keymap.set('n', '<C-n>', function()
1033+
harpoon:list():select(3)
1034+
end)
1035+
vim.keymap.set('n', '<C-s>', function()
1036+
harpoon:list():select(4)
1037+
end)
1038+
1039+
-- Toggle previous & next buffers stored within Harpoon list
1040+
vim.keymap.set('n', '<C-Left', function()
1041+
harpoon:list():prev()
1042+
end)
1043+
vim.keymap.set('n', '<C-Right>', function()
1044+
harpoon:list():next()
1045+
end)
1046+
1047+
local mark = harpoon:list()
1048+
local ui = harpoon.ui
1049+
1050+
-- Set custom key mappings for Harpoon functions
1051+
vim.keymap.set('n', '<leader>fha', function()
1052+
mark:add()
1053+
end, { desc = 'Add File' })
1054+
vim.keymap.set('n', '<leader>fhq', function()
1055+
ui:toggle_quick_menu(mark)
1056+
end, { desc = 'Open Quick Menu' })
1057+
1058+
-- Navigation to Harpoon files
1059+
for i = 1, 9 do
1060+
vim.keymap.set('n', '<leader>fh' .. i, function()
1061+
mark:select(i)
1062+
end, { desc = 'File ' .. i })
1063+
end
1064+
1065+
-- Remove the current file from the Harpoon list with relative path conversion
1066+
vim.keymap.set('n', '<leader>fhr', function()
1067+
local buf_name = vim.fn.fnamemodify(vim.fn.expand '%:p', ':~:.') -- Convert absolute to relative path
1068+
local found = false
1069+
1070+
-- Iterate through the mark.items table
1071+
for index, entry in ipairs(mark.items) do
1072+
if entry.value == buf_name then
1073+
table.remove(mark.items, index) -- Remove the matching entry
1074+
mark._length = mark._length - 1 -- Adjust the length
1075+
found = true
1076+
print('Removed from Harpoon: ' .. buf_name)
1077+
break
1078+
end
1079+
end
1080+
1081+
if not found then
1082+
print 'File not found in Harpoon list'
1083+
end
1084+
end, { desc = 'Remove Current File' })
1085+
1086+
-- Clear all files from the Harpoon list
1087+
vim.keymap.set('n', '<leader>fhx', function()
1088+
for index = #mark.items, 1, -1 do
1089+
table.remove(mark.items, index)
1090+
end
1091+
print 'Cleared all marks'
1092+
end, { desc = 'Clear All Marks' })
1093+
1094+
-- Toggle previous & next buffers stored within Harpoon list
1095+
vim.keymap.set('n', '<leader>fhp', function()
1096+
mark:prev()
1097+
end, { desc = 'Previous Buffer' })
1098+
vim.keymap.set('n', '<leader>fhn', function()
1099+
mark:next()
1100+
end, { desc = 'Next Buffer' })
1101+
1102+
----
1103+
1104+
-- require('Comment').setup {
1105+
-- -- Disable default `gc` mappings
1106+
-- mappings = {
1107+
-- basic = false, -- Disables `gc`, `gcc`, etc.
1108+
-- extra = false, -- Disables `gco`, `gcO`, `gcA`, etc.
1109+
-- },
1110+
-- }
1111+
1112+
-- Add your own keybindings
1113+
local commentApi = require 'Comment.api'
1114+
1115+
-- Normal Mode: Ctrl + /
1116+
vim.keymap.set('n', '<C-_>', commentApi.toggle.linewise.current, { noremap = true, silent = true })
1117+
1118+
-- Visual Mode: Ctrl + /
1119+
vim.keymap.set('x', '<C-_>', function()
1120+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<ESC>', true, false, true), 'nx', false)
1121+
commentApi.toggle.linewise(vim.fn.visualmode())
1122+
end, { noremap = true, silent = true })
1123+
1124+
-- *** Neotree ***
1125+
1126+
vim.keymap.set('n', '<leader>e', '<Cmd>Neotree toggle<CR>')
1127+
1128+
vim.keymap.set('n', '<leader>o', function()
1129+
vim.cmd 'Neotree reveal'
1130+
vim.cmd 'wincmd p' -- Switch back to the last window
1131+
end)

0 commit comments

Comments
 (0)