Home

Awesome

quick-scope

A Vim plugin that highlights which characters to target for <kbd>f</kbd>, <kbd>F</kbd> 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 <kbd>f<char></kbd> (which moves your cursor to <kbd><char></kbd>).

Overview

When moving across a line, the <kbd>f</kbd>, <kbd>F</kbd>, <kbd>t</kbd> and <kbd>T</kbd> motions combined with <kbd>;</kbd> and <kbd>,</kbd> 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

Benefits

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

if has("gui_running")  || has('termguicolors') || has('nvim') && $NVIM_TUI_ENABLE_TRUE_COLOR " gui vim or vim enable TrueColor
    let g:qs_first_occurrence_highlight_color = '#ffffff'
    let g:qs_first_occurrence_highlight_bgcolor = '#CD0000'
    let g:qs_second_occurrence_highlight_color = '#ffffff'
    let g:qs_second_occurrence_highlight_bgcolor = '#447e27'
else " terminal vim
    let g:qs_first_occurrence_highlight_color = 15
    let g:qs_first_occurrence_highlight_bgcolor = 28
    let g:qs_first_occurrence_highlight_color = 15
    let g:qs_second_occurrence_highlight_bgcolor = 205
endif

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)

Disable plugin on long lines

Turn off this plugin when the length of line is longer than g:qs_max_chars. (default: 1000)

let g:qs_max_chars=80

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 <kbd>f</kbd>, <kbd>F</kbd>, <kbd>t</kbd>, <kbd>T</kbd>, <kbd>;</kbd> and <kbd>,</kbd> as the character motions. They form your swiss army knife for moving across a line:

Advantages

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,
         ^ < < < < < < < < < < ^

<kbd>t</kbd> and <kbd>T</kbd> can be just as useful. Notice how <kbd>tf</kbd> 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 <kbd>;</kbd> and <kbd>,</kbd> 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