all repos — dotfiles @ 5674e47702a2c2b46d9df9ed4e363a61522b4cd3

my *nix dotfiles

nvim/lua/maps.lua (view raw)

 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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
local cmd = vim.cmd
local map = vim.keymap.set
local dap = require 'dap'
local treeapi = require 'nvim-tree.api'
local u = require 'utils'
local M = {}

-- map the leader key
map('n', '<Space>', '', {})
vim.g.mapleader = ' '


local options = { silent = true }
map('n', '<leader><esc>', ':nohlsearch<cr>', options)
map('n', '<leader>n', ':bnext<cr>', options)
map('n', '<leader>p', ':bprev<cr>', options)

-- search matches in the middle of the window
map('n', 'n', 'nzzzv', options)
map('n', 'N', 'Nzzzv', options)

-- remain in visual after indenting
map('v', '<', '<gv', options)
map('v', '>', '>gv', options)

-- Not an editor command: Wqa
cmd(':command! WQ wq')
cmd(':command! WQ wq')
cmd(':command! Wq wq')
cmd(':command! Wqa wqa')
cmd(':command! W w')
cmd(':command! Q q')

local function fzy_ignore(patterns)
  local pattern_cmd = {}
  for _, p in ipairs(patterns) do
    table.insert(pattern_cmd, string.format("-E '%s'", p))
  end

  return table.concat(pattern_cmd, ' ')
end

--  fzy mappings
if vim.fn.executable('fzy') then
  _G.fzy_edit = require('fzy.edit').fzy_edit
  map(
    '',
    '<leader>e',
    string.format(
      ':call v:lua.fzy_edit("fd -t f -t l")<cr>',
      fzy_ignore{
        '*.git/*',
        '*node_modules*',
        '*.pyc',
        '*migrations*',
        '*result*',
        '*.direnv/*',
      }
    ),
    { noremap=true, silent=true }
  )

  _G.fzy_buffers = require('fzy.buffers').fzy_buffers
  map('',
  '<leader>b',
  ':call v:lua.fzy_buffers("NvimTree_1")<cr>',
  { noremap=true, silent=true }
  )

  _G.fzy_jmp = require('fzy.jump').fzy_jmp
  map('',
  '<leader>f',
  ':call v:lua.fzy_jmp()<cr>',
  { noremap=true, silent=true}
  )
else
  print('fzy not in PATH!')
end

-- lspconfig
function M.on_attach(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', options)
  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', options)
  buf_set_keymap('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', options)
  buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', options)
  buf_set_keymap('n', 'L', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', options)
  buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', options)
  buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', options)
  buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', options)
  buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', options)
  map('n', 'ff', function()
    vim.lsp.buf.format { async = true }
  end)
end

-- vim.api.nvim_exec([[
-- " Use <Tab> and <S-Tab> to navigate through popup menu
-- inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
-- inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
-- 
-- ]], false)

-- abbreviations
local star = '★'
local stars = {}
for n = 1, 5
do
  table.insert(stars, star)
  u.iabbrev(n .. '*', table.concat(stars))
end


-- dap
-- Start debugging session
map("n", "<leader>ds", function()
  dap.continue()
  require 'dapui'.open()
  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) -- Spaces buffers evenly
end)

-- Set breakpoints, get variable values, step into/out of functions, etc.
map("n", "<leader>dl", require("dap.ui.widgets").hover)
map("n", "<leader>dc", dap.continue)
map("n", "<leader>db", dap.toggle_breakpoint)
map("n", "<leader>dn", dap.step_over)
map("n", "<leader>di", dap.step_into)
map("n", "<leader>do", dap.step_out)
map("n", "<leader>dC", dap.clear_breakpoints)

-- Close debugger and clear breakpoints
map("n", "<leader>de", function()
  dap.clear_breakpoints()
  require 'dapui'.close()
  dap.terminate()
  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false)
end)


local function toggle_tree()
  treeapi.tree.toggle({ find_file = true })
end

-- nvim-tree
map('n', '<leader>tt', toggle_tree)
map('n', '<leader>tf', treeapi.tree.focus)

return M