sponsor Vim development Vim logo Vim Book Ad

JumpToLastOccurrence : f{char} motions that count from the end of the line.

 script karma  Rating 7/4, Downloaded by 481    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
The f{char}, F, t and T family of motions are often more effective
than the more general l, w and W motions. However, there are situations
where they are difficult to apply.
Take a long file system path like /var/opt/foo/a/very/long/path/to/filename.
Imagine you are on the beginning / and want to change the entire directory
path, but keep the filename. You'd either have to count occurrences (e.g. c8f/
or c2tf), do multiple moves ($T/cB), use visual mode (veeeeeeeelc), or a
search (c/filen<CR>).

This plugin extends the built-in f/F/t/T motions with counterparts that move
to the last occurrence of {char} in the line. For the above example, that
would be a short c,f/ to jump to the last slash in the line.

SEE ALSO
- The JumpToVerticalOccurrence.vim plugin (vimscript #4841) implements
  variations of f / F that move vertically across lines, restricted to the
  same screen column as the cursor.

USAGE
,f{char}                To [count]'th occurrence of {char}, counting from the
                        end of the line. The cursor is placed on {char}
                        inclusive.
,F{char}                To the [count]'th occurrence of {char}, counting from
                        the beginning of the line. The cursor is placed on
                        {char} exclusive.
,t{char}                Till before [count]'th occurrence of {char}, counting
                        from the end of the line. The cursor is placed on the
                        character left of {char} inclusive.
,T{char}                Till after [count]'th occurrence of {char}, counting
                        from the beginning of the line. The cursor is placed
                        on the character right of {char} exclusive.

                        All motions can be repeated with ; and ,. However,
                        the ,t and ,T motions will jump to, not until, the
                        next {char}.
 
install details
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim JumpToLastOccurrence*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.016 or
  higher.
- repeat.vim (vimscript #2136) plugin, version 1.1 or higher (optional)

CONFIGURATION
For a permanent configuration, put the following commands into your vimrc:

By default, all mappings start with , (comma) as the map leader instead of
using <Leader>. I personally find the default <Leader> key too far off the
keyboard to be useful for custom motions (which also cannot be repeated via
the . (dot) command, so they should be very fast to type repeatedly), but
quite suitable for general, less frequently used custom mappings.
To avoid losing the (rarely used) , mapping (which repeats latest f, t, F or
T in opposite direction), you can remap it to ,,:
    nnoremap ,, ,
    xnoremap ,, ,
    onoremap ,, ,

If you don't agree with this and want all motions to start with <Leader> (or
any other key), you can do this (before sourcing the script):
    let g:JumpToLastOccurrence_Leader = '<Leader>'

If you want to use completely different or only a few of the mappings, map
your keys to the <Plug>JumpToLastOccurrence_? mapping targets _before_
sourcing the script (e.g. in your vimrc).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
JumpToLastOccurrence-1.20.vmb.gz 1.20 2014-04-03 7.0 Ingo Karkat - ENH: Implement repeat of operator-pending mapping without re-querying the {char}. This requires the repeat.vim plugin, version 1.1 or higher.
- Add dependency to ingo-library (vimscript #4433). *** You need to separately install ingo-library (vimscript #4433) version 1.016 (or higher)! ***
JumpToLastOccurrence-1.11.vmb.gz 1.11 2012-09-15 7.0 Ingo Karkat Also handle move to the buffer's very last character in operator-pending mode.
JumpToLastOccurrence.vba.gz 1.10 2010-12-30 7.0 Ingo Karkat - Moved functions from plugin to separate autoload script.
- Made mappings configurable, both via the customary <Plug> mappings and alternatively in bulk through the g:JumpToLastOccurrence_Leader setting.
JumpToLastOccurrence.vba.gz 1.00 2010-12-29 7.0 Ingo Karkat Initial upload
ip used for rating: 54.91.125.72

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo