Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxing3 committed Dec 31, 2023
1 parent 9ee50ac commit 457b060
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 110 deletions.
67 changes: 33 additions & 34 deletions lua/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,32 @@ map({ "n", "v" }, "<C-p>", "<cmd>Telescope projects<cr>", { desc = "Telescope pr
map({ "n", "v" }, "<space>pa", "<cmd>AddProject<cr>", { desc = "Add Projects" })

-- yank history
map({ "n", "v" }, "<space>sy", "<cmd>Telescope yarn_history<cr>", { desc = "Yank history" })
map({ "n", "v" }, "<space>sy", "<cmd>YarnRingHistory<cr>", { desc = "Yank history" })

-- cheat sheat
map({ "n", "v" }, "<space>se", "<cmd>Telescope cheat fd<cr>", { desc = "Find cheatsheat" })

-- file explorer
-- new file
map("n", "<leader>fn", "<cmd>enew<cr>", { desc = "New File" })
-- find file
map("n", "<leader>.", "<cmd>Telescope find_files<cr>", { desc = "Find files" })
-- explorer
map({ "n", "v" }, "<f3>", "<cmd>Neotree toggle<cr>", { desc = "Toggle neotree" })
map({ "n", "v" }, "<C-e>", "<cmd>Telescope file_browser file_browser<cr>", { desc = "Toggle file_browser" })
map({ "n", "v" }, "<M-e>", "<cmd>Telescope file_browser file_browser<cr>", { desc = "Toggle file_browser" })

-- lsp
map({ "n", "v" }, "<f12>", "<cmd>Telescope lsp_definitions<cr>", { desc = "Goto Definition" })
map({ "n", "v" }, "<S-f12>", "<cmd>Telescope lsp_type_definitions<cr>", { desc = "Goto type definitions" })
map({ "n", "v" }, "<f11>", "<cmd>Telescope lsp_implementations<cr>", { desc = "Goto Implementation" })
map({ "n", "v" }, "<S-f11>", "<cmd>Telescope lsp_references<cr>", { desc = "Goto Reference" })

-- lsp
map({ "n", "v" }, "<f2>", vim.lsp.buf.rename, { desc = "Rename variable" })
map({ "n", "v" }, "cr", vim.lsp.buf.rename, { desc = "Rename variable" })
map({ "n", "v" }, "ca", vim.lsp.buf.code_action, { desc = "Code action" })
map("n", "<leader>ch", "<cmd>ClangdSwitchSourceHeader<cr>", { desc = "Clangd Switch S/H" })
map("n", "gh", "<cmd>ClangdSwitchSourceHeader<cr>", { desc = "Clangd Switch S/H" })
map({ "n", "v" }, "<leader>ch", "<cmd>ClangdSwitchSourceHeader<cr>", { desc = "Clangd Switch S/H" })
map({ "n", "v" }, "gh", "<cmd>ClangdSwitchSourceHeader<cr>", { desc = "Clangd Switch S/H" })

-- Task runner
map("n", "<f5>", "<cmd>AsyncTask project-build<cr>", { desc = "Project build" })
Expand Down Expand Up @@ -130,9 +136,30 @@ else
map("n", "[b", "<cmd>bprevious<cr>", { desc = "Prev buffer" })
map("n", "]b", "<cmd>bnext<cr>", { desc = "Next buffer" })
end
map({ "n", "i", "v" }, "<C-q>", "<cmd>Bclose!<cr>", { desc = "Next buffer" })
map({ "n", "i", "v" }, "<C-q>", "<cmd>Bclose!<cr>", { desc = "Close buffer" })
map("n", "<leader>bb", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
map("n", "<leader>`", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })

-- windows
map("n", "<leader>ww", "<C-W>p", { desc = "Other window", remap = true })

map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
map("n", "<C-x>", "<C-W>c", { desc = "Delete window", remap = true })

map("n", "<leader>w-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>wh", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>w|", "<C-W>v", { desc = "Split window right", remap = true })
map("n", "<leader>wv", "<C-W>v", { desc = "Split window right", remap = true })

map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true })

-- tabs
map("n", "<leader><tab>l", "<cmd>tablast<cr>", { desc = "Last Tab" })
map("n", "<leader><tab>f", "<cmd>tabfirst<cr>", { desc = "First Tab" })
map("n", "<leader><tab><tab>", "<cmd>tabnew<cr>", { desc = "New Tab" })
map("n", "<leader><tab>]", "<cmd>tabnext<cr>", { desc = "Next Tab" })
map("n", "<leader><tab>d", "<cmd>tabclose<cr>", { desc = "Close Tab" })
map("n", "<leader><tab>[", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })

-- Clear search with <esc>
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and clear hlsearch" })
Expand Down Expand Up @@ -172,12 +199,6 @@ map("v", ">", ">gv")
-- lazy
map("n", "<leader>l", "<cmd>Lazy<cr>", { desc = "Lazy" })

-- new file
map("n", "<leader>fn", "<cmd>enew<cr>", { desc = "New File" })

-- find file
map("n", "<leader>.", "<cmd>Telescope find_files<cr>", { desc = "Find files" })

-- list
map("n", "<leader>xl", "<cmd>lopen<cr>", { desc = "Location List" })
map("n", "<leader>xq", "<cmd>copen<cr>", { desc = "Quickfix List" })
Expand Down Expand Up @@ -231,28 +252,6 @@ map("t", "<C-l>", "<cmd>wincmd l<cr>", { desc = "Go to right window" })
map("t", "<C-/>", "<cmd>close<cr>", { desc = "Hide Terminal" })
map("t", "<c-_>", "<cmd>close<cr>", { desc = "which_key_ignore" })

-- windows
map("n", "<leader>ww", "<C-W>p", { desc = "Other window", remap = true })

map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
map("n", "<C-x>", "<C-W>c", { desc = "Delete window", remap = true })

map("n", "<leader>w-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>wh", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>w|", "<C-W>v", { desc = "Split window right", remap = true })
map("n", "<leader>wv", "<C-W>v", { desc = "Split window right", remap = true })

map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true })

-- tabs
map("n", "<leader><tab>l", "<cmd>tablast<cr>", { desc = "Last Tab" })
map("n", "<leader><tab>f", "<cmd>tabfirst<cr>", { desc = "First Tab" })
map("n", "<leader><tab><tab>", "<cmd>tabnew<cr>", { desc = "New Tab" })
map("n", "<leader><tab>]", "<cmd>tabnext<cr>", { desc = "Next Tab" })
map("n", "<leader><tab>d", "<cmd>tabclose<cr>", { desc = "Close Tab" })
map("n", "<leader><tab>[", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })

-- copilot settings
-- AI Assistant
-- map({ "n", "v", "i" }, "<C-\\>", "<cmd>Copilot panel<cr>", { desc = "Copilot Panel" })
Expand Down
122 changes: 72 additions & 50 deletions lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
local cmp = require("cmp")
local luasnip = require("luasnip")

local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

local simple_mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
if not cmp.get_selected_entry() or not has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
cmp.confirm()
end
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}

local intellij_mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
-- This little snippet will confirm with tab, and if no entry is selected, will confirm the first item
if cmp.visible() then
local entry = cmp.get_selected_entry()
if not entry then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
cmp.confirm()
end
else
fallback()
end
end, { "i", "s", "c" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s", "c" }),
}

return {
{
"hrsh7th/nvim-cmp",
Expand All @@ -6,62 +63,27 @@ return {
},
---@param opts cmp.ConfigSchema
opts = function(_, opts)
local cmp = require("cmp")
opts.sources =
cmp.config.sources(vim.list_extend(opts.sources, { { name = "emoji" }, { name = "orgmode" } }))

local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0
and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")

opts.mapping = vim.tbl_extend("force", opts.mapping, {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif cmp.visible() then
-- NOTE: You could replace select_next_item() with confirm({ select = true }) to get VS Code autocompletion behavior
-- cmp.select_next_item()
cmp.confirm({ select = true })
elseif luasnip.expand_or_locally_jumpable() then
-- NOTE: You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- this way you will only jump inside the snippet region
luasnip.expand_or_locally_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
})
opts.mapping = vim.tbl_extend("force", opts.mapping, simple_mapping)
end,
},
{
"L3MON4D3/LuaSnip",
setup = function()
local snippet_path = os.getenv("HOME") .. "/.config/nvim/my-snippets"
if not vim.tbl_contains(vim.opt.rtp:get(), snippet_path) then
vim.opt.rtp:append(snippet_path)
end

require("luasnip").config.set_config({
history = true,
updateevents = "TextChanged,TextChangedI",
delete_check_events = "TextChanged,InsertLeave",
})
require("luasnip.loaders.from_lua").lazy_load()
require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_snipmate").lazy_load()
end,
build = (not jit.os:find("Windows"))
and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp"
or nil,
dependencies = {
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_vscode").lazy_load("./snippets")
end,
},
opts = {
history = true,
delete_check_events = "TextChanged",
},
},
}
9 changes: 0 additions & 9 deletions lua/plugins/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ return {
"rbgrouleff/bclose.vim",
{
"mg979/vim-visual-multi",
config = function()
vim.cmd([[
let g:VM_maps = {}
let g:VM_maps['Find Under'] = '<C-d>' " replace C-n
let g:VM_maps['Find Subword Under'] = '<C-d>' " replace visual C-n
let g:VM_maps["Select Cursor Down"] = '<M-C-Down>' " start selecting down
let g:VM_maps["Select Cursor Up"] = '<M-C-Up>' " start selecting up
]])
end,
},
{
"aserowy/tmux.nvim",
Expand Down
6 changes: 3 additions & 3 deletions lua/plugins/finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ return {
{
"<leader>fe",
function()
require("neo-tree.command").execute({ toggle = true, dir = require("lazyvim.util").get_root() })
require("neo-tree.command").execute({ toggle = true, dir = require("lazyvim.util").root })
end,
desc = "Explorer NeoTree (root dir)",
},
Expand All @@ -189,8 +189,8 @@ return {
end,
desc = "Explorer NeoTree (cwd)",
},
{ "<leader>e", "<leader>fe", desc = "Explorer NeoTree (root dir)", remap = true },
{ "<leader>E", "<leader>fE", desc = "Explorer NeoTree (cwd)", remap = true },
{ "<leader>e", "<leader>fe", desc = "NeoTree (root)", remap = true },
{ "<leader>E", "<leader>fE", desc = "NeoTree (cwd)", remap = true },
},
opts = {
filesystem = {
Expand Down
Loading

0 comments on commit 457b060

Please sign in to comment.