Skip to content

Instantly share code, notes, and snippets.

@jssteinberg
Last active June 1, 2023 11:38
Show Gist options
  • Save jssteinberg/56a53783dbb39ffc6a410fe548564aa9 to your computer and use it in GitHub Desktop.
Save jssteinberg/56a53783dbb39ffc6a410fe548564aa9 to your computer and use it in GitHub Desktop.
space_search -- search mapped to `s`, then enter with `space`
" 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
@jssteinberg
Copy link
Author

jssteinberg commented Nov 25, 2022

The problem with just using search out-of-the-box as a motion is the time and akward movement for pressing / and enter. 2 char motion-plugins tries to fix this with 2 char as argument, then cursor moves. This native solution just adds a space-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).

@jssteinberg
Copy link
Author

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