1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
local map = vim.keymap.set
-- Create split panes using leader key
map('n', '<leader>sh', ':split<CR>')
map('n', '<leader>sv', ':vsplit<CR>')
-- Clear highlights on search when pressing <Esc> in normal mode
map('n', '<Esc>', '<cmd>nohlsearch<CR>')
-- Diagnostic keymaps
map('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
-- Cycle through buffers
map('n', '<Tab>', ':bnext<CR>')
map('n', '<S-Tab>', ':bprevious<CR>')
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- to remember.
map('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- Keybinds to make split navigation easier.
-- Use CTRL+<hjkl> to switch between windows
--
-- See `:help wincmd` for a list of all window commands
map('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
map('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
map('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
map('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
-- Delete the current buffer
vim.keymap.set('n', '<leader>bd', '<cmd>bdelete<cr>', { desc = 'Delete current buffer' })
-- Force delete the current buffer (discard changes)
vim.keymap.set('n', '<leader>bD', '<cmd>bdelete!<cr>', { desc = 'Force delete current buffer' })
-- Delete all buffers except the current one
vim.keymap.set('n', '<leader>ba', ':%bd|e#<cr>', { desc = 'Delete all other buffers' })
map('n', '<leader>rdt', function()
local func_name = vim.fn.expand '<cword>'
local output = vim.fn.systemlist('django-test --list ' .. func_name)
if #output == 0 then
vim.notify('No tests found for: ' .. func_name, vim.log.levels.WARN)
elseif #output == 1 then
-- Single match, run directly
vim.cmd('split | terminal ' .. output[1])
else
-- Multiple matches, prompt user
vim.ui.select(output, {
prompt = 'Select test to run:',
}, function(choice)
if choice then
vim.cmd('split | terminal ' .. choice)
end
end)
end
end, { desc = '[R]un [D]jango [T]est for word under cursor' })
|