all repos — dotfiles @ f978c99ea329a058f56dfd050f5e8d2132dc42c5

my *nix dotfiles

nvim/lua/maps.lua (view raw)

  1local cmd = vim.cmd
  2local map = vim.keymap.set
  3local dap = require 'dap'
  4local u = require 'utils'
  5local M = {}
  6
  7-- map the leader key
  8map('n', '<Space>', '', {})
  9vim.g.mapleader = ' '
 10
 11
 12local options = { silent = true }
 13map('n', '<leader><esc>', ':nohlsearch<cr>', options)
 14map('n', '<leader>n', ':bnext<cr>', options)
 15map('n', '<leader>p', ':bprev<cr>', options)
 16
 17-- search matches in the middle of the window
 18map('n', 'n', 'nzzzv', options)
 19map('n', 'N', 'Nzzzv', options)
 20
 21-- remain in visual after indenting
 22map('v', '<', '<gv', options)
 23map('v', '>', '>gv', options)
 24
 25-- Not an editor command: Wqa
 26cmd(':command! WQ wq')
 27cmd(':command! WQ wq')
 28cmd(':command! Wq wq')
 29cmd(':command! Wqa wqa')
 30cmd(':command! W w')
 31cmd(':command! Q q')
 32
 33local function fzy_ignore(patterns)
 34  local pattern_cmd = {}
 35  for _, p in ipairs(patterns) do
 36    table.insert(pattern_cmd, string.format("-E '%s'", p))
 37  end
 38
 39  return table.concat(pattern_cmd, ' ')
 40end
 41
 42--  fzy mappings
 43if vim.fn.executable('fzy') then
 44  _G.fzy_edit = require('fzy.edit').fzy_edit
 45  map(
 46    '',
 47    '<leader>e',
 48    string.format(
 49      ':call v:lua.fzy_edit("fd -t f -t l")<cr>',
 50      fzy_ignore{
 51        '*.git/*',
 52        '*node_modules*',
 53        '*.pyc',
 54        '*migrations*',
 55        '*result*',
 56        '*.direnv/*',
 57      }
 58    ),
 59    { noremap=true, silent=true }
 60  )
 61
 62  _G.fzy_buffers = require('fzy.buffers').fzy_buffers
 63  map('',
 64  '<leader>b',
 65  ':call v:lua.fzy_buffers()<cr>',
 66  { noremap=true, silent=true }
 67  )
 68
 69  _G.fzy_jmp = require('fzy.jump').fzy_jmp
 70  map('',
 71  '<leader>f',
 72  ':call v:lua.fzy_jmp()<cr>',
 73  { noremap=true, silent=true}
 74  )
 75else
 76  print('fzy not in PATH!')
 77end
 78
 79-- lspconfig
 80function M.on_attach(client, bufnr)
 81  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
 82  buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', options)
 83  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', options)
 84  buf_set_keymap('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', options)
 85  buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', options)
 86  buf_set_keymap('n', 'L', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', options)
 87  buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', options)
 88  buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', options)
 89  buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', options)
 90  buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', options)
 91  map('n', 'ff', function()
 92    vim.lsp.buf.format { async = true }
 93  end)
 94end
 95
 96-- vim.api.nvim_exec([[
 97-- " Use <Tab> and <S-Tab> to navigate through popup menu
 98-- inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
 99-- inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
100-- 
101-- ]], false)
102
103-- abbreviations
104local star = ''
105local stars = {}
106for n = 1, 5
107do
108  table.insert(stars, star)
109  u.iabbrev(n .. '*', table.concat(stars))
110end
111
112
113-- dap
114-- Start debugging session
115map("n", "<leader>ds", function()
116  dap.continue()
117  require 'dapui'.toggle()
118  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) -- Spaces buffers evenly
119end)
120
121-- Set breakpoints, get variable values, step into/out of functions, etc.
122map("n", "<leader>dl", require("dap.ui.widgets").hover)
123map("n", "<leader>dc", dap.continue)
124map("n", "<leader>db", dap.toggle_breakpoint)
125map("n", "<leader>dn", dap.step_over)
126map("n", "<leader>di", dap.step_into)
127map("n", "<leader>do", dap.step_out)
128map("n", "<leader>dC", dap.clear_breakpoints)
129
130-- Close debugger and clear breakpoints
131map("n", "<leader>de", function()
132  dap.clear_breakpoints()
133  require 'dapui'.toggle()
134  dap.terminate()
135  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false)
136end)
137
138
139return M