GithubHelp home page GithubHelp logo

brandonmathis / vim-seek Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goldfeld/vim-seek

0.0 1.0 0.0 114 KB

Seek makes navigating long lines effortless, acting like f but taking two characters.

Vim Script 100.00%

vim-seek's Introduction

Introduction

Seek is a vim plugin that aims to make inline navigation effortless. The motion seek, summoned with s by default, is similar to f, but instead of one it expects two characters. This greatly reduces the possible matches within the line and mostly allows you to get anywhere in a line with three keystrokes. Your cursor is left off at the first character typed, so if you seek to "th" your cursor will now be at "t". The forward seek motion is complemented by S, which seeks backwards.

Motivation

The idea was borne out of frustration with getting at arbitrary points in longer lines, especially ones where navigating by word--on top of needing precise counts--gets mangled by symbols. The motion f often misfires by taking you to an earlier spot than where you aimed. And a full / search is often too much for a simple seek, needing an extra <Enter> and leaving a highlight, and might take you away from the current line. Seek only works within the line.

What about substitute?

Vim maps the key s to substitute. That it is the perfect mnemonic to seek is a fortunate coincidence, but the choice was made because substitute (without a count) is an often inefficient command, being--ironically--easily substituted by others. Seek doesn't take a count, so whenever you supply a count to s it will map to the substitute command.

The single character substitution can be accomplished with either 1s or cl. And S, which is remapped to seek backwards, is completely substituted by cc.

However, if you don't want to give up substitute, you can scroll down to the Customization section.

I already use EasyMotion..

Seek solves a different problem, and both are powerful tools. I use EasyMotion myself and love it--it's great for navigating across lines and around the file. But within the line, seek has more speed, for a very important reason: with seek you already know the keys you need to type before you even type s. Using EasyMotion there's a split second delay for it to generate the targets and another for your brain to process them. With seek you just type three quick keystrokes; you already know what to type.

Advanced

Additional motions are provided as operator-pending only. That is, they only work when used after d, c or y, and not by themselves.

The motion x is to seek what t is to f. Standing for 'cut short [of the target]', it acts up to the first character typed, but doesn't include it. This is in contrast to s itself, which does include the first character typed--to keep it consistent with f behavior--but not the second character.

Jumping motions

My personal favorites, r (remote jump) and p (presential jump) act on the next word containing the characters typed. They're the equivalent of iw, but r snipes the target word from a distance, and p jumps to the target and stays there. So you can use yrth' to yank the next word containing "th" without leaving your position (in reality vim goes there and jumps back), and that's useful for pasting it to where you are. Or you can type code' to jump to the next word with "de", deleting it and leaving you in insert mode.

Whereas r and p use the inner word text object, the respective u and o are the equivalent outer word aw.

To enable the jumping mappings you need to add the following to your vimrc: let g:seek_enable_jumps = 1. They don't work in diff mode by default, because the mode uses dp and do for other purposes, but you can override this by also adding let g:seek_enable_jumps_in_diff = 1 to your vimrc.

As expected, all these advanced mappings are complemented by their capital letter versions, which operate backwards.

Customization

You can customize any of the keys that seek binds by adding lines such as the following to your vimrc.

Change s and S:

let g:SeekKey = '<Space>' let g:SeekBackKey = '<S-Space>' // note: doesn't work in terminal vim.

Change x and X:

let g:SeekCutShortKey = '-' let g:SeekBackCutShortKey = '+'

Change p and P:

let g:seekJumpPresentialInnerKey = '<Leader>p' let g:seekBackJumpPresentialInnerKey = '<Leader>P'

Change r and R:

let g:seekJumpRemoteInnerKey = '<Leader>r' let g:seekBackJumpRemoteInnerKey = '<Leader>R'

Change o and O:

let g:seekJumpPresentialAroundKey = '<Leader>o' let g:seekBackJumpPresentialAroundKey = '<Leader>O'

Change u and U

let g:seekJumpRemoteAroundKey = '<Leader>u' let g:seekBackJumpPresentialInnerKey = '<Leader>U'

Or you can use a shorthand version to redefine all seek keys:

let g:SeekKeys = '<Space> <S-Space> - + <Leader>p <Leader>P' <Leader>r <Leader>R <Leader>o <Leader>O <Leader>u <Leader>U

Though it must always follow the order, you can simply use the defaults for keys you don't want to change, and you can truncate the string to leave the remaining unchanged:

let g:SeekKeys = 's S - +' // will not change jump keys.

Planned next

  • Repeating the last seek with ; and , (same keys used for f and t).
  • (Optional) Respect user's ignorecase and smartcase settings, so that you can seek to a capital letter by typing the lowercase character.
  • Condensed jump mappings to allow you to use just one of r or p (or yet another key) for all jump motions, whereby you define which you want to be remote and which presential (e.g. c lends itself more to being presential, y to be remote, while d has good use of both).

vim-seek's People

Contributors

goldfeld avatar ujihisa avatar brandonmathis avatar laughinghan avatar phmarek avatar

Watchers

James Cloos avatar

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.