sponsor Vim development Vim logo Vim Book Ad

chcmdmod.vim : Misc. commands for search and colon mode

 script karma  Rating 6/5, Downloaded by 2435  Comments, bugs, improvements  Vim wiki

created by
Hari Krishna Dara
 
script type
utility
 
description
This script evolved from a mistake that I used to sometimes make. To start a search, instead of using "/", I would sometimes start with ":" and after typing some text realize I am in the wrong mode, so I wrote this plugin to be able to switch between modes without loosing the text that you already typed, but I added more features to it later.

- When you are in one of the :, / or ? modes, switch to a different mode
  by typing ^X/ or ^X: or ^X?.
- While searching you can press ^S to find the next hit, without needing to
  first press <Enter> followed by n or N. You need to have 'incsearch'
  option turned on for this to work. You can mix this with the ^X/ and ^X?
  to reverse the search without needing to press enter and start over.
- While searching using 'incsearch', you can use ^Xw to complete the
  current word (or ^XW for WORD), <S-Right> to fetch one extra character
  from the end of current match position (or <S-Left> from the beginning).




Search_key_words: command chcmdmod change search Hari Krishna Dara
 
install details
Source this file from your .vimrc or just drop it in your plugin directory.

For versions prior to 2.0:
Requires curcmdmode.vim(1.0) (vimscript #745).
 

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
chcmdmod.vim 2.0 2006-05-09 7.0 Hari Krishna Dara Release 2.0 for Vim7. A lot of it is rewritten to use the new Vim7
features and it is much cleaner and safer now (thanks to the new
getcmdtype() function). Also, it no longer depends on any other plugins.
Now includes commands to retrieve characters from the search location.
chcmdmod.vim 1.0.3 2002-02-07 6.0 Hari Krishna Dara Added an experimental emacs-like feature. Vim already has a nice feature called 'incsearch' which is pretty useful. I have added a ^S command to the search prompt to take you to next search without having to press Enter and type n command. This is how you use it:

- open a file and make sure you have 'incsearch' on.
- start typing a search pattern, say /public
- without pressing Enter, Type ^S. You can see that you are taken to the next hit. Keep going.
- when you want to do a reverse search, just type ^X? and observe that you are now in ? prompt.
- you can start typing ^S again to go to the previous hits.
- when you want the cursor to move to a hit, just press enter as you would normally.
- if you want to cancel the search you can do so, but the original cursor position is restored only if you use ^U or Esc.

Also cleaned up the script a lot and fixed some misc. bugs. But before you start using the script, please be advised that it maps the ? / and : keys in normal mode. It tried to preserve your existing mapping for these keys (I have the / and ? mapped to turn on hlsearch and it continues to work even with the script), but I can't gaurantee that it will always work, so try the script and if you don't face any problems, you can start using it regularly. If you face any problems, please report it to me and I will try to solve it.

Please send in your comments.
chcmdmod.vim 1.0 2001-11-14 6.0 Hari Krishna Dara Initial upload
ip used for rating: 18.119.248.20

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.
   
Vim at Github