LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2010, 12:19 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Rep: Reputation: 51
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.

Last edited by stf92; 12-02-2010 at 12:21 PM.
 
Old 12-02-2010, 12:25 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
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
 
1 members found this post helpful.
Old 12-02-2010, 12:40 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Perhaps there is the possibility do build macros in vim. It would be odd if it had not. Thanks for you generous reply.
 
Old 12-02-2010, 12:47 PM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
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
 
Old 12-02-2010, 12:51 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Thanks for the info. Yours has been fine help. Regards.
 
Old 12-03-2010, 01:13 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
Old 12-03-2010, 08:24 AM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by chrism01 View Post
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.
 
Old 12-03-2010, 11:16 PM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Of course I am. Thanks for your explanation.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with "error: invalid conversion from `const char*' to `char*' " dave.f.one Linux - Newbie 11 02-11-2015 08:17 AM
[SOLVED] how can I search "$" in vim ,which is not the end of line but the real char '$'. e3399 Linux - Newbie 1 12-01-2010 11:01 AM
bad: Want to insert a line into a text file using "sed" command eliote Linux - General 7 09-19-2010 03:55 AM
C++ - "snprintf" inside "for" doesn't work as expected. (int to char*) Repgahroll Programming 14 08-31-2010 09:27 AM
C++ help Dynamic array and "invalid conversion from ‘char’ to ‘char*’" heathf Programming 2 04-25-2009 10:20 PM


All times are GMT -5. The time now is 09:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration