Home

Awesome

ctrlsf.vim

An ack/ag/pt/rg powered code search and view tool, takes advantage of Vim 8's power to support asynchronous searching, and lets you edit file in-place with Edit Mode.

Asynchronous Search

A demo shows how to search a word in an asynchronous way.

ctrlsf async_demo

Compact View

A demo shows compact view which looks more similar to Vim's quickfix windows.

ctrlsf compact_demo

Edit Mode

A demo shows how to rename a method named FocusWindow() to Focus() in multiple files, using vim-multiple-cursors.

ctrlsf_edit_demo

Table of Contents

Features

Installation

  1. Make sure you have ack, ag, pt or rg installed. (Note: currently only Ack2 is supported by plan)

  2. An easy way to install CtrlSF is using a package manager, like pathogen, vundle, neobundle or vim-plug.

    In vim-plug:

    Plug 'dyng/ctrlsf.vim'
    
  3. Read Quick Start for how to use.

Quick Start

  1. Run :CtrlSF [pattern], it will split a new window to show search result.

  2. If you are doing an asynchronous searching, you can explore and edit other files in the meanwhile, and can always press Ctrl-C to stop searching.

  3. In the result window, press Enter/o to open corresponding file, or press q to quit.

  4. Press p to explore file in a preview window if you only want a glance.

  5. You can edit search result as you like. Whenever you apply a change, you can save your change to actual file by :w.

  6. If you change your mind after saving, you can always undo it by pressing u and saving it again.

  7. :CtrlSFOpen can reopen CtrlSF window when you have closed CtrlSF window. It is free because it won't invoke a same but new search. A handy command :CtrlSFToggle is also available.

  8. If you prefer a quickfix-like result window, just try to press M in CtrlSF window.

Key Maps

In CtrlSF window:

In preview window:

Some default defined keys may conflict with keys you have been used to when you are editing. But don't worry, you can customize your mapping by setting g:ctrlsf_mapping. :h g:ctrlsf_mapping for more information.

Use Your Own Map

CtrlSF provides many maps which you can use for quick accessing all features, here I will list some most useful ones.

For a full list of maps, please refer to the document.

I strongly recommend you should do some maps for a nicer user experience, because typing 8 characters for every single search is really boring and painful experience. Another reason is that one of the most useful feature 'Search Visual Selected Word' can be accessed by map only.

Example:

nmap     <C-F>f <Plug>CtrlSFPrompt
vmap     <C-F>f <Plug>CtrlSFVwordPath
vmap     <C-F>F <Plug>CtrlSFVwordExec
nmap     <C-F>n <Plug>CtrlSFCwordPath
nmap     <C-F>p <Plug>CtrlSFPwordPath
nnoremap <C-F>o :CtrlSFOpen<CR>
nnoremap <C-F>t :CtrlSFToggle<CR>
inoremap <C-F>t <Esc>:CtrlSFToggle<CR>

Edit Mode

  1. Edit mode is not really a 'mode'. You don't need to press any key to enter edit mode, just edit the result directly.

  2. When your editing is done, save it and CtrlSF will ask you for confirmation, 'y' or just enter will make CtrlSF apply those changes to actual files. (You can turn off confirmation by setting g:ctrlsf_confirm_save to 0)

  3. Undo is the same as regular editing. You just need to press 'u' and save again.

  4. Finally I recommend using vim-multiple-cursors together with edit mode.

Limitation

Arguments

CtrlSF has a lot of arguments you can use in search. Most arguments are similar to Ack/Ag's but not perfectly same. Here are some most frequently used arguments:

Read :h ctrlsf-arguments for a full list of arguments.

Example

Tips

Configuration

A full list of options can be found in :help ctrlsf-options.

For user comes from pre v1.0

Difference between v1.0 and pre-v1.0

There are many features and changes introduced in v1.0, but the most important difference is v1.0 breaks backward compatibility.

Where and why backward compatibility is given up?

CtrlSF is at first designed as a wrapper of ag/ack within vim, and the principle of interface design is sticking to the interface of ag/ack running upon shell. This fact lets user get access to all features of ag/ack, and it's easier to implement too. However I found it is not as useful as I thought, what's worse, this principle limits features I could add to CtrlSF and makes CtrlSF counter-intuitive sometimes.

So I want to change it.

Example:

Case-insensitive searching in pre-v1.0 CtrlSF is like this

CtrlSF -i foo

In v1.0, that will be replaced by

CtrlSF -ignorecase foo

For those most frequently used arguments, an upper case short version is available

CtrlSF -I foo