Rename stuff in vimrc
This commit is contained in:
parent
a529cd6560
commit
2a57ce8837
124
vimrc
124
vimrc
|
@ -26,12 +26,12 @@ let s:uname = system("echo -n \"$(uname)\"")
|
|||
let g:vim_dir = $HOME . "/.vim"
|
||||
let mapleader=","
|
||||
|
||||
function! IsWindows()
|
||||
fu! IsWindows()
|
||||
if s:uname =~ "mingw" || s:uname =~ "msys"
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
if has('termguicolors')
|
||||
set termguicolors
|
||||
|
@ -40,12 +40,12 @@ if has('termguicolors')
|
|||
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
|
||||
endif
|
||||
|
||||
function! PrintError(msg) abort
|
||||
fu! PrintError(msg) abort
|
||||
exec 'normal! \<Esc>'
|
||||
echohl ErrorMsg
|
||||
echomsg a:msg
|
||||
echohl None
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
|
||||
"|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
|
@ -193,13 +193,13 @@ let g:campo_custom_ctags_args = ""
|
|||
" call g:SetExtraCtagsPaths([g:campo_jai_path.'/tags'])
|
||||
"
|
||||
" You can see what your ctags search list is set to in the editor with :echo &tags
|
||||
function! g:SetExtraCtagsPaths(paths_array)
|
||||
fu! 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 .= ',' . path
|
||||
endfor
|
||||
let &tags=l:list
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
|
||||
"##################################################################################
|
||||
|
@ -475,7 +475,7 @@ augroup campoCmds
|
|||
autocmd BufWritePost ~/.vimrc_templates.private silent! source $MYVIMRC
|
||||
|
||||
" Remove trailing whitespace when saving any file.
|
||||
function! StripTrailingWhitespaces()
|
||||
fu! StripTrailingWhitespaces()
|
||||
if g:campo_strip_trailing_whitespace == 1
|
||||
if len(g:campo_directories_to_ignore_when_stripping_trailing_whitespace)
|
||||
for path in g:campo_directories_to_ignore_when_stripping_trailing_whitespace
|
||||
|
@ -671,7 +671,7 @@ nnoremap <c-g> :%s///g<left><left>
|
|||
" order to only call it once for a group of saves I've had to remap the
|
||||
" various save commands to a function call.
|
||||
|
||||
function! CreateCtags()
|
||||
fu! CreateCtags()
|
||||
" Only allow one instance of ctags to run in this directory at any given time.
|
||||
let l:lock_file = "ctags.lock"
|
||||
if filereadable(l:lock_file) || filereadable("newtags")
|
||||
|
@ -725,32 +725,32 @@ endfun
|
|||
" These write functions below will not be reloaded because they initiate the
|
||||
" save. So if you make changes to them then you need to manually reload this
|
||||
" file using <leader>rv or whatever. :ReloadVimrcError
|
||||
function! WriteCurrentFileAndCreateCtags()
|
||||
fu! WriteCurrentFileAndCreateCtags()
|
||||
write!
|
||||
call CreateCtags()
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! WriteCurrentFileAndCreateCtagsThenQuit()
|
||||
fu! WriteCurrentFileAndCreateCtagsThenQuit()
|
||||
write!
|
||||
call CreateCtags()
|
||||
quit
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
" @fixme Sometimes a :wa that saves multiple files causes vim to hang and use a lot of CPU.
|
||||
function! WriteAllModifiedFilesAndCreateCtags()
|
||||
fu! WriteAllModifiedFilesAndCreateCtags()
|
||||
wall!
|
||||
call CreateCtags()
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
" Create a command abbreviation that only applies when it's at the beginning
|
||||
" of a ex command. If you were to do a normal cnoreabbrev or cabbrev then the
|
||||
" subsitution can happen anywhere in the command line. It was mostly affecting
|
||||
" my text search; I'd type '/w' and it would be replaced with the call to save
|
||||
" and create ctags.
|
||||
function! Cabbrev(key, value)
|
||||
fu! Cabbrev(key, value)
|
||||
exe printf('cabbrev <expr> %s (getcmdtype() == ":" && getcmdpos() <= %d) ? %s : %s',
|
||||
\ a:key, len(a:key)+1, string(a:value), string(a:key))
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
call Cabbrev('w', 'call WriteCurrentFileAndCreateCtags()')
|
||||
call Cabbrev('W', 'call WriteCurrentFileAndCreateCtags()')
|
||||
|
@ -774,14 +774,14 @@ noremap Q <Nop>
|
|||
"##################################################################################
|
||||
" MULTIPURPOSE TAB KEY
|
||||
"##################################################################################
|
||||
function! InsertTabWrapper()
|
||||
fu! InsertTabWrapper()
|
||||
let l:col = col('.') - 1
|
||||
if !l:col || getline('.')[l:col - 1] !~ '\k'
|
||||
return "\<tab>"
|
||||
else
|
||||
return "\<c-p>"
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
|
||||
inoremap <s-tab> <c-n>
|
||||
|
||||
|
@ -883,12 +883,12 @@ let g:rg_window_height = g:quickfix_pane_height
|
|||
" 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)
|
||||
fu! 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
|
||||
endfu
|
||||
|
||||
function! CtrlP_JaiSearch(jai_rel_search_path)
|
||||
fu! CtrlP_JaiSearch(jai_rel_search_path)
|
||||
if g:campo_jai_path == ''
|
||||
call PrintError("g:campo_jai_path isn't set!")
|
||||
return
|
||||
|
@ -902,7 +902,7 @@ function! CtrlP_JaiSearch(jai_rel_search_path)
|
|||
return
|
||||
endif
|
||||
call CtrlP_Search(l:path)
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
" CtrlP File Searching
|
||||
noremap <leader>g :call CtrlP_Search('')<cr> " Search in current directory
|
||||
|
@ -952,7 +952,7 @@ let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gr
|
|||
let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray']
|
||||
let s:rainbow_theme = g:campo_light_dark_mode
|
||||
|
||||
function! UpdateRainbowConf()
|
||||
fu! UpdateRainbowConf()
|
||||
let g:rainbow_conf = {
|
||||
\ 'ctermfgs': (s:rainbow_theme == "light"? s:dark_rainbow : s:light_rainbow)
|
||||
\}
|
||||
|
@ -960,11 +960,11 @@ function! UpdateRainbowConf()
|
|||
"\ '*': 0, " Disable all
|
||||
"\ 'c++': {} " Only enable c++
|
||||
"\ }
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
call UpdateRainbowConf()
|
||||
|
||||
function! ReloadRainbow()
|
||||
fu! ReloadRainbow()
|
||||
if g:campo_theme_use_rainbow_parens
|
||||
if exists(':RainbowToggle')
|
||||
call UpdateRainbowConf()
|
||||
|
@ -977,7 +977,7 @@ function! ReloadRainbow()
|
|||
call rainbow#clear()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
|
||||
"|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
|
@ -999,15 +999,15 @@ noremap <leader>l :call ToggleLightDarkTheme()<cr>
|
|||
|
||||
let s:current_light_dark_mode = g:campo_light_dark_mode
|
||||
|
||||
function! ToggleLightDarkTheme()
|
||||
fu! ToggleLightDarkTheme()
|
||||
if s:current_light_dark_mode == 'light'
|
||||
call ChangeLightDarkMode('dark', 0)
|
||||
else
|
||||
call ChangeLightDarkMode('light', 0)
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! ChangeLightDarkMode(mode, onlySetTheme)
|
||||
fu! ChangeLightDarkMode(mode, onlySetTheme)
|
||||
if a:mode == 'light'
|
||||
let s:rainbow_theme = 'light'
|
||||
let s:theme = g:campo_light_theme
|
||||
|
@ -1028,7 +1028,7 @@ function! ChangeLightDarkMode(mode, onlySetTheme)
|
|||
if !a:onlySetTheme
|
||||
exec 'AirlineTheme' a:mode
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
" Set the intial light/dark mode.
|
||||
if g:campo_light_dark_mode =~ 'light'
|
||||
|
@ -1038,14 +1038,14 @@ else
|
|||
endif
|
||||
|
||||
" Open the current color scheme for editing.
|
||||
function! EditColorScheme()
|
||||
fu! EditColorScheme()
|
||||
let l:path = g:vim_dir . '/colors/' . s:theme . '.vim'
|
||||
if filereadable(l:path)
|
||||
execute 'vsplit ' . l:path
|
||||
else
|
||||
call PrintError("Failed to open " . l:path . " for editing.")
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
command -nargs=0 EditColorScheme call EditColorScheme()
|
||||
|
||||
|
@ -1129,10 +1129,10 @@ let errormarker_warninggroup = "BuildWarn"
|
|||
let errormarker_infogroup = "BuildInfo"
|
||||
|
||||
" I don't know how to map to a plugin command, so I'm wrapping it with a function...ugh.
|
||||
function! ShowErrorAtCursor()
|
||||
fu! ShowErrorAtCursor()
|
||||
" This is defined in errormarker.vim
|
||||
ErrorAtCursor
|
||||
endfunction
|
||||
endfu
|
||||
nnoremap <leader>ce :call ShowErrorAtCursor()<cr>
|
||||
|
||||
"/////////////////////////////////////////////////
|
||||
|
@ -1143,7 +1143,7 @@ nnoremap <leader>ce :call ShowErrorAtCursor()<cr>
|
|||
" This will print the valid entries. You'll know parsing is correct when the
|
||||
" entries have a type, line num, error message, etc.
|
||||
|
||||
function! ShowErrorEntries()
|
||||
fu! ShowErrorEntries()
|
||||
" Prints out valid quickfix errors.
|
||||
redraw!
|
||||
for l:d in getqflist()
|
||||
|
@ -1151,7 +1151,7 @@ function! ShowErrorEntries()
|
|||
echomsg l:d
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
endfu
|
||||
command -nargs=0 ShowErrorEntries call ShowErrorEntries()
|
||||
|
||||
" Jai
|
||||
|
@ -1185,25 +1185,25 @@ set errorformat+=\\\ %#%f(%l\\\,%c-%*[0-9]):\ %#%t%[A-z]%#\ %m
|
|||
" BUILD FUNCTIONS
|
||||
"/////////////////////////////////////////////////
|
||||
|
||||
function! HideBuildResultsAndClearErrors()
|
||||
fu! HideBuildResultsAndClearErrors()
|
||||
RemoveErrorMarkers
|
||||
call asyncrun#quickfix_toggle(g:quickfix_pane_height, 0)
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! HideAsyncResults()
|
||||
fu! HideAsyncResults()
|
||||
call asyncrun#quickfix_toggle(g:quickfix_pane_height, 0)
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! ToggleBuildResults()
|
||||
fu! ToggleBuildResults()
|
||||
call asyncrun#quickfix_toggle(g:quickfix_pane_height)
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! StopRunTask()
|
||||
fu! StopRunTask()
|
||||
AsyncStop
|
||||
call HideAsyncResults()
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! Build(optimized=0, silent=0)
|
||||
fu! Build(optimized=0, silent=0)
|
||||
let l:async_cmd = "AsyncRun! "
|
||||
if a:silent
|
||||
let l:async_cmd .= "-post=call\\ HideAsyncResults() "
|
||||
|
@ -1290,9 +1290,9 @@ function! Build(optimized=0, silent=0)
|
|||
" be generated so we're handling the save ourselves.
|
||||
call WriteAllModifiedFilesAndCreateCtags()
|
||||
exec l:async_cmd . l:cmd
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! RunProgram()
|
||||
fu! RunProgram()
|
||||
let l:ran = 0
|
||||
let l:ext = tolower(expand('%:e'))
|
||||
let l:path_to_use = ""
|
||||
|
@ -1352,7 +1352,7 @@ function! RunProgram()
|
|||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
" Show results window the moment the async job starts
|
||||
augroup asyncPluginCmds
|
||||
|
@ -1394,7 +1394,7 @@ nnoremap <C-p> :cp<CR>
|
|||
"##################################################################################
|
||||
|
||||
" Search using ripgrep (first install with Rust: cargo install ripgrep).
|
||||
function! Search(path, search_args, case_insensitive=0)
|
||||
fu! Search(path, search_args, case_insensitive=0)
|
||||
let l:helper = "Search '" . a:path . "' (" . (len(a:search_args) > 0 ? a:search_args . " | " : '') . (a:case_insensitive ? "INSENSITIVE" : "SENSITIVE") . "): "
|
||||
let l:term = input(l:helper)
|
||||
if empty(l:term)
|
||||
|
@ -1415,9 +1415,9 @@ function! Search(path, search_args, case_insensitive=0)
|
|||
let l:format = 'Rg ' . l:rg_args . ' ' . a:path . ' -e %s'
|
||||
let l:cmd = printf(l:format, shellescape(l:escaped_term))
|
||||
exec l:cmd
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! SearchExt(path, search_args, case_insensitive=0)
|
||||
fu! SearchExt(path, search_args, case_insensitive=0)
|
||||
call inputsave()
|
||||
let l:ext = input('Enter extension to search on (leave blank for files with no ext): ')
|
||||
call inputrestore()
|
||||
|
@ -1432,7 +1432,7 @@ function! SearchExt(path, search_args, case_insensitive=0)
|
|||
let l:args = a:search_args." -g \"".l:ext."\""
|
||||
|
||||
call Search(a:path, l:args, a:case_insensitive)
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
"/////////////////////////////////////////////////
|
||||
" SEARCH IN CURRENT WORKING DIRECTORY
|
||||
|
@ -1508,7 +1508,7 @@ nnoremap <expr> p (&buftype is# "quickfix" ? "<CR>\|:copen<CR>" : "p")
|
|||
|
||||
" Replace text in a git repo's committed files.
|
||||
" The range identifier allows us to run this once when multiple lines are selected in a file.
|
||||
function! GlobalReplaceIt(confirm_replacement) range
|
||||
fu! GlobalReplaceIt(confirm_replacement) range
|
||||
if exists(':Ggrep')
|
||||
call inputsave()
|
||||
if a:confirm_replacement
|
||||
|
@ -1561,7 +1561,7 @@ function! GlobalReplaceIt(confirm_replacement) range
|
|||
else
|
||||
call PrintError("Unable to search since you're not in a git repo!")
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
noremap <leader>r :call GlobalReplaceIt(0)<cr>
|
||||
noremap <leader>rr :call GlobalReplaceIt(1)<cr>
|
||||
|
||||
|
@ -1570,7 +1570,7 @@ noremap <leader>rr :call GlobalReplaceIt(1)<cr>
|
|||
" RENAME CURRENT FILE
|
||||
"##################################################################################
|
||||
|
||||
function! RenameFile()
|
||||
fu! RenameFile()
|
||||
let l:old_name = expand('%')
|
||||
let l:new_name = input('New file name: ', expand('%'), 'file')
|
||||
if l:new_name != '' && l:new_name != l:old_name
|
||||
|
@ -1581,7 +1581,7 @@ function! RenameFile()
|
|||
redraw!
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
noremap <leader>n :call RenameFile()<cr>
|
||||
|
||||
|
||||
|
@ -1589,19 +1589,19 @@ noremap <leader>n :call RenameFile()<cr>
|
|||
" CENTER THE BUFFER
|
||||
"##################################################################################
|
||||
|
||||
function! CenterPane()
|
||||
fu! CenterPane()
|
||||
" Centers the current pane as the middle 2 of 4 imaginary columns should
|
||||
" be called in a window with a single pane.
|
||||
" Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim
|
||||
lefta vnew
|
||||
wincmd w
|
||||
exec 'vertical resize' string(&columns * 0.65)
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
function! RemoveCenterPane()
|
||||
fu! RemoveCenterPane()
|
||||
wincmd w
|
||||
close
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
nnoremap <leader>cc :call CenterPane()<cr>
|
||||
nnoremap <leader>cd :call RemoveCenterPane()<cr>
|
||||
|
@ -1614,7 +1614,7 @@ nnoremap <leader>cd :call RemoveCenterPane()<cr>
|
|||
" Applies a clean view of the current buffer by turning off line
|
||||
" numbers, trailing spaces, tabs and git diff markers in the gutter.
|
||||
|
||||
function! ToggleSimpleView()
|
||||
fu! ToggleSimpleView()
|
||||
" I wasn't able to get this to apply to every copy of the same buffer,
|
||||
" e.g. you have a split view showing the same file; only the active one
|
||||
" will be affected, but they will share the same state! I tried many
|
||||
|
@ -1640,7 +1640,7 @@ function! ToggleSimpleView()
|
|||
setlocal list
|
||||
exec 'GitGutterBufferEnable'
|
||||
endif
|
||||
endfunction
|
||||
endfu
|
||||
|
||||
nnoremap <leader>c :call ToggleSimpleView()<cr>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user