Giter Site home page Giter Site logo

vim-asterisk's Introduction

vim-asterisk: * -Improved

Introduction

asterisk.vim provides improved * motions.

1. stay star motions (z prefixed mappings)

z star motions doesn't move your cursor.

2. visual star motions

Search selected text.

3. Use smartcase unlike default one

Default behavior, which sees ignorecase and not smartcase, is not intuitive.

4. Keep cursor position across matches

It is handy for refactoring to keep cursor position while iterating over matches.

Add following line in your vimrc to enable this feature. let g:asterisk#keeppos = 1 Default: 0

Installation

Neobundle / Vundle / vim-plug

NeoBundle 'haya14busa/vim-asterisk'
Plugin 'haya14busa/vim-asterisk'
Plug 'haya14busa/vim-asterisk'

pathogen

git clone https://github.com/haya14busa/vim-asterisk ~/.vim/bundle/vim-asterisk

Usage

map *   <Plug>(asterisk-*)
map #   <Plug>(asterisk-#)
map g*  <Plug>(asterisk-g*)
map g#  <Plug>(asterisk-g#)
map z*  <Plug>(asterisk-z*)
map gz* <Plug>(asterisk-gz*)
map z#  <Plug>(asterisk-z#)
map gz# <Plug>(asterisk-gz#)

If you want to set "z" (stay) behavior as default

map *  <Plug>(asterisk-z*)
map #  <Plug>(asterisk-z#)
map g* <Plug>(asterisk-gz*)
map g# <Plug>(asterisk-gz#)

To enable keepCursor feature:

let g:asterisk#keeppos = 1

Special thanks

|vim-asterisk| uses the code from vim-visualstar for visual star feature.

Author

haya14busa (https://github.com/haya14busa)

vim-asterisk's People

Contributors

haya14busa avatar lumakernel avatar pelodelfuego avatar presuku avatar tamago324 avatar thinca 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

vim-asterisk's Issues

Keep cursor position while moving

Hello,

First of all thanks for your plugin, it is really usefull !

I would like to submit you an improvement idea:
Why not save cursor position it the current pattern and restore it when reaching next/prev match. Overwrite vim's default behaviour (first char) allow quick refactoring by combining it with ..

If you want i can fork and submit you an implementation ?

Discussion: A search operator

I just want to start a discussion about an idea I have:

I think vim should have a "search" operator, so that we can type <search-operator><motion> or <search-operator><text-object>.

Do you think it makes sense to add this to vim-asterisk?

One option would be to make * itself the operator, overriding its original behavior. I understand that typing * in visual mode can already behave as an operator using vim-asterisk. If we make it a true operator, we can also do the following (the third column):

operation             | visual mode method | operator-first method
----------------------| ------------       |----------------
search in word        | viw*               | *iw
search in parens      | vib*               | *ib
search to end of line | v$*                | *$
etc.

Another option would be to leave * (and g*) the way it works since it is a a convenient shortcut for "search in word", and allow the user to choose any key sequence as the search operator. I might choose <leader>/ or something.

haya14busa, what do you think?

Behaves inconsistently when `iskeyword` contains `?`

This may also apply to other punctuation characters, I'm not sure. To reproduce:

  • set iskeyword+=?
  • Perform <Plug>(asterisk-#) on a word containing ?
  • The ? will break the word

Curiously, <Plug>(asterisk-*) does not break the word at ?. I think # should behave this way, too.

Keep cursor pos in visual mode

How about keeping cursor position while visual selection?

You can only have 2 positions, begin or end of the selection depending on how you moved your cursor to select.

I can make a pull request if you want me to?

Incorrectly adding \< and \> when selection starts or ends with a multi-byte character.

If you visually select the question mark and press star in the following text:

texttext

It will search for \V\<\> and not find it.

I don't understand the logic in convert_2_word_pattern_4_visual.
Shouldn't the if conditions just be:

        if text =~# '^\k' && outer !~# '\k'

and

        if text =~# '\k$' && outer !~# '\k'

I would submit a pull request if I understood better.

Looks like this is where the behavior was changed originally:
thinca/vim-visualstar@34979b3

Support gd / gD

It'd be cool if there were also functions to override gd/gD to override smartcase.

Right now there is also some issue with using the keeppos feature and gd/gD. Specifically, if you

  1. position yourself like so 'vim-asterisk'
  2. hit *
  3. cancel that search
  4. go back to 'vim-asterisk', position yourself as 'vim-asterisk'
  5. hit gd

The gd search will use the regex used to position you at 'vim-asterisk'.

Question about case sensitivity

Hi, I have a question about casing of the words (I have put the map bindings from the README)

Let's say my cursor is on the word set; when I do z* or *, it would select both set and Set; however, when I'm on Set, it would only select Set.

What happens if I'm on a set and I want to only select lowercase set words? Can I do that?

Disable highlight when finish ?

Do you think it is possible (and a good idea) to disable (or add an option to) highlight when finish? For example a script limited scope keymap to delete highlight ?

cgn goes to next selection if selection=exclusive

In my vimrc, I have selection=exclusive. and whenever I want to replace a text, I would highlight it, press z*, press cgn, the n part goes to the next selection. You can replicate it if you add set selection=exclusive to your vimrc.

Sometimes crashes and closes buffer on first use

After using (and loving!) this plugin for a while, I've reluctantly had to disable my bindings to it. I was having a problem with buffers suddenly closing on me and finally realized it was triggered by * motions (in my case bound to <Plug>(asterisk-z*).

A little bit of poking showed in typically happened on the first run in a new tab or buffer, it would typically work if I opened up the buffer and tried again, and it typically worked thereafter until I switched buffers or opened something new. Then it was likely to crash again.

I don't know how to get useful debug information as the buffer just disappears and no messages are shown but I'd be happy to try something if there is a way to get any error being reported.

I'm using Neovim and vim-plug, and other than bindings my only setting is:

let g:asterisk#keeppos = 1

[FEATURE REQ] Select `WORD` under cursor

Currently, we can only select the current word under the cursor. But there are many times when it would be really convenient to select the WORD instead. What do you think?

keeppos needs resourcing

I am using vim-asterisk with vim-plug.
I use the setting g:asterisk#keeppos = 1 however it doesn't work until I manually source my config file.

'smartcase' should be optional

I actually find the default behavior of * or # to ignore 'smartcase' more useful in practice, which certainly varies from person to person. Could you provide an option to ignore 'smartcase'?

Issue when running it at the 1st time

I have installed haya14busa/incsearch.vim, haya14busa/vim-asterisk, osyo-manga/vim-anzu and thinca/vim-visualstar via neobundle. And here are the settings for these plugins:

" provide incremental highlighting for all pattern matches{{{2
NeoBundleLazy 'haya14busa/incsearch.vim', {
            \ 'name'     : 'incsearch',
            \ 'mappings' : ['<plug>(incsearch-'],
            \ }

" show details of the position of the search result{{{2
" NeoBundleLazy 'henrik/vim-indexed-search', {
"             \ 'name'     : 'indexed-search',
"             \ 'commands' : [
"             \               {'name': 'ShowSearchIndex'},
"             \              ],
"             \ }

" show the index of the matched searching results
NeoBundleLazy 'osyo-manga/vim-anzu', {
            \ 'name'     : 'vim-anzu',
            \ 'mappings' : ['<plug>(anzu-'],
            \ }

" improve star motions
NeoBundleLazy 'haya14busa/vim-asterisk', {
            \ 'name'     : 'asterisk',
            \ 'mappings' : ['<plug>(asterisk-'],
            \ }

" provide star feature in visual-mode{{{2
NeoBundleLazy 'thinca/vim-visualstar', {
            \ 'name'     : 'visual-star',
            \ 'mappings' : ['<plug>(visualstar-'],
            \ }

if neobundle#tap('incsearch')

  function! neobundle#tapped.hooks.on_post_source(bundle)
    IncSearchNoreMap <c-a> <home>
    IncSearchNoreMap <c-e> <end>
    IncSearchNoreMap <c-l> <right>
    IncSearchNoreMap <c-h> <left>
    IncSearchNoreMap <c-j> <down>
    IncSearchNoreMap <c-k> <up>
    IncSearchNoreMap <c-f> <bs>
    IncSearchNoreMap <tab>   <Over>(buffer-complete)
    IncSearchNoreMap <S-Tab> <Over>(buffer-complete-prev)
  endfunction

  " let g:incsearch#auto_nohlsearch = 1
  nmap /  <plug>(incsearch-forward)
  nmap ?  <plug>(incsearch-backward)
  nmap g/ <plug>(incsearch-stay)
  " nmap n  <plug>(incsearch-nohl-n)zv:ShowSearchIndex<cr>
  " nmap N  <plug>(incsearch-nohl-N)zv:ShowSearchIndex<cr>
  nmap n  <plug>(incsearch-nohl)<plug>(anzu-n-with-echo)
  nmap N  <plug>(incsearch-nohl)<plug>(anzu-n-with-echo)
  " nmap *  <plug>(incsearch-nohl-*)
  " nmap #  <plug>(incsearch-nohl-#)
  " nmap g* <plug>(incsearch-nohl-g*)
  " nmap g# <plug>(incsearch-nohl-g#)

  map *   <plug>(incsearch-nohl)<plug>(asterisk-*)
  map g*  <plug>(incsearch-nohl)<plug>(asterisk-g*)
  map #   <plug>(incsearch-nohl)<plug>(asterisk-#)
  map g#  <plug>(incsearch-nohl)<plug>(asterisk-g#)

  map z*  <plug>(incsearch-nohl0)<plug>(asterisk-z*)
  map gz* <plug>(incsearch-nohl0)<plug>(asterisk-gz*)
  map z#  <plug>(incsearch-nohl0)<plug>(asterisk-z#)
  map gz# <plug>(incsearch-nohl0)<plug>(asterisk-gz#)

  call neobundle#untap()
endif

" settings for visual-star{{{2
if neobundle#tap('visual-star')
    vmap * <plug>(visualstar-*)N
    vmap # <plug>(visualstar-#)N
    vmap g* <plug>(visualstar-g*)N
    vmap g# <plug>(visualstar-g#)N

  call neobundle#untap()
endif

Open a file via vim, move cursor to a word and press *. It doesn't search the word under the cursor. Clear the unexpected result, move cursor the a word and press * again. It just works fine. This issue only happens when we do the search for the 1st time.

Conflicts with google/vim-searchindex

This plugin conflicts with https://github.com/google/vim-searchindex. None of the functionality works when both plugins are enabled. I wonder if that is because their plugin re-implements vim's search function in order to get an accurate search count, which might be of conflict. It seems they had a previous conflict with another plugin, google/vim-searchindex#6, and it was fixed by disabling the search rework with 'let g:asterisk#keeppos = 1', although that doesn't work here. So maybe it's something else.

Some words appear when I use <Plug>(asterisk-

いつも便利に使用させていただいております。

vim-asteriskで検索開始した時に一瞬文字が表示されて表示がチラつくのがちょっと気になりました。
マッピング用公開インターフェースにを付加していただくことを検討していただけないでしょうか。

Show total number of matches and current match number

Thank you for the awesome plugin! It is amazing and I cannot use vim without it. The cursor stay in place feature is a game changer.

I was wondering if it would be possible to add a feature where the plugin shows the total number of matches and current match number? I've tried vim-indexedsearch and vim-anzu and they don't play along well with this plugin. This is what I have in my .vimrc.

" make searching with * use vim-asterisk
map *  <Plug>(asterisk-z*)
map #  <Plug>(asterisk-z#)
map g* <Plug>(asterisk-gz*)
map g# <Plug>(asterisk-gz#)

let g:asterisk#keeppos = 1

Does not open closed folds like vim's native commands

The native vim '*' command will open any closed fold in which the search term is located. But when I mapped '*' to the asterisk plugin, I see it only navigates to the closed fold which contains the term, but doesn't actually open it.

Consistency for first match in visual mode

Hello,

I would like to ask if this is expected:

  • When I visually select some text, and then press *, Vim jumps to the next match if available.
  • When I visually select some text, and then press #, Vim stays at the first match.

Is this expected? If not perhaps we should be consistent in how this is handled. Moving to the next match for # seems better to me.

Note that in normal mode pressing # will jump to next match.

Right now I have to use this to work around:

map #  <Plug>(incsearch-nohl)<Plug>(asterisk-#)n

Include GetVisualSelection() as Vim default

Dear @haya14busa ,

in https://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript/28398359#28398359 I propose your function as a robust mean to get the visual selection. There are many other, less robust functions, proposed.

It would be handy if there was such a robust function as yours to get the visual selection included in Vim by default; how about proposing it over at https://github.com/vim/vim/issues ? (If you do not think there are other, even better, say shorter and robuster, alternatives, perhaps in vital.vim.)

Stay star motion

Maybe, it would be better if the cursor stay on current match only the first time ?
Because currently * to move forward is disabeled, is it a feature ?

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.