all repos — dotfiles @ c910c80f6037defa36e95fc0cce605d8da382112

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