all repos — dotfiles @ 13e6298f33be60b6b6d3bfe0b30dc4f55aab02d0

my *nix dotfiles

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

 1local cmd = vim.cmd
 2local map = vim.api.nvim_set_keymap
 3local M = {}
 4
 5-- map the leader key
 6map('n', '<Space>', '', {})
 7vim.g.mapleader = ' '
 8
 9
10local options = { noremap = true, silent = true }
11map('n', '<leader><esc>', ':nohlsearch<cr>', options)
12map('n', '<leader>n', ':bnext<cr>', options)
13map('n', '<leader>p', ':bprev<cr>', options)
14
15-- search matches in the middle of the window
16map('n', 'n', 'nzzzv', options)
17map('n', 'N', 'Nzzzv', options)
18
19-- Not an editor command: Wqa
20cmd(':command! WQ wq')
21cmd(':command! WQ wq')
22cmd(':command! Wq wq')
23cmd(':command! Wqa wqa')
24cmd(':command! W w')
25cmd(':command! Q q')
26
27local function fzy_ignore(patterns)
28  pattern_cmd = {}
29  for _, p in ipairs(patterns) do
30    table.insert(pattern_cmd, string.format("! -path '%s'", p))
31  end
32
33  return table.concat(pattern_cmd, ' ')
34end
35
36--  fzy mappings
37if vim.fn.executable('fzy') then
38  _G.fzy_edit = require('fzy.edit').fzy_edit
39  map(
40    '',
41    '<leader>e',
42    string.format(
43      ':call v:lua.fzy_edit("find -L . -type f %s | cut -c3-")<cr>',
44      fzy_ignore{'*.git/*', '*node_modules*', '*.pyc', '*migrations*'}
45    ),
46    { noremap=true, silent=true }
47  )
48
49  _G.fzy_buffers = require('fzy.buffers').fzy_buffers
50  map('',
51  '<leader>b',
52  ':call v:lua.fzy_buffers()<cr>',
53  { noremap=true, silent=true }
54  )
55
56  _G.fzy_jmp = require('fzy.jump').fzy_jmp
57  map('',
58  '<leader>f',
59  ':call v:lua.fzy_jmp()<cr>',
60  { noremap=true, silent=true}
61  )
62else
63  print('fzy not in PATH!')
64end
65
66-- lspconfig
67function M.on_attach(client, bufnr)
68  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
69  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
70
71  buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', options)
72  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', options)
73end
74
75-- completion-nvim
76-- FIXME: rewrite this in Lua
77vim.api.nvim_exec([[
78" Use <Tab> and <S-Tab> to navigate through popup menu
79inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
80inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
81
82" Set completeopt to have a better completion experience
83set completeopt=menuone,noinsert,noselect
84
85" Avoid showing message extra message when using completion
86set shortmess+=c
87
88]], false)
89
90
91-- walmart autopairs
92-- vim.api.nvim_set_keymap('i', '{', '{}<esc>i', options)
93-- vim.api.nvim_set_keymap('i', '(', '()<esc>i', options)
94-- vim.api.nvim_set_keymap('i', '[', '[]<esc>i', options)
95-- vim.api.nvim_set_keymap('i', '\'', '\'\'<esc>i', options)
96-- vim.api.nvim_set_keymap('i', '\"', '\"\"<esc>i', options)
97
98return M