Improve ctrlp ctag situation and add some jai searching

This commit is contained in:
Michael Campagnaro 2022-12-29 19:20:10 -05:00
parent 0227534656
commit 2640761dc5

92
vimrc
View File

@ -15,6 +15,8 @@
"
"###################################################################################################
let g:campo_vimrc_initialized = 0 " Will be set to 1 at the end of the file. Can be used to avoid changes on subsequent vimrc reloads.
scriptencoding utf-8
" @note If the file contains a BOM then vim will automatically set `bomb` for
" the buffer so that the BOM is written out again.
@ -62,18 +64,19 @@ endfunction
" file in the root folder that you want it applied to.
"
" Some variables cannot be customized in an .lvimrc because their value is used
" by settings in this file when it's sourced. These have been flagged with a note.
" by settings in this file when it's sourced. These have been flagged with the
" note :unsupported-in-lvimrc.
"
" Also take note that an .lvimrc has precedence because it's loaded after this
" and the private vimrc.
" --------------------------------------------------------------------------------------------------
" @note unsupported in lvimrc
" @note :unsupported-in-lvimrc
let g:campo_max_line_length = 120 " Display a vertical bar at x=<n>.
" Set the row height of the quickfix pane, which is used to display results
" from various plugins (like ctrl-p, ripgrep, compilation errors, etc), in rows
" from various plugins (like ctrlp, ripgrep, compilation errors, etc), in rows
let g:quickfix_pane_height = 20
""""""""""""""
@ -140,8 +143,9 @@ let g:campo_custom_search_args = ""
""""""""""""""
" CTAGS
""""""""""""""
" I use the ctags executable from https://github.com/universal-ctags/ctags-win32/releases
"
" Be sure to check out the ctags plugin config in section #3 for additional API functions.
" If != 0 then ctag generation will always happen on a file save, otherwise
" it'll only be triggered if the file being saved has an extension in the
@ -169,6 +173,13 @@ let g:campo_ctags_exclude = ['*.txt', '*.config', '.cache']
" * Exclude a directory with `let g:campo_custom_ctags_args = '--exclude=3rd_party'`
let g:campo_custom_ctags_args = ""
""""""""""""""
" JAI
""""""""""""""
" Set to your Jai install path. Used for various commands, like for example
" searching the modules and how_to directories with CtrlP
let g:campo_jai_path = ''
"################################################################
"################################################################
"################################################################
@ -881,6 +892,29 @@ let g:syntastic_check_on_wq = 0
let g:rg_highlight = 1
let g:rg_window_height = g:quickfix_pane_height
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" C-TAGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set extra paths to use when searching for ctags files. By default the current
" directory is always checked. You can use this to combine tag lookups from
" different projects, e.g. set it to the Jai directory and you can look up
" current project tags and Jai module tags (of course this isn't needed if you
" have Jai module tags in your local file).
"
" This destructively overwrites the tags option value.
"
" Call this from a .vimrc.private or .lvimrc file, e.g.
" call g:SetExtraCtagsPaths([g:campo_jai_path.'/tags'])
"
function! g:SetExtraCtagsPaths(paths_array)
let l:list = './tags,tags' " This is the default tags list set by vim.
for path in a:paths_array
let l:list = l:list . ',' . path
endfor
let &tags=l:list
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTRL-P
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -900,7 +934,43 @@ let g:rg_window_height = g:quickfix_pane_height
" ctrl-o = ask how to open a file search result.
" ctrl-p | ctrl-n = traverse search history.
noremap <leader>g :CtrlP<cr>
" CtrlP finds the tags file by using vim's 'tags' option value. I initially
" tried changing the tags value to the working_path if one is provided. I made
" a copy of the current tags value and attempted to restore it when CtrlP was
" exited without an action or a tag action took place. I wasn't able to get
" the tags restored because there's no vim event that gets triggered when a
" tag is opened using the :tag comment. I tried a bunch of autocmds on buffer,
" window and cmdline events but wasn't able to find anything that fired AFTER
" the tag command. So we're instead just setting the tags list once for the
" session and not bothering with changing it on the fly. See g:SetExtraCtagsPaths
function! CtrlP_Search(search_path)
" If a:search_path is empty then ctrlp will use g:ctrlp_working_path_mode to determine the cwd to search in.
execute 'CtrlP ' . a:search_path
endfunction
function! CtrlP_JaiSearch(jai_rel_search_path)
if g:campo_jai_path == ''
call PrintError("g:campo_jai_path isn't set!")
return
endif
let l:path = g:campo_jai_path
if a:jai_rel_search_path != ''
let l:path = l:path. '/' . a:jai_rel_search_path
endif
if !isdirectory(l:path)
call PrintError("Directory ".l:path." doesn't exist.")
return
endif
call CtrlP_Search(l:path)
endfunction
" CtrlP File Searching
noremap <leader>g :call CtrlP_Search('')<cr> " Search in current directory
noremap <leader>gg :call CtrlP_JaiSearch('')<cr> " Search in Jai directory
noremap <leader>gm :call CtrlP_JaiSearch('modules')<cr> " Search in Jai modules
noremap <leader>gh :call CtrlP_JaiSearch('how_to')<cr> " Search in Jai how_to
noremap <leader>ge :call CtrlP_JaiSearch('examples')<cr> " Search in Jai examples
let g:ctrlp_map = '<leader>f'
let g:ctrlp_cmd = 'CtrlPTag' " Search tags by default.
let g:ctrlp_by_filename = 1 " File search by filename as opposed to full path.
@ -912,12 +982,6 @@ let g:ctrlp_switch_buffer = 'et' " If a file is already open, open it again in a
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard'] " If a git repo, use checked in files (ignore things in .gitignore); fallback to globpath()
" @fixme Not sure why I can't get these new mappings (c-m, c-cr) to register...
"let g:ctrlp_prompt_mappings = {
" \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>'],
" \ 'AcceptSelection("v")': ['<c-v>', '<c-m>'],
" \ }
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GIT
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -984,11 +1048,6 @@ function! ReloadRainbow()
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" C-TAGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tags+=tags;$HOME
"---------------------------------------------------------------------------------------------------
"################################################################
@ -1441,3 +1500,4 @@ noremap <leader>n :call RenameFile()<cr>
"---------------------------------------------------------------------------------------------------
let g:campo_vimrc_initialized = 1