Giter VIP home page Giter VIP logo

vim-sneak's Introduction

sneak.vim 👟

Jump to any location specified by two characters.

Sneak is a powerful, reliable, yet minimal motion plugin for Vim. It works with multiple lines, operators (including repeat . and surround), motion-repeat (; and ,), keymaps, visual mode, multibyte text, and macros.

Try label-mode for a minimalist alternative to EasyMotion:

let g:sneak#label = 1

Usage

Sneak is invoked with s followed by exactly two characters:

s{char}{char}
  • Type sab to move the cursor immediately to the next instance of the text "ab".
    • Additional matches, if any, are highlighted until the cursor is moved.
  • Type ; to go to the next match (or s again, if s_next is enabled; see :help sneak).
  • Type 3; to skip to the third match from the current position.
  • Type ctrl-o or `` to go back to the starting point.
    • This is a built-in Vim motion; Sneak adds to Vim's jumplist only on s invocation—not repeats—so you can abandon a trail of ; or , by a single ctrl-o or ``.
  • Type s<Enter> at any time to repeat the last Sneak-search.
  • Type S to search backwards.

Sneak can be limited to a vertical scope by prefixing s with a count.

  • Type 5sxy to go immediately to the next instance of "xy" within 5 columns of the cursor.

Sneak is invoked with operators via z (because s is taken by surround.vim).

  • Type 3dzqt to delete up to the third instance of "qt".
    • Type . to repeat the 3dzqt operation.
    • Type 2. to repeat twice.
    • Type d; to delete up to the next match.
    • Type 4d; to delete up to the fourth next match.
  • Type yszxy] to surround in brackets up to xy.
    • Type . to repeat the surround operation.
  • Type gUz\} to upper-case the text from the cursor until the next instance of the literal text \}
    • Type . to repeat the gUz\} operation.

Install

Requires Vim 7.3+ or Nvim. Label-mode requires Vim 7.4.792+. With Nvim 0.5+ label-mode is driven by virtual text instead of the legacy "conceal" feature.

  • vim-plug
    • Plug 'justinmk/vim-sneak'
  • Pathogen
    • git clone git://github.com/justinmk/vim-sneak.git ~/.vim/bundle/vim-sneak
  • Manual installation:
    • Copy the files to your .vim directory.

To repeat Sneak operations (like dzab) with dot ., repeat.vim is required.

FAQ

Why not use /?

For the same reason that Vim has motions like f and t: common operations should use the fewest keystrokes.

  • /ab<cr> requires 33% more keystrokes than sab
  • Sets only the initial position in the Vim jumplist—so you can explore a trail of matches via ;, then return to the start with a single ctrl-o or ``
  • Doesn't clutter your search history
  • Input is always literal (don't need to escape special characters)
    • Ignores accents ("equivalence class") when matching (#183)
  • Smarter, subtler highlighting

Why not use f?

  • 50x more precise than f or t
  • Moves vertically
  • Highlights matches in the direction of your search

How dare you remap s?

You can specify any mapping for Sneak (see :help sneak). By the way: cl is equivalent to s, and cc is equivalent to S.

How can I replace f with Sneak?

map f <Plug>Sneak_s
map F <Plug>Sneak_S

How can I replace f and/or t with one-character Sneak?

Sneak has <Plug> mappings for f and t 1-character-sneak. These mappings do not invoke label-mode, even if you have it enabled.

map f <Plug>Sneak_f
map F <Plug>Sneak_F
map t <Plug>Sneak_t
map T <Plug>Sneak_T

Related

License

Copyright © Justin M. Keyes. Distributed under the MIT license.

vim-sneak's People

Contributors

bitdeli-chef avatar blueyed avatar bohrshaw avatar cuviper avatar dahlbaek avatar dbmrq avatar dmitrivereshchagin avatar fdelacruz avatar ggandor avatar harmth avatar haya14busa avatar justinmk avatar khalian avatar lacygoill avatar lag13 avatar lfdm avatar r0mai avatar romgrk avatar roxma avatar sch0125 avatar shougo avatar tomtomjhj avatar wilywampa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-sneak's Issues

Restore cursor position after cancelling streak-mode

If you enter streak mode, press Tab, then exit without making a selection, the cursor stays at the position you tabbed to.

It would be more intuitive if the cursor jumped back to the original position before entering streak mode.

sc<CR> should jump to the `c` at the end of a line, etc.

moved from here: #40 (comment)


let sc<CR> jump to the c at the end of a line. Similarly, s<CR>c can also jump to c at the beginning of a line, while s<CR> to repeat the previous jump can be replaced by s<BS>.
In the meanwhile, I see that <CR> is a non-printable character, so I have doubts if this is possible.

Custom Highlighting

I can't change the highlighting of matches as described in the docs. Placing any of the lines:
hi SneakPluginTarget ctermbg=none ctermfg=green
hi SneakPluginScope ctermbg=none ctermfg=blue
hi link SneakPluginTarget Comment
hi link SneakPluginScope Comment

In either my vimrc or my colorscheme file has no effect.

provide option to ignore concealed characters

A search may fail even though the visible text appears to be a match, because the actual text contains a concealed character that prevents the match. Maybe Sneak can provide an option to match only visible/non-concealed text.

vim-sneak becomes disabled after sneaking and then doing a visual select till

I am very much enjoying the plugin, but I have found that it stops working frequently. This evening I have been able to reproduce actions that seem to disable the sneak plugin.

Steps To Reproduce:

  • Sneak to a specific location in a line
  • Do a visual select until a character vtl for example to select until the letter l.
  • Vim-sneak no longer works

Let me know if I can provide any additional information.

Conflicts with 'maxbrunsfeld/vim-yankstack'

I have vim-yankstack

Bundle 'maxbrunsfeld/vim-yankstack'
set winaltkeys=no
call yankstack#setup()
Bundle 'justinmk/vim-sneak'
nnoremap f :Sneak!         1<cr>
nnoremap F :SneakBackward! 1<cr>
xnoremap f <esc>:<c-u>SneakV!         1<cr>
xnoremap F <esc>:<c-u>SneakVBackward! 1<cr>

However, even ensuring that Sneak is kept after vim-yankstack, the s binding is taken over by vim-yankstack.

I know this might be more of a vim-yankstack issue but if you have any suggestions (probably initialize default mappings explicitly?)

streak-mode multibyte highlighting

sneak basic mode works fine with all multibyte situations so far.

however, streak-mode has the same issue that easymotion has or had: easymotion/vim-easymotion#28

Target labels are offset or missing completely. To test, try a streak-mode search for ïo (on a Mac, option-o + o) in the following text:

foo æfïooæ ïoòôõïo ïofoo fooïo ïoïo

Another test case (#47):

абв

Another thing to keep in mind with sneak basic mode:

  • use strwidth() instead of len() (vim-7.3 only)

see also: easymotion/vim-easymotion#60

toggle for sneak as case sensitive or smart case

Using sneak all morning (again, I can't say enough about how superb it is, it really improves medium distance movement) I think it would improve if it used smart case.

Shift is a whole extra key! And in 95% of cases I get where I want in one jump!

"f" stops taking amount when plugin is enabled.

Steps to reproduce:
2f. on a line that had two dots after the cursor.

This seems to affect at least keys fFtT.

When I press one of the keys listed in the topic, the number is dropped and <number>f. becomes just f..

Breaks f;

abcde abcde abcde abcde
abcde abcde abcde abcde
abcde abcde abcde abcde
  • fe;;
  • sbc;;
  • fe;;
    • ; goes to bc instead of e

multi-line f with ; and , or \ support

You mentioned that this plugin should replace all the other f enhancement plugins, however, there is one feature I can't seem to get which vim-fangingtastic provides (the two plugins seem incompatible), and that is multi line f, with support for ; and , or \ and I guess possibly with highlighting as well.

I could map f to SneakForward, however I would rather just be able to enter a single character and it work over multi-lines for f, and stick with s for 2 characters.

Sorry if I've missed the explanation somewhere :).

Thanks

Tom

Make f iterate through search results if pressed immediatly after use

Wow. This is a fantastic plugin.

One feature I would really love is the way 'f' is used to repeat immediately after a motion, a la rhysd/clever-f.vim, especially because I've remapped ; to : in normal mode to make entering commands 50% easier.

Arguments for this:

  • the chance that I want to do a second character sneak immediately after completing one seem small
  • the f key is index finger, and much more agile for me than the pinky or ring finger
  • frees up ; (with a recommendation to remap :, making command mode more accessible)

Would this be possible? Maybe crib from clever-f?

sneak next with ; remapped

I have the following bindings in my .vimrc

let mapleader=","
nnoremap ; :
nnoremap : ;

When after using s{char}{char}, pressing : (nor ; ...of course) does not work move to the next instance. I've also tried binding : to SneakNext and VSneakNext, neither of which work. What am I doing incorrectly?

keymap option is ignored

sneak.vim doesn't respect the keymap option. Vanilla f and t do respect it. To reproduce:

  1. :set keymap=bulgarian-phonetic (or any other non-english keymap, I guess)
  2. enter абв (no english letters)
  3. fb goes to letter б (б is entered with key b) -- this is expected, just shows that f respects the keymap
  4. fbw says not found: bw -- at this point, I would expect the cursor to be placed on бв (бв is entered with keys bw)

I guess this has to do with the fact that s starts command mode, where the keymap is ignored by vim.

BTW Great plugin!

An option to use ; instead of <enter> for "1 character search"

It would be nice to have ";" instead of enter for terminating input while sneaking for 1 character.
It is easier to reach and is consistent with default meaning of ;
So, whenever you want to proceed to the next occurrence, you don't need move your hand.
The only drawback is losing possibility to sneak for 2 char search if the last char is ;

indentLine char is highlighted as match

I also use indentLine pluging, I am using this char:

        let g:indentLine_char = '¦'

so if I have a block that is showing that char, when I seach for something with s, the indentLine char is also highlitghted as if it was another match, for example here I did 'sol':
http://i.imgur.com/LJJTkS4.png

I guess this is not on purpose?

thanks

cannot repeat dZab (backwards operation)

dZab (backwards delete operation) must be invoked twice with the same search ("ab"), at the same cursor position, in order for . to repeat the operation. Seems like b:changedtick is not being updated the same way as it is with forward-operations like dzab. Very odd.

eliminate unnecessary <Plug>VFoo mappings

given the following

nnoremap <Plug>SneakForward ...
xnoremap <Plug>SneakForward ...

... xmap <Plug>SneakForward will map correctly to the second one. So there's no need for separate <Plug>VSneakForward. This simplifies the configuration experience.

Backwards streak-mode?

Maybe i am too stupid or maybe this is not implemented - if i activate streak mode and type sea to find my leaders in .vimrc - I can jump to them with the asdfjkl-movements (which is friggin great, btw). Typing Sea does not go into streak-mode, it just provides me the highlights and I can jump to them with ; and ,
What am I doing wrong?

A very great plugin nonetheless!

streak-mode: ctrl-c causes weird state

Not sure if anything can be done about this (maybe a sanity check). If user hits <C-c> during streak-mode, highlighting thereafter "masks" every match, even basic-mode matches.

Backwards sneaking persists past f/F/t/T

Sometimes, after sneaking backwards, then using f/F/t/T, directions on ;/, will not correspond to the latter.

For instance, consider the file:

quux quuux quuuux
| <- cursor here

Sneaking vertically with 30Sux will put you at the last ux on the line. Then, fx will move you to the x. However, ; will move you backwards from there, instead of forwards, repeating the fx. Also, 5Sux will move you to the first ux. Then Fq will move backwards to the beginning of the line. But ; will move you forward to subsequent qs. , behaves opposite of ; in these examples.

Regular backwards sneaking seems to have the same effects. Doing a forward sneak resets the situation, I think.

Strange mapping. s not mapped in normal mode

I have just those mappings on s'es.

x  s             <Plug>VSneakForward
        Last set from ~/Code/dotfiles/vim/bundle/vim-sneak/plugin/sneak.vim
n  sk            :SplitjoinJoin<CR>
        Last set from ~/.vimrc
n  sj            :SplitjoinSplit<CR>
        Last set from ~/.vimrc  
x  S             <Plug>VSurround
        Last set from ~/Code/dotfiles/vim/bundle/surround.vim/plugin/surround.vim
n  S             <Plug>SneakBackward
        Last set from ~/Code/dotfiles/vim/bundle/vim-sneak/plugin/sneak.vim

E216: No such event

I have just installed spf13 and I receive the following error upon initializing vim:

Error detected while processing /home/flyer/.spf13-vim-3/.vim/bundle/vim-sneak/plugin/sneak.vim:
line  338:
E216: No such event: netrw autocmd SneakPluginNetrw CursorMoved <buffer> call <sid>map_netrw_key('s') | call <sid>map_netrw_key('S') | autocmd! SneakPluginNetrw * <buffer>
Press ENTER or type command to continue

I am running on Fedora 19,

vim-X11.x86_64                         2:7.4.027-2.fc19                @updates 
vim-common.x86_64                      2:7.4.027-2.fc19                @updates 
vim-enhanced.x86_64                    2:7.4.027-2.fc19                @updates 
vim-filesystem.x86_64                  2:7.4.027-2.fc19                @updates 
vim-minimal.x86_64                     2:7.4.027-2.fc19                @updates

However, on my 32-bit laptop with the same OS, everything works fine.

Error when mapleader is not set

After I removed set mapleader from my vimrc, vim-sneak complains about mapleader being undefined:

 ~ LANG=C vim
Error detected while processing /home/rav/.vim/bundle/vim-sneak/plugin/sneak.vim:
line  277:
E121: Undefined variable: mapleader
E15: Invalid expression: mapleader ==# ','
line  288:
E121: Undefined variable: mapleader
E15: Invalid expression: mapleader ==# ','
Press ENTER or type command to continue

'cz{char}{char}' consumes char to left of cursor

Great plugin!

Little quirk, when doing change to sneak target, the character to the left of cursor is consumed. Often a space, but doesn't seem to matter. Doesn't happen on dz{char}{char}:

" start, cursor between pipes --------
abc|d|ef ghijkl

" after 'czgh' ----------------
ab|ghijkl

netrw mapping

optional netrw mapping (instead of netrw's "sort")

support for "1 character search"

Hi justin,
thx for your great plugin!

Is it possible to also search for just 1 character? For example when I type fs and <Enter> it jumps to s

Best regards

Sneak forward and back at the same time

This discussion at /r/vim about easy-motion got me thinking that the decision of the direction to move could be better made after seeing the matches.

The OP used, call EasyMotion#F(0, 0) to do a direct search. Would this be possible to do with vim-sneak.

Something like a, SneakAny which searches with both SneakForward and SneakBackward. The matches highlight, and SneakNext and SneakProvious work as currently.

Make the streak-mode coexist with the default mode

Instead of overriding the default mode with let g:sneak#streak = 1, I prefer to be able to use the streak-mode along with the normal mode. I would like to use mappings starting with <leader>s in the streak-mode.

Access to vim-sneak's modes with autocmds, SneakEnter, SneakLeave

I have mapped vim-sneak to f instead of the default s as I've grown to accustomed to the s and particularly S.

Unfortunately my <leader> and <localleader> are comma and semicolon. (Dvorak layout), so I can't use the comma and semicolon to navigate between the matches. And if I map n and N to vim-sneak I lose the /search navigation!

Looking for an alternate approach, I noticed that you have a way to come out of sneak-mode when you turn off highlighting. If you could add a couple of user autocmds like SneakEnter and SneakLeave, it would be possible to remap the navigation keys on demand, and restore to their defaults for /search.

This isn't a bug per-se, rather an enhancement. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.