-3

I only use vi when I must. The commands I memorized so far are:

:q! exit

ZZ save and exit

$ go to end of line

^ go to beginning of line

I recently installed OpenBSD 5.9. Then I had to use vi or ed to bring up the system because there are no other editors included. So once again I had to search for how to edit and save file with vi and I forget it already. Now I now it's something with pressing ctrl once or twice to switch between modes and :x!! to save and exit. It seems that I only must remember two commands to do what I must and get out of the vi confusion but I use vi so rarely that I tend to forget it what I must know.

Now if I once and for all try to learn the minimal requirement of what I should know e g how to edit a file and save it, which I have been able to do and then I installed nano and emacs.

For instance, I will never forget ctrl+shift+prtscr+B+U+S+I+E+R because of the mnemonic, how can I learn the basics of vi once and for all?

Or did I miss something and vi is actually so much better that the editors I use today (Clion, emacs, nano, Sublime, Gedit). Now I find that I can do almost everything I want by just remembering these simple commands:

:x save and exit

i insert

Esc switch to control mode

Now I find that I can actually use the vi editor to create a file, edit it and save it with this basic knowledge: I create and open the file by writing vi myfile.txt then I can press i to get into insert mode, write my text and then press : x to save and exit. If all goes wrong, I can press Esc twice and :q to get out of vi without saving and start again.

Can you answer or comment if this very basic knowledge of vi will be good enough to save me from googling next time or can you infer what I should or must know next time I'm on a system that only has vi?

closed as primarily opinion-based by statox, nobe4, EvergreenTree, muru May 26 '16 at 9:01

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Are you sure you don't have nano on your system? – romainl May 25 '16 at 5:13
  • @romainl RT*M - OpenBSD does not include nano. – Niklas Rosencrantz May 30 '18 at 17:46
  • you can install packages – romainl May 30 '18 at 19:08
  • @romainl That's impossible without an internet connection and I can't get an internet connection without editing the file. – Niklas Rosencrantz May 30 '18 at 19:09
1

I had the same issue and created a help file with an easy to remember mnemonic eg sf-

See creating Vim help files amongst many more

basically it's a linked list so you have a tag to the help file that loads the help, yeah OK it's probably something else in vim speak but I'm no longer a programmer :)

eg

|sf-transpose-string|   /*the Bar before & after denotes this as the index.
                        /* Basically a key
*sf-transpose-string*  /* The * denotes the helpt text location followed by
                      /* the help text which is unformatted

For example to manipulate the below to change , eg, Page, Jimmy to Jimmy
Page 

Example  
------------
Plant, Robert A.
Page, Jimmy

Use
^* :s/\v([a-z]+),\s+([a-z]+)(\s+[a-z.]+)?/\2\3 \1 ^*   

Breaking it down:

....
/*Separator to the next entry
==============================================================
*sf-replace-nbsp-with-space* *sf-utf* *sf-hex* /*Additional index keys link here
To replace a nbsp with a space do the following
^* :%s/\%xa0/ /g  ^*   

I save it in $VIM\vimfiles\doc with a backup elsewhere as a .txt file. Run :helptags [dir] after saving it to create the help tags needed then in vim type :h sf-vim-general-topics for eg to get to the help

Sure there are other ways but I've set up some mappings and functions to let me add to it on the fly. I use indent folding to make it neater and syntax colouring to makes things stand out but basic text works well

enter image description here

1

Most vi (or Vim) commands are easy to remember since the keys allotted for a function will be related namewise.

Some examples for you Name wise relation:

By remembering the first letter of a function name, you can do it actually.

 d - delete
 p - paste
 v - visual
 J - join
 g - global
 c - change
 r - replace
 i - insert

 g/re/p - globally, regular expressions, print

 Using object motions
 aw - a word
 iw - in word
 a(  -  a ( and content and ending till )
 i(  - text inside ( and )
 a{ - a block
  ap - a paragraph

 You can combine operations with these objects.
 daw - delete a word
 yaw - Yank a word
 di" - delete inside double quotes (")
 ya{ - yank a block
 dap - delete a paragraph

You can add a count to any of these commands, to perform that many times. Example. 5daw - five times delete a word d5aw - same as above.

Similarly, most other commands are also easy to remember since they are related to them in some way or the other.

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