GithubHelp home page GithubHelp logo

rhysd / clever-f.vim Goto Github PK

View Code? Open in Web Editor NEW
998.0 14.0 43.0 1.81 MB

Extended f, F, t and T key mappings for Vim.

Home Page: https://rhysd.github.io/clever-f.vim

Vim Script 100.00%
vim vim-plugin cursor-moves

clever-f.vim's Introduction

clever-f.vim

Build Status Coverage Status

clever-f.vim extends f, F, t and T mappings for more convenience. Instead of ;, f is available to repeat after you type f{char} or F{char}. F after f{char} and F{char} is also available to undo a jump. t{char} and T{char} are ditto. This extension makes a repeat easier and makes you forget the existence of ;. You can use ; for other key mapping. In addition, this extension provides many convenient features like target character highlighting, smart case matching and so on.

If you want to reset the searching character without moving cursor, map <Plug>(clever-f-reset) to your favorite key.

Lastly, you can customize the behavior of the mappings and features.

USAGE

Screen shot

I'll show some examples of usage. _ is the place of cursor, -> is a move of cursor, alphabets above -> is input by keyboard. Note that this is a part of clever-f.vim's features.

f

input:       fh         f         f      e         fo         f
move :  _---------->_------>_---------->_->_---------------->_->_
input:                            F                            F
move :                        _<-----------------------------_<-_
text :  hoge        huga    hoo         hugu                ponyo

f screencast

F

input:        f        Fh       b     f                         Fo
move :  _<----------_<------_<-_<-----------------------------_<-_
input:        F        F          F
move :  _---------->_------>_----------->_
text :  hoge        huga    huyo         hugu                ponyo

F screencast

t

input:       th         t         t      e         to         t
move :  _--------->_------>_---------->_-->_--------------->_->_
input:                            T                            T
move :                         _<-----------------------------__
text :  hoge        huga    hoo         hugu                ponyo

t screencast

CUSTOMIZE

Search a character only in current line

g:clever_f_across_no_line controls to search a character across multi lines or not. Please set it to 1 in your vimrc to search a character only in current line.

Ignore case

g:clever_f_ignore_case controls whether or not searches are case-insensitive. If you want searches to be case-insensitive, set it to 1 in your vimrc.

Smart case

g:clever_f_smart_case controls whether searches are smart case or not. If you type a lower case character, the case will be ignored however if you type an upper case character it will only search for upper case characters. Please set it to 1 in your vimrc to enable searching by smart case.

Target character highlighting in current line

clever-f.vim highlights the target character you input in current line. The highlight is cleared automatically when the search ends. If you want to change the highlight group, set your favorite highlight group to g:clever_f_mark_char_color.

Below is an example using ta in description of clever-f.vim.

highlight example

Here, ta searches a forward then matches the character before a and Ta searches a backward then matches the character after a. You can see the highlighted target is dynamically changed following the cursor's direction.

Highlight can be cleared after timeout. See below section.

Highlighting characters which can be directly jumped to

clever-f.vim can highlight the characters in the line which can be directly jumped to. With this feature, you can easily understand where cursor can move by the f{char} input before inputting {char}.

For example, when 'aba' is in the current line, cursor can reach the first 'a' with fa but cannot reach the second 'a'. In this case, the first 'a' is highlighted but the second 'a' is not when typing f.

To enable this feature, set 1 to g:clever_f_mark_direct in your vimrc. Note that setting 1 after Vim starts does not work.

Repeat timeout

You can specify the timeout for repeating the previous target character on f, F, t and T mappings. If the interval of these mappings is greater than the one you specified, clever-f.vim resets its state to make you input a new character. This feature is disabled by default. If you want to use this feature, set timeout value in milliseconds to g:clever_f_timeout_ms.

Highlight timeout

When target character highlighting is enabled, the highlight can be cleared after specific timeout.

By default, this feature is not enabled. Highlight won't be cleared until the cursor moves. To enable this feature, set milliseconds value to g:clever_f_highlight_timeout_ms.

This feature requires timer feature added at Vim8. Confirm :echo has('timers') returns 1 to check if this feature is available.

Repeat last input

<CR> is easy to type but usually it isn't input as the target character of search. So by default, when you input <CR> as {char}, the previous input is used instead of <CR>. For example, when you previously input fa and then input f<CR>, a will be used as input instead of <CR>. You can specify characters to use previous input by setting g:clever_f_repeat_last_char_inputs. Adding <Tab> may be handy.

Migemo support

In Japanese environment, it is convenient that fa matches in some cases. Originally, this feature is provided by migemo. clever-f can search multibyte Japanese character with f, 'F', 't' and 'T' key mappings. A cmigemo package is NOT required because clever-f includes regex patterns generated by migemo. Set clever_f_use_migemo to 1 to get migemo support.

Fix a direction of search

If you always want to search forward with f and always want to search backward with F, set g:clever_f_fix_key_direction to 1.

input:        F        Fh     b     F                         Fo
move :  _<----------_<------_<-_<-----------------------------_<-_
input:        f        f          f
move :  _---------->_------>_----------->_
text :  hoge        huga    huyo         hugu                ponyo

Show prompt

If you want to show a prompt when you input a character for clever-f, set g:clever_f_show_prompt to 1. The prompt is disposed after a character is input.

Match all symbols with one char

Many symbol ({, (, ", and so on) keys are hard to press. If you want to match ; key to all symbols, you can use g:clever_f_chars_match_any_signs. If you set it to ';', f; matches all symbols.

input:   f;   f       f      f f       f       f
move :  _-->_--->_--------->_>_>_------------>_>_
text :  hoge.huga( autoloads: %w{ aaa bbb ccc } )

Keeping the functionality of ; and , via mappings

If you are used to using ; and , for forward and backward searching, but still want these to work the same way with clever-f, you can simply remap ;and , to use this plugin:

map ; <Plug>(clever-f-repeat-forward)
map , <Plug>(clever-f-repeat-back)

LICENSE

Distributed under MIT License. See doc/clever_f.txt

clever-f.vim's People

Contributors

bertrandsim avatar elyscape avatar enzime avatar hiroebe avatar huxpro avatar ichizok avatar jidhub avatar kadamski avatar matsui54 avatar pocke avatar r6eve avatar rbtnn avatar rhysd avatar tafryn avatar thinca avatar yuntan 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

clever-f.vim's Issues

visual mode t/T repeat

t/T doesn't work in visual mode
reason: s:first_move is never reset to 0 when in visual mode
see autoload/clever_f.vim line 181

should be easy to fix :)

Clear highlights after timeout

Just found this addon and I really like it!

One thing that struck me though is that if you set a timeout the highlights remain even after it's triggered. I think it would make sense to clear them once you no longer have the option to jump to them without starting a new search.

'fFtT' keys can not be input on select mode

map f されているので fFtT のキーがセレクトモードで入力できません。
セレクトモードでは印字可能文字を入力すると、選択範囲が入力文字で置換されることが期待されているのでこの挙動は neosnippet などセレクトモードを利用するプラグインで問題を起こします。 See :h Select-mode-mapping

再現手順

  1. 適当に文章を打つ
  2. v<C-g> でセレクトモードになる
  3. fFtT が入力できない

unmap T

How to unmap T key in init.vim

E523 in nvim_buf_set_lines

Have been using clever-f for a really long time. Recently, I encounter an error that is shown below

image

I am using fidget.nvim to show the progress of LSP. I am not sure whether this issue is caused by clever-f or fidget.nvim. It seems that this issue is related to neovim/neovim#16278, i.e., the <expr> + getchar() thing.

This issue happens during the initialization of the LSP servers. After the initialization, no issues.

Nvim version: NVIM v0.7.0-dev+1429-g8bdcd832a

Thank you very much.

mapping `clever-f-reset` doesn't work

or I'm too dumb to get it right ... ^^

I tried as normal with:

nm <Leader>f          <Plug>(clever-f-reset)

with , as leader. When I do this f doesn't work anymore. Ther cursor jumps to the status line when I press f and return to previous position when I press another key to search for that character. But it doesn't search any more :(

Introduction in documentation is a little unclear

In doc/clever-f.txt, it says

|F| after |f|{char} and |F|{char} is also available to undo a jump.

This is a little unclear because doing something like fpFF starting at "start here"

first p second p start here third p

Will take you back to the first p rather than one of the other ones.

`<Plug>(clever-f-reset)` doesn't reset highlight

I have the following map in my config:
nmap <Esc> <Plug>(clever-f-reset)

Moving the cursor resets the highlights, but pressing <Esc> doesn't. However, it does reset the searching character.

add number of character

I has a good idea. When i type f{char},addition to highlighting character, also can show numbers around characters(the number of repetitions of that character). Then i can type {count}f to jump.

Breaks macros after second press of t or f

Say you have the following line a,, b,, and you wish to delete the extra , after each letter, to do this you record the following macro: qqf,fx which leaves you with the following line after recording: a, b,, then you would run the macro again with @q

Expected Behaviour

to get a line like this: a, b,

Actual Behaviour

a,b,,

steps to reproduce

  1. qq start macro
  2. f,fx (find a comma, then go to the next comma and press x to delete the character)
  3. q to stop the macro
  4. @q to run the macro

vim

neovim 0.5.0 nightly (bare config)

Thank you!

Not an issue - just wanted to say thank you! This plugin rocks.

Error: Argument of map() must be a List or Dictionary

After I press "fs" to jump to 's' character i got this error:

Error detected while processing function clever_f#find_with:
line   40:
E712: Argument of map() must be a List or Dictionary

Removing this setting making it works again:
let g:clever_f_repeat_last_char_inputs='<Tab>'

My vim version is:

NVIM v0.4.3
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNUP

enable highlights for next matching lines?

Because clever-f is capable of traversing lines, I think that it would be quite helpful if we could configure it to highlight further out so we know where we will be landing. Of course, highlighting all of the matching chars in the entire buffer is probably too extreme, but somebody might want to do that as well!

Mainly I just want to be able to at least see the next line having the match. So, if i fZ and there is a Z 5 lines further down in the buffer, i'd like that to get highlighted as well as the Z's on the current line. No need to highlight more than the next match away from the current line.

Breaks with period character

Given this line of Ruby (_ == cursor):

    expect(Lib::_Version.to_s).to be_a String

In normal mode, if I do f., it repeats my previous action (in this case, text substitution) instead of jumping to the . character.

Enhancement: combine clever-f with shot-f

I just stumbled acros deris/vim-shot-f plugin which is a really nice feature for the f,F,t,T keys. But sadly it does not work with clever-f which I like even more :)

Is there a chance to combine them or implement something similar in clever-f? I might be able to do the implementation if I get some pointers.

More persistent repeating

When after using clever-f, say 'fj' and typing something in insert mode it is not possible to repeat the same search again.
Without clever f I would do 'fjiTYPING;.' to jump again and repeat typing again. But in case of clever-f ';' doesn't work anymore and 'f' itself asks for a character.

Is it possible to fix ';' and '.' keys while they are needed sometimes?

Thanks.

Repeat like key pressed to repeat

If you jump to a character x, using fx, then both f and t will jump to the next occurrence of x, but t does the same (i.e. it just repeats the initial fx jump).

IMHO, f should do a further jump in a f-ish way, and t in a t-ish way, independently of whether the initial jump was fx or tx. For instance, fxt should jump to before the second occurrence of x. Of course, likewise for any permutation of f, F, t, T.

Navigate only certain characters?

Is it possible to add an option to make clever-f to navigate only certain characters? Like, the beginning and end of words or camelCased words, and the non-alpha characters?

Feature Request: Reset highlights when <Esc> key is pressed

I have this mapping to clear/reset the Vim's search results highlights (i.e. when using /):

nnoremap <Esc> :noh<CR>

So, I'm thinking if it's possible to use the <Esc> key also to reset the clever-f highlights instead of using the cursor keys?

Highlight won't be cleared until the cursor moves.

I think it's better UX than using g:clever_f_highlight_timeout_ms since sometimes you're not done yet, but the highlight will be auto-cleared. Clearing it on-demand offers more timing control. I think <Esc> is also a natural choice since it's kinda escaping the clever-f (find) mode.

BTW, thanks a lot for this useful/practical plugin! :)

Remap the "t" key to another one ?

Hello !
Thanks for this smart plugin. Would there be a simple way to replace "t" by "j" because I use a different keyboardmap ? (bépo which is the french Dvorak sort of. j is already remapped as t in my vimrc and t to j but the plugin overwrite this remapping that is done with nnoremap).
Thanks and have a good day !

Reset repeat on Escape

Is there a quick option to make clever-f forget about the character to search not only on movement, but also on Esc.
After all, 'f' is not so consistent when:

input    fa      x fa
move   ---->_----->_
text   1    abc   da

This is as expected (cursor stays still), but:

input    fa    d0 fa
move   ---->_
move   _<
text   1    abc   da

In this case cursor moves and clever-f won't find next match anymore.

Would be nice if there were an option not to rely on previous_pos, and just reset clever-f on Esc (or C-f?).

I have tried, but my VimL skills are poor.

Using f for next search

Hi, thanks for a great plugin. I have a question. Is there a way to exit f-repeating mode?
Now, to make another search instead of repeating, I'm pressing some random key.
Is it possible to make some mapping like map <esc> call f-repeating-mode-exit().
Thanks in advance

Cursor stuck as underscore after autocompletion

First of all, I discovered this plugin today and am really enjoying it so far so thanks!

After installing the plugin I was getting some weird cursor issues and managed to find this related issue, which fixed my problem, but I wanted to open an issue here to point to the solution to help others in the future if they run into the same problem.

I was using all default params for clever-f with Shougo/deoplete.nvim as my autocompleter (not sure if it matters)

Here's a short video that shows the problem. Before my cursor is a block, then goes into underline mode when i enter Insert mode. After I take the autocompletion my cursor is permanently stuck in underline mode (both when in Normal mode and Insert mode).

vokoscreen-2019-02-20_16-48-28

Just add the following to your vimrc
let g:clever_f_hide_cursor_on_cmdline = 0
neovim/neovim#6913
credit to @zhou13

f and t in macros

It doesn't look like f and t work in user recorded macros, example:

qqfaq

would record a macro that moves to the next 'a' in a line. If I do that, then move to another line and call it via:

@q

nothing happens. Is this something that could be added? Great plugin, thanks!

Disappear cursor icon's color.

Description

Disapper cursor color by executing clerver-f

https://vim-jp.slack.com/archives/C03C4RC9F/p1562727930036200

Reproduce process

  1. Hit f
  2. Hit key to jump char

Environment

  • OS : Windows 10
  • vim: kaoriya-gvim
  • version: 8.1.1461

Minimum setting

if &compatible
  set nocompatible               " Be iMproved
endif

if empty(glob('c:/nekowasabi/tools/vim/vim81/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
        \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

call plug#begin('c:/nekowasabi/tools/vim/vim81/plugged')
Plug 'rhysd/clever-f.vim'
nmap f <Plug>(clever-f-f)
xmap f <Plug>(clever-f-f)
omap f <Plug>(clever-f-f)
nmap F <Plug>(clever-f-F)
xmap F <Plug>(clever-f-F)
omap F <Plug>(clever-f-F)

Clever-f jumps to wrong characters

Clever-f jumps to wrong characters, If clever-f set like below.
let g:clever_f_ignore_case = 1
let g:clever_f_use_migemo = 1
let g:clever_f_across_no_line = 0

Then, typing "fs" jumps to not only "s" but also "o"
test

ct/cf combinations change cursor appearance

Looks like plugin resets some cursor attributes after ct/cf combinations, before the change my cursor was horizontal, but after ct command it became a block:
июля-22-2019 16-45-06
Tried to disable plugin in .vimrc and it helped, so I'm sure problem related to the plugin. If there's some hotfix, that I can paste in my .vimrc I would appreciate it.

Breaks macros

Say you have the following line 1a 2a 3a 4a 5a, and you wish to delete all of the a in this line, to do this you record the following macro: qqfax which leaves you with the following line after recording: 1 2a 3a 4a 5a. from there, to delete the rest of the a you would simply call the macro by doing 4@q.

Expected Behaviour

to get a line like this: 1 2 3 4 5

Actual Behaviour

1 2axfaxfaxfax 3a 4a 5a

steps to reproduce

  1. qq start macro
  2. fax (find next a and delete it with the x key)
  3. q
  4. 4@q

vim

neovim 0.5.0 nightly (bare config)

cursor position not right when `set selection=exclusive`

to reproduce:

  1. set selection=exclusive

  2. assume we have these text (| means cursor position)

     |abcdef
    
  3. v to enter visual mode

  4. press fc

    • with clever-f, the result would be (ab selected)

        ab|cdef
      
    • without clever-f, the right result should be (abc selected)

        abc|def
      

Mark character color, how get it working?

Thanks for sharing this awesome plugin! How does g:clever_f_mark_char_color work? I found no example by yet.

For example, when I do: g:clever_f_mark_char_color="Statement"

And in my colorscheme the Statement is defined as:

hi Statement guifg=#8a3824 guibg=NONE guisp=NONE gui=bold

But I see no another colors of the matching character when I press f{insert character} ?

How can I map `f` and `F` only?

issueではないのですが質問があり、投票させていただきました。

clever-fについてf F t T の4種類の文字にて検索を行うことができますよね。
これに対してf, F のみを動作させて t T を動作させないようにしたいと考えました。

clever-f.vim / plugin / clever-f.vimの

noremap (clever-f-t) clever_f#find_with('t')
noremap (clever-f-T) clever_f#find_with('T')

をコメントアウトさせることで出来るのかと思いましたが違いました。
どのようにいじればよろしいのでしょうか。
お忙しいとは思いますがよろしくお願いします。

Breaks lazyredraw

when using a macro with lazyredraw on, the screen should not redraw, but when using f, F, t and T, the screen will always redraw.

I tested this with a bare neovim config

Enhancement: Modifiable clever_f_chars_match_any_signs list

I most cases when i hit "f;" (search and go to any sign) i get too many variants. As a result - i've tried it a couple of times and just do not use since.

Could you please add an option like "clever_f_chars_any_signs list" with possibility to limit the list?
".", ",", "_", " ' " are easy to jump by their original name (e.g. "f.")

clever-f conflicts with ale

I'm getting this error occasionally when using clever-f. It seems to be related to https://github.com/w0rp/ale but I'm not really sure what the error is trying to tell me nor whether the issue is with clever-f or ale.

Error detected while processing function clever_f#find_with[31]..<SNR>223_getchar[2]..<SNR>151_NeoVimCallback[29]..<SNR>112_HandleExit[43]..ale#engine#HandleLoclist[33]..ale#engine#SetResults[26]..ale#cursor#EchoCursorWarning[1]..ale#CallWithCooldown[9]..<SNR>118_EchoImpl[20]..ale#cursor#TruncatedEcho:
line   15:
E523: Not allowed here

Any help would be greatly appreciated 🙏

Guicursor is overwritten with neovim

I have the following to change my cursor from a block into an underline:

set guicursor=a:hor20-Cursor

Whenever I run df to delete a range, my cursor is changed back to a block.

I have to source my config to have it as an underscore again.

This behaviour seems to happen only with Neovim and not Vim itself.

Making semicolon behaving like f/t?

Many vimers might have got used to type ; for repeating after forward or toward. So It might be reasonable to map ; with same behaviour as well?

Any thoughts?

clever-f triggered by any use of f or t in normal mode

I have a map in one of my user-written plugin files, <Leader>fs, that manually applies a syntax highlight fix. I have let mapleader="," in my maps configuration, so the actual map is ,fs. This map keeps triggering clever-f on me, and invokes a forward-find of the character s. On immediate reuse of the map, it'll break the map and invoke a substitution action on the character under the cursor.

Additionally, if I type :help clever-f<CR>, I do indeed get the help docs for clever-f, but with all of the carriage returns highlighted. It seems as if clever-f is being triggered by any use of f/t/F/T while in normal mode, regardless of its context.

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.