dotfiles/.config/nvim/lua/my/coding.lua

153 lines
4.4 KiB
Lua

require('my/plugins')
local map = require('my.functions').map
require('Comment').setup({
toggler = {
line = '<Leader>cc',
block = '<Leader>CC'
},
opleader = {
line = '<Leader>c',
block = '<Leader>C'
},
extra = {
above = '<Leader>cO',
below = '<Leader>co',
eol = '<Leader>cA',
},
pre_hook = function(ctx)
local comment_utils = require('Comment.utils')
local context_utils = require('ts_context_commentstring.utils')
local context_internal = require('ts_context_commentstring.internal')
local location = nil
if ctx.ctype == comment_utils.ctype.block then
location = context_utils.get_cursor_location()
elseif ctx.cmotion == comment_utils.cmotion.v or
ctx.cmotion == comment_utils.cmotion.V then
location = context_utils.get_visual_start_location()
end
return context_internal.calculate_commentstring {
key = ctx.ctype == comment_utils.ctype.line and '__default' or
'__multiline',
location = location,
}
end
})
local neogit = require('neogit')
neogit.setup {
disable_commit_confirmation = true,
kind = 'tab',
integrations = {
diffview = true
},
disable_insert_on_commit = false
}
map('n', '<Leader>gg', neogit.open, 'Open Neogit')
-- start git commits in insert mode
vim.api.nvim_create_augroup('config_coding', { clear = true })
vim.api.nvim_create_autocmd({ 'FileType' }, {
group = 'config_coding',
pattern = { 'gitcommit', 'gitrebase' },
command = [[startinsert | 1]]
})
vim.api.nvim_create_autocmd({ 'FileType' }, {
group = 'config_coding',
pattern = { 'NeogitCommitMessage' },
callback = require('autosplit')
})
vim.api.nvim_create_autocmd({ 'FileType' }, {
group = 'config_coding',
pattern = { 'Neogit*' },
command = [[set nolist]]
})
require("nvim-autopairs").setup({})
require('luasnip.loaders.from_lua').load({
paths = vim.fn.stdpath('config') .. '/snippets'
})
require('gitsigns').setup({
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
map('n', '<Leader>gb', function() gs.blame_line({ full = true }) end,
'Show blame for current line', bufnr)
end
})
require('project_nvim').setup({
detection_methods = { 'pattern', 'lsp' },
patterns = require('my.functions').project_root_markers,
show_hidden = false,
fallback_buffer_dir = true
})
-- icons for diagnostics in the symbol column
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
local dap = require('dap')
if vim.fn.executable('lldb-vscode') > 0 then
dap.adapters.lldb = {
type = 'executable',
command = 'lldb-vscode',
name = 'lldb'
}
dap.configurations.cpp = {
{
name = 'Launch',
type = 'lldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ',
vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
args = {},
},
{
name = "Attach to process",
type = 'lldb',
request = 'attach',
pid = require('dap.utils').pick_process,
args = {},
}
}
dap.configurations.c = dap.configurations.cpp
end
map('n', '<Leader>dc', dap.continue, 'Continue')
map('n', '<F10>', dap.step_over, 'DAP: step over')
map('n', '<F11>', dap.step_into, 'DAP: step into')
map('n', '<F12>', dap.step_out, 'DAP: step out')
map('n', '<Leader>db', dap.toggle_breakpoint, 'Toggle breakpoint')
map('n', '<Leader>dB', function()
dap.set_breakpoint(vim.fn.input('Breakpoint condition: '))
end, 'Set breakpoint')
map('n', '<Leader>dr', dap.repl.open, 'Open REPL')
map('n', '<Leader>dl', dap.run_last, 'Run last')
map('n', '<Leader>dj', function()
require('dap.ext.vscode').load_launchjs(
vim.fn.input('Path to launch.json: ',
vim.fn.getcwd() .. '/launch.json', 'file'))
end, 'Load launch.json')
require('dapui').setup({})
map('n', '<Leader>du', require("dapui").toggle, 'Toggle UI')
require('nvim-dap-virtual-text').setup({})