all repos — dotfiles @ 55a74361d288fd5959556da9dd1d0c3b9f65fe15

my *nix dotfiles

nvim/lua/maps.lua (view raw)

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