GithubHelp home page GithubHelp logo

foxerfly / quick-scope Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unblevable/quick-scope

0.0 1.0 0.0 358 KB

Lightning fast left-right movement in Vim

License: MIT License

Vim Script 100.00%

quick-scope's Introduction

quick-scope

A Vim plugin that highlights which characters to target for f, F and family. No mappings are needed.

screencast3

Check out character motions to learn about what these keys do and their advantages. See other motions for alternative ways of moving across a line and their use-cases.

TLDR: This plugin should help you get to any word on a line in two or three keystrokes with mainly f<char> (which moves your cursor to <char>).

Overview

When moving across a line, the f, F, t and T motions combined with ; and , should be your go-to options for many reasons. Quick-scope fixes their only drawback: it is difficult to consistently choose the right characters to target.

Features

  • Quick-scope highlights the first occurrences of characters to the left and right of your cursor (green in the screencast), once per word, everytime your cursor moves.

    screencast0

  • If a word does not contain a first occurrence of a character but contains a second occurrence of a character, that character is highlighted in another color (blue in the screencast).

    screencast1

  • Quick-scope takes extra measures to avoid bombarding you with superfluous colors:

    • It ignores special characters since they are easy to eye and tend to only appear once or twice on a line.

      screencast2

    • By default, it samples colors from your active color scheme for its highlighting.

      screencast3

Benefits

  • Highlighting is done automatically.
    • You already know what character to target before pressing any keys.
    • No more guesswork or slowing down to reason about the character motions.
  • This plugin neither introduces new motions nor overrides built-in ones.
    • You don't have to learn any new commands or mappings.
    • This helps you to become a better user of vanilla Vim.

Installation

Use your favorite plugin manager.

" Your .vimrc

Plug 'unblevable/quick-scope'       " Plug
NeoBundle 'unblevable/quick-scope'  " xor NeoBundle
Plugin 'unblevable/quick-scope'     " xor Vundle
$ git clone https://github.com/unblevable/quick-scope ~/.vim/bundle/quick-scope # xor Pathogen

Options

Highlight on key press

" Your .vimrc

" Trigger a highlight in the appropriate direction when pressing these keys:
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']

" Trigger a highlight only when pressing f and F.
let g:qs_highlight_on_keys = ['f', 'F']

Customize colors

" Your .vimrc

let g:qs_first_occurrence_highlight_color = '#afff5f' " gui vim
let g:qs_first_occurrence_highlight_color = 155       " terminal vim

let g:qs_second_occurrence_highlight_color = '#5fffff'  " gui vim
let g:qs_second_occurrence_highlight_color = 81         " terminal vim

Toggle highlighting

Turn the highlighting on and off with a user command:

:QuickScopeToggle

Or create a custom mapping for the toggle.

" Your .vimrc

" Map the leader key + q to toggle quick-scope's highlighting in normal/visual mode.
" Note that you must use nmap/vmap instead of their non-recursive versions (nnoremap/vnoremap).
nmap <leader>q <plug>(QuickScopeToggle)
vmap <leader>q <plug>(QuickScopeToggle)

Moving Across a Line

This section provides a detailed look at the most common and useful options for moving your cursor across a line in Vim. When you are aware of the existing tools available to you and their tradeoffs, you can better understand the benefits of this plugin.

Character motions

I unofficially refer to f, F, t, T, ; and , as the character motions. They form your swiss army knife for moving across a line:

Advantages

  • The motions are easy to reason about. Simply choose a character and then move your cursor to it. (And with quick-scope, the best characters to choose are always identified for you.)
  • They are versatile. You can usually move your cursor to any word on a line in a single motion.
  • Yet they are also precise. You specify an exact location to move your cursor.
  • The key combinations are quick to execute and efficient in terms of number of key presses. It should only take 2 or 3 key presses to move your cursor to where you want it to be.
  • The f key in particular sits comfortably on home row of the keyboard.
  • Vim includes a set of two dedicated keys, ; and ,, just to make it easier to repeat the character motions and offset bad character targets.

Reference

You can also consult Vim's excellent help docs for information about any command using :h <command>.

f<char> moves your cursor to the first occurrence of <char> to the right.

fg
It's just like the story of the grasshopper and the octopus.
^ > > > > > > > > > > > > > > > ^

F<char> moves your cursor to the first occurrence of <char> to the left.

Fl
All year long, the grasshopper kept burying acorns for winter,
         ^ < < < < < < < < < < ^

t and T can be just as useful. Notice how tf is the most optimal way to reach the word off in the example below.

t<char> moves your cursor right before the first occurrence of <char> to the right.

tf
while the octopus mooched off his girlfriend and watched TV.
      ^ > > > > > > > > > ^
T<char> moves your cursor right before the first occurrence of <char> to the left.

Ts
But then the winter came, and the grasshopper died, and the octopus ate all his acorns.
                                       ^ < < < < ^

The character motions can take a preceding count, but in practice, Vim users tend to use the ; and , to repeat a character motion any number of times.

; repeats the last character motion in the original direction.

fa;;
And also he got a racecar.
^ > ^
And also he got a racecar.
    ^ > > > > > ^
, repeats the last character motion in the opposite direction.

fs,
Is any of this getting through to you?
   ^ > > > > ^
Is any of this getting through to you?
 ^ < < < < < ^

Other motions

  • Note that many of Vim's motions can take a preceding count, e.g. 2w moves your cursor two words to the right. However, in most cases I would advise you not to use a count:

    • The number keys tend to be awkward to reach.
    • It is silly to waste time counting things before using a motion.
    • There are probably more effective ways to get to where you want in one or two keystrokes anyway (usually with f and co. or simply by repeating the motion).
  • b, B, w, W, ge, gE, e, E

    The word motions. They are usually the optimal choices for moving your cursor a distance of one or two words. (See :h word for Vim's definition of a word.) Take advantage of the fact that some of these keys ignore special characters or target the beginning or end of words.

  • 0, ^, $

    These keys let you skip to the beginning or end of a line. They are especially useful for repositioning your cursor for another motion on long lines.

    You might want to map 0 to ^ because ^ tends to be the preferred functionality but 0 is easier to reach.

    " Your .vimrc
    
    " Move across wrapped lines like regular lines
    noremap 0 ^ " Go to the first non-blank character of a line
    noremap ^ 0 " Just in case you need to go to the very beginning of a line
  • h, l

    Try to avoid spamming these keys at all costs, but bear in mind that they are the most optimal ways to move your cursor one or two spaces.

  • ?, /

    The search keys. They are overkill for moving across a line.

    • Much of their behavior overlaps with that of the superior character motions.
    • / + pattern + Return amounts to a wildly inefficent number of keystrokes.
    • Searches pollute your buffer with lingering highlights.
  • (, )

    These keys let you move across sentences. (See :h sentence for Vim's definition of a sentence.) They can also be convenient when working with programming languages that occasionally have ! or ? at the end of words, e.g. Ruby and Elixir.

quick-scope's People

Contributors

unblevable avatar alexfreska avatar

Watchers

 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.