all repos — dotfiles @ 5f5761bb63ecf770eb02f00e6466f78a0a568436

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-- remain in visual after indenting
20map('v', '<', '<gv', options)
21map('v', '>', '>gv', options)
22
23-- Not an editor command: Wqa
24cmd(':command! WQ wq')
25cmd(':command! WQ wq')
26cmd(':command! Wq wq')
27cmd(':command! Wqa wqa')
28cmd(':command! W w')
29cmd(':command! Q q')
30
31local function fzy_ignore(patterns)
32  pattern_cmd = {}
33  for _, p in ipairs(patterns) do
34    table.insert(pattern_cmd, string.format("! -path '%s'", p))
35  end
36
37  return table.concat(pattern_cmd, ' ')
38end
39
40--  fzy mappings
41if vim.fn.executable('fzy') then
42  _G.fzy_edit = require('fzy.edit').fzy_edit
43  map(
44    '',
45    '<leader>e',
46    string.format(
47      ':call v:lua.fzy_edit("find -L . -type f %s | cut -c3-")<cr>',
48      fzy_ignore{'*.git/*', '*node_modules*', '*.pyc', '*migrations*'}
49    ),
50    { noremap=true, silent=true }
51  )
52
53  _G.fzy_buffers = require('fzy.buffers').fzy_buffers
54  map('',
55  '<leader>b',
56  ':call v:lua.fzy_buffers()<cr>',
57  { noremap=true, silent=true }
58  )
59
60  _G.fzy_jmp = require('fzy.jump').fzy_jmp
61  map('',
62  '<leader>f',
63  ':call v:lua.fzy_jmp()<cr>',
64  { noremap=true, silent=true}
65  )
66else
67  print('fzy not in PATH!')
68end
69
70-- lspconfig
71function M.on_attach(client, bufnr)
72  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
73  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
74
75  buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', options)
76  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', options)
77end
78
79vim.api.nvim_exec([[
80" Use <Tab> and <S-Tab> to navigate through popup menu
81inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
82inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
83
84" Set completeopt to have a better completion experience
85set completeopt=menuone,noinsert,noselect
86
87" Avoid showing message extra message when using completion
88set shortmess+=c
89
90]], false)
91
92return M