VIM updates
- updated keybindings to match work - added functions for finding files
This commit is contained in:
parent
8129a8a2f3
commit
b1f1ff8545
@ -1,15 +1,22 @@
|
||||
-- FUNCTIONS --
|
||||
|
||||
-- all language functions
|
||||
vim.cmd [[
|
||||
augroup lang_all
|
||||
autocmd!
|
||||
autocmd FileType * luafile ~/.config/nvim/lua/func/utils.lua
|
||||
autocmd FileType * luafile ~/.config/nvim/lua/func/tabline.lua
|
||||
autocmd FileType * luafile ~/.config/nvim/lua/func/popterm.lua
|
||||
autocmd FileType * luafile ~/.config/nvim/lua/func/sessions.lua
|
||||
augroup END
|
||||
]]
|
||||
require('func.utils')
|
||||
require('func.tabline')
|
||||
require('func.popterm')
|
||||
require('func.sessions')
|
||||
require('func.findfile')
|
||||
|
||||
-- vim.cmd [[
|
||||
-- augroup lang_all
|
||||
-- autocmd!
|
||||
-- autocmd FileType * luafile ~/.config/nvim/lua/func/utils.lua
|
||||
-- autocmd FileType * luafile ~/.config/nvim/lua/func/tabline.lua
|
||||
-- autocmd FileType * luafile ~/.config/nvim/lua/func/popterm.lua
|
||||
-- autocmd FileType * luafile ~/.config/nvim/lua/func/sessions.lua
|
||||
-- autocmd FileType * luafile ~/.config/nvim/lua/func/findfile.lua
|
||||
-- augroup END
|
||||
-- ]]
|
||||
|
||||
-- puppet language keybindings
|
||||
vim.cmd [[
|
||||
|
||||
72
.config/nvim/lua/func/findfile.lua
Normal file
72
.config/nvim/lua/func/findfile.lua
Normal file
@ -0,0 +1,72 @@
|
||||
vim.cmd([[
|
||||
let g:previous_buffer = 0
|
||||
|
||||
function! FindFile()
|
||||
" Store the buffer number of the current window
|
||||
let g:previous_buffer = bufnr('%')
|
||||
|
||||
" Prompt user for search pattern
|
||||
let pattern = input('Enter search pattern: ')
|
||||
let escaped_pattern = escape(pattern, '\/$.*[~')
|
||||
"let cmd = "grep -Rl " . escaped_pattern . " *"
|
||||
let cmd = "rg --column --no-heading --color=never -l " . shellescape(escaped_pattern)
|
||||
|
||||
|
||||
" Get the search results as a list
|
||||
let results = systemlist(cmd)
|
||||
if empty(results)
|
||||
echo "No files found for pattern: " . pattern
|
||||
return
|
||||
endif
|
||||
|
||||
" Open a new split window at the bottom
|
||||
new
|
||||
" Set the height of the new split window
|
||||
resize 10
|
||||
|
||||
" Set the buffer to be unlisted, no swapfile
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
|
||||
|
||||
" Clear the 'readonly' option in case it's set by default
|
||||
setlocal noreadonly
|
||||
|
||||
" Populate the buffer with the search results
|
||||
call setline(1, results)
|
||||
|
||||
" Make the buffer read-only after populating it
|
||||
setlocal readonly
|
||||
|
||||
" Map keys to open files in different modes
|
||||
nnoremap <silent> <buffer> <CR> :call OpenFile('edit', g:previous_buffer)<CR>
|
||||
nnoremap <silent> <buffer> v :call OpenFile('vsplit', g:previous_buffer)<CR>
|
||||
nnoremap <silent> <buffer> h :call OpenFile('split', g:previous_buffer)<CR>
|
||||
nnoremap <silent> <buffer> t :call OpenFile('tabedit', g:previous_buffer)<CR>
|
||||
|
||||
" Focus on the results window
|
||||
normal! G
|
||||
endfunction
|
||||
|
||||
function! OpenFile(openType, bufnr)
|
||||
" Extract the file path from the current line
|
||||
let file_path = getline('.')
|
||||
if filereadable(file_path)
|
||||
" Save the current buffer number
|
||||
let current_bufnr = bufnr('%')
|
||||
" Close the search results window
|
||||
bd!
|
||||
" Switch to the buffer that was active before the search
|
||||
execute 'buffer' g:previous_buffer
|
||||
" Open the file based on the specified openType
|
||||
execute a:openType . ' ' . file_path
|
||||
" If opening in a new tab, switch back to the original buffer in the new tab
|
||||
if a:openType == 'tabnew'
|
||||
execute 'tabnext'
|
||||
execute 'buffer' . current_bufnr
|
||||
endif
|
||||
else
|
||||
echo "File does not exist or cannot be read"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
nnoremap <Leader>ff :call FindFile()<CR>
|
||||
]])
|
||||
@ -1,4 +1,9 @@
|
||||
vim.cmd([[
|
||||
let g:session_dir = expand('~/.cache/nvim/sessions/')
|
||||
if !isdirectory(g:session_dir)
|
||||
call mkdir(g:session_dir, "p")
|
||||
endif
|
||||
|
||||
command! SaveSession call SaveSession()
|
||||
function! SaveSession()
|
||||
let session_file = g:session_dir . GetRepositoryName() . '_' . GetCurrentGitBranch() . '.vim'
|
||||
|
||||
@ -48,6 +48,6 @@ map('n', 'ff', [[:Telescope find_files]], {})
|
||||
-- map('n', 'T', ':lua require("FTerm").toggle()<CR>', {})
|
||||
|
||||
-- Open a file in a vertical split, horizontal split and move a split to a new tab
|
||||
map('n', '<Leader>sv', ':vsplit ', {noremap = true, silent = false})
|
||||
map('n', '<Leader>sh', ':split ', {noremap = true, silent = false})
|
||||
map('n', '<Leader>ov', ':vsplit ', {noremap = true, silent = false})
|
||||
map('n', '<Leader>oh', ':split ', {noremap = true, silent = false})
|
||||
map('n', '<Leader>mt', ':tabedit %<CR>', {noremap = true, silent = true})
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 8bafa7394bfcb8cfbafc43190be64cee6e70aa7c
|
||||
Subproject commit ba169ed5b0c16f6bd9cedf88d4b54ba369d4a19c
|
||||
Loading…
Reference in New Issue
Block a user