Last active
June 1, 2023 11:38
-
-
Save jssteinberg/56a53783dbb39ffc6a410fe548564aa9 to your computer and use it in GitHub Desktop.
space_search -- search mapped to `s`, then enter with `space`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" search with s in normal and visual mode | |
nnoremap s <cmd>let g:space_search=1<cr>/ | |
xnoremap s <cmd>let g:space_search=1<cr>/ | |
" backwards search with S in normal mode | |
nnoremap S <cmd>let g:space_search=1<cr>? | |
" in command mode, if space_search then <space> is <cr> | |
cnoremap <expr> <space> exists("g:space_search") | |
\ ? "<cr>" : " " | |
" autocmd to unlet variable so space_search is deactivated | |
augroup space_search | au! | |
au CmdlineLeave * if exists("g:space_search") | unlet g:space_search | en | |
augroup END |
Further extended with buffer switcher here: https://gist.github.com/jssteinberg/49a41c52cbfa34918a7eaf8293595b42
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem with just using search out-of-the-box as a motion is the time and akward movement for pressing
/
andenter
. 2 char motion-plugins tries to fix this with 2 char as argument, then cursor moves. This native solution just adds aspace
-press in between, which is almost as fast once you get it into your fingers, and is a very lightweight solution. And you also get the advantages of it being a native search (and also the disatvantages if you see it that way).