all repos — dotfiles @ 8215116180f14a7375be4ac0057879d0659cc16c

my *nix dotfiles

config/nvim/lua/maps.lua (view raw)

  1local cmd = vim.cmd
  2local map = vim.keymap.set
  3local u = require 'utils'
  4local M = {}
  5
  6-- map the leader key
  7map('n', '<Space>', '', {})
  8vim.g.mapleader = ' '
  9
 10
 11local options = { silent = true }
 12map('n', '<leader><esc>', ':nohlsearch<cr>', options)
 13map('n', '<leader>n', ':bnext<cr>', options)
 14map('n', '<leader>p', ':bprev<cr>', options)
 15
 16-- search matches in the middle of the window
 17map('n', 'n', 'nzzzv', options)
 18map('n', 'N', 'Nzzzv', options)
 19
 20-- remain in visual after indenting
 21map('v', '<', '<gv', options)
 22map('v', '>', '>gv', options)
 23
 24-- Not an editor command: Wqa
 25cmd(':command! WQ wq')
 26cmd(':command! WQ wq')
 27cmd(':command! Wq wq')
 28cmd(':command! Wqa wqa')
 29cmd(':command! W w')
 30cmd(':command! Q q')
 31
 32local function fzy_ignore(patterns)
 33  local pattern_cmd = {}
 34  for _, p in ipairs(patterns) do
 35    table.insert(pattern_cmd, string.format("-E '%s'", p))
 36  end
 37
 38  return table.concat(pattern_cmd, ' ')
 39end
 40
 41--  fzy mappings
 42if vim.fn.executable('fzy') then
 43  _G.fzy_edit = require('fzy.edit').fzy_edit
 44  map(
 45    '',
 46    '<leader>e',
 47    string.format(
 48      ':call v:lua.fzy_edit("fd -t f -t l")<cr>',
 49      fzy_ignore{
 50        '*.git/*',
 51        '*node_modules*',
 52        '*.pyc',
 53        '*migrations*',
 54        '*result*',
 55        '*.direnv/*',
 56      }
 57    ),
 58    { noremap=true, silent=true }
 59  )
 60
 61  _G.fzy_buffers = require('fzy.buffers').fzy_buffers
 62  map('',
 63  '<leader>b',
 64  ':call v:lua.fzy_buffers()<cr>',
 65  { noremap=true, silent=true }
 66  )
 67
 68  _G.fzy_jmp = require('fzy.jump').fzy_jmp
 69  map('',
 70  '<leader>f',
 71  ':call v:lua.fzy_jmp()<cr>',
 72  { noremap=true, silent=true}
 73  )
 74else
 75  print('fzy not in PATH!')
 76end
 77
 78-- lspconfig
 79function M.on_attach(client, bufnr)
 80  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
 81  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
 82
 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', '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
 92  if client.server_capabilities.document_formatting then
 93    buf_set_keymap('n', 'ff', '<cmd>lua vim.lsp.buf.format()<CR>', options)
 94  elseif client.server_capabilities.document_range_formatting then
 95    buf_set_keymap('n', 'ff', '<cmd>lua vim.lsp.buf.range_formatting()<CR>', options)
 96  end
 97end
 98
 99-- vim.api.nvim_exec([[
100-- " Use <Tab> and <S-Tab> to navigate through popup menu
101-- inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
102-- inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
103-- 
104-- ]], false)
105
106-- abbreviations
107local star = ''
108local stars = {}
109for n = 1, 5
110do
111  table.insert(stars, star)
112  u.iabbrev(n .. '*', table.concat(stars))
113end
114
115return M