Compare commits
2 Commits
e78c8fc07f
...
fcd5cfbd54
Author | SHA1 | Date | |
---|---|---|---|
fcd5cfbd54 | |||
1996e631a3 |
3
after/ftplugin/c.lua
Normal file
3
after/ftplugin/c.lua
Normal file
@ -0,0 +1,3 @@
|
||||
local opts = { buffer = true, remap = false, silent = true }
|
||||
vim.keymap.set('n', '0', ':PreProcIfWrap<CR>', opts)
|
||||
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)
|
@ -1,2 +1,6 @@
|
||||
vim.opt.commentstring = '//%s'
|
||||
vim.opt.matchpairs:append('<:>')
|
||||
|
||||
local opts = { buffer = true, remap = false, silent = true }
|
||||
vim.keymap.set('n', '0', ':PreProcIfWrap<CR>', opts)
|
||||
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)
|
||||
|
@ -36,7 +36,6 @@ return {
|
||||
vim.keymap.set('n', '<leader>gF', builtin.find_files, opts)
|
||||
vim.keymap.set('n', '<leader>gf', builtin.git_files, opts)
|
||||
vim.keymap.set('n', '<leader>gg', builtin.live_grep, opts)
|
||||
vim.keymap.set('n', '<leader>rg', builtin.grep_string, opts)
|
||||
vim.keymap.set('n', '<leader>gb', builtin.buffers, opts)
|
||||
vim.keymap.set('n', '<leader>gh', builtin.help_tags, opts)
|
||||
vim.keymap.set('n', '<leader>bl', builtin.current_buffer_fuzzy_find, opts)
|
||||
|
@ -116,13 +116,38 @@ end, {
|
||||
complete = 'file',
|
||||
})
|
||||
|
||||
-- :Rg grep for the given string and fuzzy find the results, bang to enable
|
||||
-- regex in given string
|
||||
-- FIXME: Support visual select modes
|
||||
-- :Rg grep for the given string, word under the cursor, or visual selection
|
||||
-- then fuzzy find the results. Bang to enable regex in given string.
|
||||
vim.api.nvim_create_user_command('Rg', function(opts)
|
||||
local grep_opts = { search = opts.args }
|
||||
print(vim.inspect(opts))
|
||||
local search = opts.args
|
||||
if opts.range == 2 then
|
||||
local lines = vim.fn.getline(vim.fn.line("'<"), vim.fn.line("'>"))
|
||||
local start_col = vim.fn.col("'<")
|
||||
local end_col = vim.fn.col("'>")
|
||||
if #lines == 1 then
|
||||
lines[1] = string.sub(lines[1], start_col, end_col)
|
||||
else
|
||||
lines[1] = string.sub(lines[1], start_col)
|
||||
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
||||
end
|
||||
search = table.concat(lines, "\n")
|
||||
elseif #search == 0 then
|
||||
search = vim.fn.expand('<cword>')
|
||||
end
|
||||
local grep_opts = { search = search}
|
||||
if opts.bang then
|
||||
grep_opts['use_regex'] = true
|
||||
end
|
||||
require('telescope.builtin').grep_string(grep_opts)
|
||||
end, { bang = true, nargs = '*' })
|
||||
end, { bang = true, range = true, nargs = '*' })
|
||||
|
||||
vim.api.nvim_create_user_command('PreProcIfWrap', function(opts)
|
||||
local buffer = vim.api.nvim_get_current_buf()
|
||||
vim.api.nvim_buf_set_lines(
|
||||
buffer, opts.line2, opts.line2, true, { '#endif' })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
buffer, opts.line1 - 1, opts.line1 - 1, true, { '#if 0' })
|
||||
local window = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_cursor(window, { opts.line1, 5 })
|
||||
end, { range = true })
|
||||
|
@ -43,3 +43,7 @@ vim.keymap.set('t', '<C-w><C-g>', '<C-\\><C-n>:Gdb<CR>:startinsert<CR>', opts)
|
||||
vim.keymap.set('t', '<C-w><C-e>', '<C-\\><C-n>:Program<CR>', opts)
|
||||
vim.keymap.set('t', '<C-w><C-s>', '<C-\\><C-n>:Source<CR>', opts)
|
||||
vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)
|
||||
|
||||
-- Mappings to grep for then fuzzy find the word under the cursor or visual selection
|
||||
vim.keymap.set('n', '<leader>rg', ':Rg<CR>', opts)
|
||||
vim.keymap.set('v', '<leader>rg', ":'<,'>Rg<CR>", opts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user