about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--configs/.vimrc19
-rw-r--r--functions/misc_functions.sh17
2 files changed, 35 insertions, 1 deletions
diff --git a/configs/.vimrc b/configs/.vimrc
index 3cabc22cf960..11e3c52e8190 100644
--- a/configs/.vimrc
+++ b/configs/.vimrc
@@ -438,7 +438,7 @@ vnoremap L $
 
 
 " Search for visually selected text
-vnoremap // y/<C-r>"<CR>N
+" vnoremap // y/<C-r>"<CR>N
 
 
 " trim trailing whitespace on save
@@ -459,3 +459,20 @@ let g:ctrlp_custom_ignore = {
   \ 'file': '\v\.(exe|dll|png|jpg|jpeg)$'
 \}
 
+
+" Search within a visual selection
+function! RangeSearch(direction)
+  call inputsave()
+  let g:srchstr = input(a:direction)
+  call inputrestore()
+  if strlen(g:srchstr) > 0
+    let g:srchstr = g:srchstr.
+          \ '\%>'.(line("'<")-1).'l'.
+          \ '\%<'.(line("'>")+1).'l'
+  else
+    let g:srchstr = ''
+  endif
+endfunction
+vnoremap <silent> / :<C-U>call RangeSearch('/')<CR>:if strlen(g:srchstr) > 0\|exec '/'.g:srchstr\|endif<CR>
+vnoremap <silent> ? :<C-U>call RangeSearch('?')<CR>:if strlen(g:srchstr) > 0\|exec '?'.g:srchstr\|endif<CR>
+
diff --git a/functions/misc_functions.sh b/functions/misc_functions.sh
index 728c6e453b8a..5e36733f791b 100644
--- a/functions/misc_functions.sh
+++ b/functions/misc_functions.sh
@@ -46,6 +46,23 @@ function trim {
 }
 
 
+# Extends `codemod` to exclude dirs in .gitignore file
+function cm {
+  extensions="$1"
+  regex="$2"
+  replacement="$3"
+
+  ignore_dirs=""
+
+  if [ -f ./.gitignore ]; then
+    # Sanitizes .gitignore and converts it to a comma-separated list
+    ignore_dirs="$(sed 's/^\//.\//g' <./.gitignore | sed -e 's/#.*$//' -e '/^$/d' | tr '\n' ',' | sed 's/,$//')"
+  fi
+
+  codemod -m -d . --extensions ${extensions} --exclude-paths ${ignore_dirs} ${regex} ${replacement}
+}
+
+
 function tt() {
   sessionName="${1}"
   if ! tmux has-session -t "${sessionName}" 2> /dev/null; then