Introduces `<leader>gw` to format the entire buffer using the internal formatting operator gw. It preserves the current window view (cursor position and scroll) during the operation.
60 lines
2.2 KiB
Lua
60 lines
2.2 KiB
Lua
local opts = { remap = false, silent = true }
|
|
|
|
-- Quick write
|
|
vim.keymap.set('n', '<leader>w', ':w!<CR>', opts)
|
|
|
|
-- Treat long lines as line containing breaks
|
|
vim.keymap.set('n', 'j', 'gj', opts)
|
|
vim.keymap.set('n', 'k', 'gk', opts)
|
|
|
|
vim.keymap.set('n', '<leader>tn', ':tabnew<Space>', { remap = false })
|
|
vim.keymap.set('n', '<leader>tm', ':tabmove<Space>', { remap = false })
|
|
vim.keymap.set('n', '<leader>tc', ':tabclose<CR>', opts)
|
|
vim.keymap.set('n', '<leader>to', ':tabonly<CR>', opts)
|
|
|
|
-- Quickly access spelling menu
|
|
vim.keymap.set('i', '<C-s>', '<C-g>u<C-X>s', opts)
|
|
vim.keymap.set('n', '<C-s>', 'i<C-g>u<C-X>s', opts)
|
|
|
|
-- Clear search highlights
|
|
vim.keymap.set('n', '<leader><Space>', ':nohlsearch<CR>', opts)
|
|
|
|
-- Disable 'Q' from opening Ex mode
|
|
vim.keymap.set('n', 'Q', '<nop>', opts)
|
|
|
|
-- System clipboard yank/put
|
|
vim.keymap.set('', '<leader>y', '"+y', opts)
|
|
vim.keymap.set('', '<leader>Y', '"+Y', opts)
|
|
vim.keymap.set('', '<leader>p', '"+p', opts)
|
|
vim.keymap.set('', '<leader>P', '"+P', opts)
|
|
|
|
-- Undo neovim's default mapping of Y to y$
|
|
vim.cmd.unmap('Y')
|
|
|
|
-- Make nvim :terminal more like vim :terminal
|
|
vim.keymap.set('t', '<C-w>N', '<C-\\><C-n>', opts)
|
|
|
|
-- Mappings to make navigating :Termdebug
|
|
vim.keymap.set('n', '<C-w><C-g>', ':Gdb<CR>:startinsert<CR>', opts)
|
|
vim.keymap.set('n', '<C-w><C-e>', ':Program<CR>', opts)
|
|
vim.keymap.set('n', '<C-w><C-s>', ':Source<CR>', opts)
|
|
vim.keymap.set('n', '<C-w><C-a>', ':Asm<CR>', opts)
|
|
vim.keymap.set('t', '<C-w><C-g>', '<C-\\><C-n>:Gdb<CR>:startinsert<CR>', opts)
|
|
vim.keymap.set('t', '<C-w><C-e>', '<C-\\><C-n>:Program<CR>', opts)
|
|
vim.keymap.set('t', '<C-w><C-s>', '<C-\\><C-n>:Source<CR>', opts)
|
|
vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)
|
|
|
|
-- Mappings to grep for then fuzzy find the word under the cursor or visual selection
|
|
vim.keymap.set('n', '<leader>rg', ':Rg<CR>', opts)
|
|
vim.keymap.set('v', '<leader>rg', ":'<,'>Rg<CR>", opts)
|
|
|
|
-- Mapping to toggle checkboxes
|
|
vim.keymap.set('n', '<leader><CR>', ':CheckboxToggle<CR>', opts)
|
|
|
|
-- Format whole file using internal algorithm
|
|
vim.keymap.set('n', '<leader>gw', function()
|
|
local view = vim.fn.winsaveview()
|
|
vim.cmd('normal! gggwG')
|
|
vim.fn.winrestview(view)
|
|
end, { desc = 'Format whole file with gw' })
|