Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active December 17, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRadev/5672666 to your computer and use it in GitHub Desktop.
Save AndrewRadev/5672666 to your computer and use it in GitHub Desktop.
" Plugins:
"
" Markmultiple:
" https://github.com/adinapoli/vim-markmultiple
"
" ChangeGlobally:
" http://www.vim.org/scripts/script.php?script_id=4321
"
" vim-multiedit (abandoned):
" https://github.com/felixr/vim-multiedit
"
" Multichange:
" https://github.com/AndrewRadev/multichange.vim
"
" Foldutils:
" http://www.vim.org/scripts/script.php?script_id=158
"
" writable_search (should be more complete after the upcoming weekend):
" https://github.com/AndrewRadev/writable_search.vim
" Tricks:
"
" Pre-filled :substitute
nnoremap & :'{,'}s/<c-r><c-w>//gc<left><left><left>
" * and # without moving the cursor
nnoremap <Leader>* m`*``
nnoremap <Leader># m`#``
" My own attempt at a cleverer version of the above:
" https://gist.github.com/AndrewRadev/4239736
nnoremap g* :call <SID>SmartStar()<cr>
function! s:SmartStar()
let cword = expand('<cword>')
if cword == ''
echo "No word under the cursor"
return
endif
let current_col = col('.')
call search('\<'.cword.'\>', 'bWc', line('.'))
let cword_start_col = col('.')
let cword_start = strpart(cword, 0, current_col - cword_start_col)
let cword_end = strpart(cword, current_col - cword_start_col)
let search_pattern = '\<\%('.cword_start.'\zs'.cword_end.'\)\>'
call histadd('search', search_pattern)
let @/ = search_pattern
normal! n
echo 'Search for: '.cword
endfunction
" Return the cursor where it was when executing a .
nnoremap . .`[
" Same as above, but works with repeat.vim
runtime autoload/repeat.vim
nnoremap . mr:call repeat#run(v:count)<bar>call feedkeys('`r', 'n')<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment