Reply
Thread Tools
Posts: 11 | Thanked: 6 times | Joined on Jul 2008
#1
Since I'm too lazy to learn VI properly, can someone tell me how to enter the following commands?

edit/open a readonly document, for example a repository list file

delete text in a file (sorry, I'm stupid ;p)

save changes made to a readonly file

Of course once I start editing a readonly file it would mean converting the file to read/write...

All in all, probably not hard to do but I'm still learning the ropes. Thanks in advance.
 

The Following User Says Thank You to taimishu23 For This Useful Post:
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#2
Originally Posted by taimishu23 View Post
Since I'm too lazy to learn VI properly
In that case you'd probably be better off installing nano from the diablo tools repository. If on the other hand you change your mind, you'll probably want to install vim from the same place, since the built-in vi is quite limited.

edit/open a readonly document, for example a repository list file
If it's a file that you have permission to modify just edit as normal and use a "!" in the write command (eg ":w!") to force overwrite. Otherwise you'll have to become root first.

delete text in a file (sorry, I'm stupid ;p)
Several ways:
  • "x" deletes the character under the cursor
  • "X" deletes the character before the cursor
  • "D" deletes to the end of the line
  • "dd" deletes the current line
  • "d" followed by a movement command deletes from the current to the new cursor position, for example:
    • "dw" deletes the next word
    • "db" deletes the previous word
    • "d^" deletes to the beginning of the line
    • "d$" deletes to the end of the line

Also, in vi you can prefix most commands with numeric multipliers, so for example "12x" deletes the next 12 characters and "5dd" the next five lines.

save changes made to a readonly file

Of course once I start editing a readonly file it would mean converting the file to read/write...
See above. Even when vi overwrites a read-only file the permissions are not altered. You should probably avoid changing permissions, especially to system files like the repository list.
 

The Following 5 Users Say Thank You to lma For This Useful Post:
allnameswereout's Avatar
Posts: 3,397 | Thanked: 1,212 times | Joined on Jul 2008 @ Netherlands
#3
You can also install VIm from Garage if you prefer.

Straightforward VI mini howto!
 

The Following 3 Users Say Thank You to allnameswereout For This Useful Post:
Posts: 11 | Thanked: 6 times | Joined on Jul 2008
#4
Thank you kindly.

Yeah, the only reason I'm trying to edit a file I normally wouldn't touch is because the repository list has a bad dependency entry for one of the packages, which doesn't let me install the app.
 

The Following User Says Thank You to taimishu23 For This Useful Post:
Posts: 28 | Thanked: 10 times | Joined on May 2007
#5
There are many right answers to questions like "how do I delete?"

No matter how lazy you are, in fact especially if you're lazy, you should look at a diagram of vi's "modes." You can see a good example at

http://www.ostc.de/vi-overview-eng.pdf

That is a six-slides-on-one-pdf-page intro to vi I just now found by googling vi modes. The second of the six slides is a diagram of vi's modes. I found plenty such diagrams by googling, but this was the best-looking. The other diagrams on that page are also really good.

The most confusing thing about vi for newbs is that it behaves differently depending on which mode it's in. You have to be able to go from one mode to another to be sure that any hint will work (or just say, "well, I *assumed* you'd be in edit mode!" and roll your eyes).

Most of the hints given in this thread assume you're in "command mode" in the above-mentioned diagram. Looking at the diagram, you can probably see that pressing the escape key puts you in this mode or does nothing if you're already in this mode. So if the hints behave unexpectedly, you may want to hit the escape key (the back button on my N800) first.
 

The Following User Says Thank You to zorg For This Useful Post:
Jaffa's Avatar
Posts: 2,535 | Thanked: 6,681 times | Joined on Mar 2008 @ UK
#6
FWIW, vim 7.0 is in Extras-devel.

I'll be promoting it to Extras when the launch script and menu item is integrated into the package: at the moment you have to open X Terminal before using it.

(It's one of the packages I'm using to test the re-invigorated mud-builder - in this case, directly from the upstream source tarball)
__________________
Andrew Flegg -- mailto:andrew@bleb.org | http://www.bleb.org
 

The Following 2 Users Say Thank You to Jaffa For This Useful Post:
Posts: 11 | Thanked: 6 times | Joined on Jul 2008
#7
yep, I'll be spending some time going thru those modes. In the meantime, its nano...


very off topic, but where in the file system are the folders that appear in the built-in file manager? I tried checking /home/user/mydocs and other logical folders but no dice.

Last edited by taimishu23; 2008-07-18 at 21:41.
 

The Following User Says Thank You to taimishu23 For This Useful Post:
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#8
Nope, they're in MyDocs. They're hidden files (UNIXly, files starting with '.' are hidden) so that they don't show up in the file manager. Instead an entry is faked in, with a properly internationalized name, while the actual directories keep the same names.
Code:
ls -a /home/user/MyDocs/
 

The Following 3 Users Say Thank You to Benson For This Useful Post:
cmdowns's Avatar
Posts: 100 | Thanked: 13 times | Joined on Mar 2008
#9
Maybe I'm doing it wrong, but the Xterm vi doesn't really seem that complicated for minor edits.

After launching "vi [file name]", I guess you start off in command mode. The D-pad moves the cursor, x deletes characters. Press "i" for insert mode where you can type whatever text you want to insert into the original file. Esc returns to command mode where you can use ":wq" to save and quit if you're confident that you did everything right, or ":q!" to quit without saving if you're afraid your messed something up.

I'm sure there's way more to it, but the above commands work for my minor modifications.
 

The Following 4 Users Say Thank You to cmdowns For This Useful Post:
Posts: 5,795 | Thanked: 3,151 times | Joined on Feb 2007 @ Agoura Hills Calif
#10
That was a nice vi doc!

The trouble with vi or vim on a tablet, though Ii use it, is that the whole rationale is supposedly that it minimizes finger movement. That kinda falls apart when you are typing everything with one finger, which is what you are doing with a stylus.
 

The Following User Says Thank You to geneven For This Useful Post:
Reply

Tags
text editor, vi vim

Thread Tools

 
Forum Jump


All times are GMT. The time now is 10:54.