3

I would like to start overwriting immediately visually selected text without any additional keystrokes such as c. I am looking something similar to normal text editor where you can straightaway replace selected text by typing in new text. Thank you for your help!

EDIT: My main concern is the extra keystroke of c to start overwriting. Any tips/suggestions that can remove this extra keystroke in any other way are welcome :)

  • Can you please share the context? If by "visually selected text" you mean mouse selected text (Select-mode instead of Visual-mode) you just need to remain in insert mode to achieve that. In this case evim might be helpful. – mMontu Jun 19 '18 at 19:22
  • You can start Select-mode by pressing gh, gH or g<Ctrl-H>, which will behave like visual mode in normal gui editors (e.g. typing will overwrite the visually selected text) – Christian Brabandt Jun 19 '18 at 19:28
  • @mMontu, thank you for your suggestions. I'm looking for visual mode only not select mode. I am fine with select mode if it has the same power of expanding the selection as in visual mode. But I guess select mode is very limited in that sense. I'm curious what experienced vim users do in this case. Do they always type s or c to replace the visually selected text or do they define some mappings/commands/etc. to jump that step? – omsrisagar Jun 19 '18 at 19:58
  • 1
    Visual mode is a launching point for many vim operations, so yes, I typically hit c (it’s one keystroke) once I’ve made my selection. Mappings and commands wouldnt make sense as they add complexity. And it would be difficult (not to mention counter-intuitive) to skip that step because you have to delineate « visually select text » and « change selected text ». One stroke is about as efficient as it gets. – D. Ben Knoble Jun 19 '18 at 21:10
  • 3
    I am fine with select mode if it has the same power of expanding the selection as in visual mode. You have a misunderstanding here. If you want typing to immediately overwrite the text and you want to be able to use vim-motions to expand the text, what should happen if you type j? Should it overwrite the text or move the selection downwards? Think of visual mode like normal mode. It's useful for manipulating the text, but once you want to modify it you need one button to change modes (i from insert or c/s from visual) – DJMcMayhem Jun 19 '18 at 22:02
1

I believe most experienced users employ visual mode in very few/specific cases.

You could use visual mode mainly as a tool to help learn the commands (like training wheels to learn to ride a bike). For example: you type vwwc to replace the next two words, until you feel comfortable to type c2w and drop the visual aid. This answer ("Your problem with Vim is that you don't grok vi") has more information about it.

In addition to the movement regarding large blocks explained on that answer, Vim provides lots of movements to use in the current line, such as f/F/t/T. And most of them accepts a count.

So you could replace up to the start of this sentence by typing cFS, or c2Fm to replace up to most on the previous sentence. Once you can avoid smaller steps such as j and l it becomes easier to drop visual mode.

Vim has a really good documentation/help system, so it is probably the best way to learn such movements (just type :help). Here are some other good resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.