Skip to content

Commit aeb68e3

Browse files
committed
Update keybindings
1 parent 6368d1a commit aeb68e3

File tree

4 files changed

+225
-94
lines changed

4 files changed

+225
-94
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ This repo contains all my config files.
44

55
## Contents
66

7-
The main things in this are a highly modified lunarvim, a basic setup of zsh
7+
The main things in this are a highly modified lazyvim, a basic setup of zsh
88
using zgenom and oh-my-zsh. All dotfiles are installed via stow.
99
`$DOTFILES/home` contains all the dotfiles that go directly in `$HOME`,
1010
while `$DOTFILES/config` contains all the dotfiles that go in `$HOME/config`.
1111
And we don't talk about `$DOTFILES/private`.
1212

1313
Honestly the most useful thing in hear for those that are looking would be
14-
the configuration of lunarvim, which can be found in `$DOTFILES/config/lvim`.
15-
This contains a lunarvim config with, in my opinion, a much better set of
14+
the configuration of lazyvim, which can be found in `$DOTFILES/config/nvim`.
15+
This contains a lazyvim config with, in my opinion, a much better set of
1616
keybindings, and additional plugins like `nvim-devcontainer-cli`. There are
1717
some less important plugins in there, but maybe the most interesting thing is
18-
that it is an example of how to highly modify lunarvim. The most important
19-
files are in `$DOTFILES/config/lvim/lua/user`. The naming should be mostly
18+
that it is an example of how to highly modify lazyvim. The most important
19+
files are in `$DOTFILES/config/nvim/lua/user`. The naming should be mostly
2020
self-explanatory.
2121

2222
## Install

config/nvim/lua/config/keymaps.lua

Lines changed: 119 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,132 @@
22
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
33
-- Add any additional keymaps here
44

5+
-- custom keymaps
6+
-- for conciseness
7+
local keymap = vim.keymap
8+
local wk = require("which-key")
9+
10+
-- helper for keymaps
11+
local function map(mode, l, r, opts)
12+
keymap.set(mode, l, r, opts)
13+
end
14+
15+
local function nmap(l, r, opts)
16+
map("n", l, r, opts)
17+
end
18+
19+
local function vmap(l, r, opts)
20+
map("v", l, r, opts)
21+
end
22+
23+
local function unmap(mode, l)
24+
keymap.del(mode, l)
25+
end
26+
27+
local function nunmap(l)
28+
unmap("n", l)
29+
end
30+
31+
local function vunmap(l)
32+
unmap("v", l)
33+
end
34+
35+
local function wunmap(l)
36+
nunmap("<leader>" .. l)
37+
end
38+
39+
local function wgroup(groups)
40+
for key, value in pairs(groups) do
41+
wk.add({ "<leader>" .. key, group = value })
42+
end
43+
end
44+
45+
local function wmap(mode, mappings)
46+
for key, value in pairs(mappings) do
47+
local mapping = "<leader>" .. key
48+
local command = value[1]
49+
local description = value[2]
50+
51+
wk.add({ mapping, command, desc = description, mode = mode })
52+
end
53+
end
54+
55+
local function wnmap(mappings)
56+
wmap("n", mappings)
57+
end
58+
59+
local function wvmap(mappings)
60+
wmap("v", mappings)
61+
end
62+
563
-- custom which-key mappings
664
local groups = {}
765
local mappings = {}
866
local vmappings = {}
967

68+
-- comments
69+
nmap(";;", "gcc", { remap = true })
70+
nmap(";A", "gcA", { remap = true })
71+
nmap(";p", "gcap", { remap = true })
72+
nmap(";o", "gco", { remap = true })
73+
nmap(";O", "gcO", { remap = true })
74+
vmap(";", "gc", { remap = true })
75+
76+
-- navigation
77+
nmap("H", "Hzz")
78+
nmap("L", "Lzz")
79+
80+
-- navigation between window panes
81+
nmap("<C-h>", "<CMD>NvimTmuxNavigateLeft<CR>")
82+
nmap("<C-j>", "<CMD>NvimTmuxNavigateDown<CR>")
83+
nmap("<C-k>", "<CMD>NvimTmuxNavigateUp<CR>")
84+
nmap("<C-l>", "<CMD>NvimTmuxNavigateRight<CR>")
85+
nmap("<C-Tab>", "<CMD>NvimTmuxNavigateLastActive<CR>")
86+
nmap("<C-Space>", "<CMD>NvimTmuxNavigateNext<CR>")
87+
88+
-- navigation between buffers
89+
nmap("<M-Right>", "<CMD>BufferLineCycleNext<CR>")
90+
nmap("<M-Left>", "<CMD>BufferLineCyclePrev<CR>")
91+
92+
nmap("<M-3>", "<leader>Tf")
93+
nmap("<M-2>", "<leader>Th")
94+
nmap("<M-1>", "<leader>Tv")
95+
96+
-- which-key setup
1097
-- unmap things that I want to use
11-
-- mappings["/"] = {} -- comment
12-
-- mappings[";"] = {} -- Dashboard
13-
-- mappings["b"]["b"] = {} -- previous buffer
14-
-- mappings["b"]["D"] = {} -- BufferLineSortByDirectory
15-
-- mappings["b"]["l"] = {} -- BufferLineCloseRight
16-
-- mappings["b"]["L"] = {} -- sort by language
17-
-- mappings["g"]["b"] = {} -- git new branch
18-
-- mappings["g"]["l"] = {} -- git blame
19-
-- mappings["g"]["L"] = {} -- git blame
20-
-- mappings["bf"] = {} -- buffer find
21-
-- mappings["c"] = {} -- close buffer
22-
-- mappings["s"] = {} -- search
23-
-- mappings["w"] = {} -- save
24-
-- vmappings["/"] = {} -- comment
98+
wunmap("`")
99+
wunmap("fb")
100+
wunmap("fc")
101+
wunmap("fe")
102+
wunmap("fE")
103+
wunmap("ft")
104+
wunmap("fT")
105+
wunmap("gg")
106+
wunmap("gG")
107+
wunmap("bo")
108+
wunmap("bl")
109+
wunmap("br")
25110

26111
-- set menu items
27-
groups["D"] = "Devcontainer"
28-
groups["f"] = "Files"
29-
groups["q"] = "Quit"
30-
groups["/"] = "Search"
31-
groups["w"] = "Windows"
112+
groups["D"] = "+devcontainer"
113+
groups["f"] = "+files"
114+
groups["/"] = "+search"
115+
groups["t"] = "+terminal"
116+
117+
wgroup(groups)
32118

33119
mappings["+"] = { "<C-a>", "Increment Number" } -- increment
34120
mappings["-"] = { "<C-x>", "Decrement Number" } -- decrement
121+
mappings["h"] = { "<CMD>nohlsearch<CR>", "No Highlight" }
35122

36123
-- buffers operations
37124
mappings["<Tab>"] = { "<CMD>edit #<CR>", "Previous Active Buffer" }
38-
mappings["0"] = { "<CMD>NvimTreeFocus<CR>", "Focus Explorer" }
125+
mappings["0"] = {
126+
function()
127+
require("neo-tree.command").execute({ toggle = false, dir = vim.uv.cwd() })
128+
end,
129+
"Focus Explorer",
130+
}
39131
mappings["1"] = { "<CMD>BufferLineGoToBuffer 1<CR>", "Select Buffer 1" }
40132
mappings["2"] = { "<CMD>BufferLineGoToBuffer 2<CR>", "Select Buffer 2" }
41133
mappings["3"] = { "<CMD>BufferLineGoToBuffer 3<CR>", "Select Buffer 3" }
@@ -47,16 +139,15 @@ mappings["8"] = { "<CMD>BufferLineGoToBuffer 8<CR>", "Select Buffer 8" }
47139
mappings["9"] = { "<CMD>BufferLineGoToBuffer 9<CR>", "Select Buffer 9" }
48140

49141
mappings["b/"] = { "<CMD>Telescope buffers previewer=true<CR>", "Find" }
50-
mappings["bb"] = { "<cmd>Telescope oldfiles<CR>", "Open Recent File" }
51-
mappings["bd"] = { "<CMD>BufferKill<CR>", "Close" }
142+
mappings["b["] = { "<CMD>BufferLineCycleNext<CR>", "Previous" }
143+
mappings["b]"] = { "<CMD>BufferLineCyclePrev<CR>", "Next" }
144+
mappings["bb"] = { "<CMD>Telescope oldfiles<CR>", "Open Recent File" }
52145
mappings["bD"] = { "<CMD>BufferSortByDirectory<CR>", "Sort by Directory" }
53146
mappings["bj"] = { "<CMD>BufferLinePick<CR>", "Jump" }
54147
mappings["bl"] = { "<CMD>BufferLineSortByExtension<CR>", "Sort by Language" }
55148
mappings["bL"] = { "<CMD>BufferLineCloseLeft<CR>", "Close All to Left" }
56-
mappings["bM"] = { "<CMD>BufferLineCloseLeft<CR><CMD>BufferLineCloseRight<CR>", "Close All Other" }
57-
mappings["bn"] = { "<CMD>BufferLineCycleNext<CR>", "Next" }
58149
mappings["bN"] = { "<CMD>tabnew<CR>", "New" }
59-
mappings["bp"] = { "<CMD>BufferLineCyclePrev<CR>", "Previous" }
150+
mappings["bO"] = { "<CMD>BufferLineCloseLeft<CR><CMD>BufferLineCloseRight<CR>", "Close All Other" }
60151
mappings["bR"] = { "<CMD>BufferLineCloseRight<CR>", "Close All to Right" }
61152

62153
-- command
@@ -97,7 +188,7 @@ mappings["fw"] = { "<CMD>noautocmd w<CR>", "Save Current (noautocmd)" }
97188
mappings["fo"] = { "<CMD>Oil --float .<CR>", "Open Oil in Current Path" }
98189

99190
-- git
100-
mappings["gl"] = { "<CMD>LazyGit<CR>", "LazyGit (float)" }
191+
mappings["gl"] = { "<CMD>LazyGitCurrentFile<CR>", "LazyGit (float)" }
101192
mappings["gb"] = { "<CMD>Gitsigns toggle_current_line_blame<CR>", "Blame" }
102193

103194
-- gitlab
@@ -154,65 +245,5 @@ mappings["ws"] = { "<CMD>split<CR>", "Split Horizontal" }
154245
mappings["wt"] = { "<CMD>tab split<CR>", "Send to Tab" }
155246
mappings["wv"] = { "<CMD>vsplit<CR>", "Split Vertical" }
156247

157-
local wk = require("which-key")
158-
for key, value in pairs(groups) do
159-
wk.add({ "<leader>" .. key, group = value })
160-
end
161-
162-
for key, value in pairs(mappings) do
163-
local map = "<leader>" .. key
164-
local command = value[1]
165-
local description = value[2]
166-
167-
wk.add({ map, command, desc = description, mode = "n" })
168-
end
169-
170-
for key, value in pairs(vmappings) do
171-
local map = "<leader>" .. key
172-
local command = value[1]
173-
local description = value[2]
174-
175-
wk.add({ map, command, desc = description, mode = "v" })
176-
end
177-
178-
179-
-- custom keymaps
180-
-- for conciseness
181-
local keymap = vim.keymap
182-
183-
-- helper for keymaps
184-
local function map(mode, l, r, opts)
185-
keymap.set(mode, l, r, opts)
186-
end
187-
188-
local function nmap(l, r, opts)
189-
map("n", l, r, opts)
190-
end
191-
192-
local function vmap(l, r, opts)
193-
map("v", l, r, opts)
194-
end
195-
196-
-- comments
197-
nmap(";;", "gcc", { remap = true })
198-
nmap(";A", "gcA", { remap = true })
199-
nmap(";p", "gcap", { remap = true })
200-
nmap(";o", "gco", { remap = true })
201-
nmap(";O", "gcO", { remap = true })
202-
vmap(";", "gc", { remap = true })
203-
204-
-- navigation
205-
nmap("H", "Hzz")
206-
nmap("L", "Lzz")
207-
208-
-- navigation between window panes
209-
nmap("<C-h>", "<CMD>NvimTmuxNavigateLeft<CR>")
210-
nmap("<C-j>", "<CMD>NvimTmuxNavigateDown<CR>")
211-
nmap("<C-k>", "<CMD>NvimTmuxNavigateUp<CR>")
212-
nmap("<C-l>", "<CMD>NvimTmuxNavigateRight<CR>")
213-
nmap("<C-Tab>", "<CMD>NvimTmuxNavigateLastActive<CR>")
214-
nmap("<C-Space>", "<CMD>NvimTmuxNavigateNext<CR>")
215-
216-
-- navigation between buffers
217-
nmap("<M-Right>", "<CMD>BufferLineCycleNext<CR>")
218-
nmap("<M-Left>", "<CMD>BufferLineCyclePrev<CR>")
248+
wnmap(mappings)
249+
wvmap(vmappings)

config/nvim/lua/plugins/plugins.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ return {
1919
dotfiles_branch = "main",
2020
dotfiles_targetPath = "~/dotfiles",
2121
dotfiles_installCommand = "install.sh",
22-
nvim_binary = "lvim",
22+
nvim_binary = "nvim",
2323
shell = "zsh",
2424
}
2525
require("devcontainer-cli").setup(opts)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
return {
2+
{
3+
"akinsho/toggleterm.nvim",
4+
lazy = true,
5+
cmd = { "ToggleTerm" },
6+
keys = {
7+
{
8+
"<leader>tf",
9+
function()
10+
local count = vim.v.count1
11+
require("toggleterm").toggle(count, 0, LazyVim.root.get(), "float")
12+
end,
13+
desc = "ToggleTerm (float root_dir)",
14+
},
15+
{
16+
"<leader>th",
17+
function()
18+
local count = vim.v.count1
19+
require("toggleterm").toggle(count, 15, LazyVim.root.get(), "horizontal")
20+
end,
21+
desc = "ToggleTerm (horizontal root_dir)",
22+
},
23+
{
24+
"<leader>tv",
25+
function()
26+
local count = vim.v.count1
27+
require("toggleterm").toggle(count, vim.o.columns * 0.4, LazyVim.root.get(), "vertical")
28+
end,
29+
desc = "ToggleTerm (vertical root_dir)",
30+
},
31+
{
32+
"<leader>tn",
33+
"<cmd>toggleTermSetName<cr>",
34+
desc = "Set term name",
35+
},
36+
{
37+
"<leader>ts",
38+
"<cmd>termSelect<cr>",
39+
desc = "Select term",
40+
},
41+
{
42+
"<leader>tt",
43+
function()
44+
require("toggleterm").toggle(1, 100, LazyVim.root.get(), "tab")
45+
end,
46+
desc = "ToggleTerm (tab root_dir)",
47+
},
48+
{
49+
"<leader>tT",
50+
function()
51+
require("toggleterm").toggle(1, 100, vim.loop.cwd(), "tab")
52+
end,
53+
desc = "ToggleTerm (tab cwd_dir)",
54+
},
55+
},
56+
opts = {
57+
-- size can be a number or function which is passed the current terminal
58+
size = function(term)
59+
if term.direction == "horizontal" then
60+
return 15
61+
elseif term.direction == "vertical" then
62+
return vim.o.columns * 0.4
63+
end
64+
end,
65+
open_mapping = [[<c-\>]],
66+
-- on_open = fun(t: Terminal), -- function to run when the terminal opens
67+
-- on_close = fun(t: Terminal), -- function to run when the terminal closes
68+
-- on_stdout = fun(t: Terminal, job: number, data: string[], name: string) -- callback for processing output on stdout
69+
-- on_stderr = fun(t: Terminal, job: number, data: string[], name: string) -- callback for processing output on stderr
70+
-- on_exit = fun(t: Terminal, job: number, exit_code: number, name: string) -- function to run when terminal process exits
71+
hide_numbers = true, -- hide the number column in toggleterm buffers
72+
shade_filetypes = {},
73+
shade_terminals = true,
74+
-- shading_factor = '<number>', -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light
75+
start_in_insert = true,
76+
insert_mappings = true, -- whether or not the open mapping applies in insert mode
77+
terminal_mappings = true, -- whether or not the open mapping applies in the opened terminals
78+
persist_size = true,
79+
direction = "horizontal" or "vertical" or "window" or "float",
80+
-- direction = "vertical",
81+
close_on_exit = true, -- close the terminal window when the process exits
82+
-- shell = vim.o.shell, -- change the default shell
83+
-- This field is only relevant if direction is set to 'float'
84+
-- float_opts = {
85+
-- -- The border key is *almost* the same as 'nvim_open_win'
86+
-- -- see :h nvim_open_win for details on borders however
87+
-- -- the 'curved' border is a custom border type
88+
-- -- not natively supported but implemented in this plugin.
89+
-- border = 'single' or 'double' or 'shadow' or 'curved',
90+
-- width = <value>,
91+
-- height = <value>,
92+
-- winblend = 3,
93+
-- highlights = {
94+
-- border = "Normal",
95+
-- background = "Normal",
96+
-- }
97+
-- }
98+
},
99+
},
100+
}

0 commit comments

Comments
 (0)