LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Vi/vim and the "insert-only-one-char" command. (https://www.linuxquestions.org/questions/linux-newbie-8/vi-vim-and-the-insert-only-one-char-command-847965/)

stf92 12-02-2010 11:19 AM

Vi/vim and the "insert-only-one-char" command.
 
Vi 2.2, vim 7.1

Hi:
If you please, a vim (alghough I esteem the corresponging vi command is the same) command to insert one character only, into the text being edited. That is, I'm in command mode, I issue command INSERT, I type a character, and automatically I'm again in command mode, where INSERT is the command I do not know. I have vimtutor but do not see it explained there. Any hint will be welcome.

markush 12-02-2010 11:25 AM

Well,

this will not work, but there is the "r" command in commandmode, this replaces the character which the cursor is under. This means "r" is the same as "x" "i" "character" "ESC".

Another possibility to insert one charater without leaving the commandmode would be to yank the new character and paste it with "p".

Markus

stf92 12-02-2010 11:40 AM

Perhaps there is the possibility do build macros in vim. It would be odd if it had not. Thanks for you generous reply.

markush 12-02-2010 11:47 AM

A macro with vim, this is a good idea, but be aware, that this will be a "vim only" solution. As I understood your requirements, you want the solution to work also with vi.

You may record a macro in vim
Code:

q a i c ESC q
where "c" is the new character to be inserted. this macro is stored in buffer a and can be edited and adapted to your needs. Maybe this helps.

For more information about vim try ":help" in command mode (not ":help!" ;) )

Markus

stf92 12-02-2010 11:51 AM

Thanks for the info. Yours has been fine help. Regards.

chrism01 12-03-2010 12:13 AM

I'm not quite sure what you mean here
Quote:

automatically I'm again in command mode, where INSERT is the command I do not know
but in vi/vim once you start a cmd like 'insert', you stay in that 'mode' until you hit the ESC key.
Simlarly with append ( shift-a) etc etc.
vi/vim is a modal editor.
If you want vim macros, see here; http://vimdoc.sourceforge.net/htmldoc/usr_10.html#10.1

MTK358 12-03-2010 07:24 AM

Quote:

Originally Posted by chrism01 (Post 4179139)
I'm not quite sure what you mean here

but in vi/vim once you start a cmd like 'insert', you stay in that 'mode' until you hit the ESC key.
Simlarly with append ( shift-a) etc etc.
vi/vim is a modal editor.
If you want vim macros, see here; http://vimdoc.sourceforge.net/htmldoc/usr_10.html#10.1

he's not falsely describing Vim's operation, he's describing a feature he would want.

stf92 12-03-2010 10:16 PM

Of course I am. Thanks for your explanation.


All times are GMT -5. The time now is 05:28 AM.