Skip to content

Instantly share code, notes, and snippets.

@Houl
Created May 6, 2019 18:48
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 Houl/7b3f46c42fbb8fbe3d1d6bd54204ab51 to your computer and use it in GitHub Desktop.
Save Houl/7b3f46c42fbb8fbe3d1d6bd54204ab51 to your computer and use it in GitHub Desktop.
Star-search with 'iskeyword' temporarily set to additional characters.
" File: mtc147.vim
" Created: 2019 May 06
" Last Change: 2019 May 06
" Version: 0.1
" Author: Andy Wokula <anwoku@yahoo.de>
" License: Vim License, see :h license
" Description:
" Star-search with 'iskeyword' temporarily set to additional characters.
" Usage: (several variants)
"
" :map <F4>8 <Plug>(roux-search-*)
" :map <F4>3 <Plug>(roux-search-#)
" " (mnemonic) where `8' is `*' without Shift, `3' is `#' without Shift
"
" or
" :map <expr> <F4>8 PlugRouxSearch('*')
" :map <expr> <F4>3 PlugRouxSearch('#')
"
" or when using the autoload script:
" :map <expr> <F4>8 roux#search#Plug('*')
" :map <expr> <F4>3 roux#search#Plug('#')
"
" possibly with <buffer>, from ftplugin script
"
" Config:
" b:roux_isk_cmd
" TODO
" - move to autoload: PlugRouxSearch() => autoload/roux/search.vim,
" roux#search#Plug()
" - RouxSearch() => <sid>Search()
func! PlugRouxSearch(what) "{{{
return printf("\<Plug>(roux-search-%s)", a:what)
endfunc "}}}
noremap <silent> <Plug>(roux-search-*) <C-\><C-N>:call RouxSearch('pre',0)<CR>*:let @/=RouxSearch('post',0,@/)<CR>
vnoremap <silent> <Plug>(roux-search-*) :<C-U>call RouxSearch('pre',1)<CR>*:<C-U>let @/=RouxSearch('post',1,@/)<CR>
noremap <silent> <Plug>(roux-search-#) <C-\><C-N>:call RouxSearch('pre',0)<CR>#:let @/=RouxSearch('post',0,@/)<CR>
vnoremap <silent> <Plug>(roux-search-#) :<C-U>call RouxSearch('pre',1)<CR>#:<C-U>let @/=RouxSearch('post',1,@/)<CR>
func! RouxSearch(when, vmode, ...) "{{{
if a:vmode
normal! gv
endif
if a:when ==# 'pre'
if !exists('b:roux_isk_cmd')
let b:roux_isk_cmd = 'setlocal isk+=# isk+=-'
endif
if !exists('b:_roux_sav_isk')
let b:_roux_sav_isk = &isk
endif
exec b:roux_isk_cmd
elseif a:when ==# 'post'
if exists('b:_roux_sav_isk')
let &l:isk = b:_roux_sav_isk
unlet b:_roux_sav_isk
endif
if a:0 >= 1
return substitute(a:1, '^\\<\k\@!\|\k\@<!\\>$', '', 'g')
else
return ''
endif
endif
endfunc "}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment