Posts tagged ‘vi’

Using vi / vim to Encrypt Text Files

vim.png

The disadvantage of using encrypted partitions is that while the partition is mounted, at least root can access the data. To prevent this, vi can be used in encrypted mode.

Use vi -x filename (or vim alternatively) to edit a new file. vi prompts you to set a password, after which it encrypts the content of the file. Whenever you access this file, vi requests the correct password.

For even more security, you can place the encrypted text file in an encrypted partition. This is recommended because the encryption used in vi is not very strong.

Source

Vi and Vim Cheatsheets

vim.png

Continue reading ‘Vi and Vim Cheatsheets’ »

Vi/Vim and no disk space

vim.png

If you get the error while opening a file in vi,

“There is not enough space in the file system.
[Press return to continue]”

and you know that you have space in your home directory, than simply use this command
in vi, say

:set dir=

then press:

:e .

You will be able to see the entire file.

Suspend a Vi/Vim session for shell

vim.png

Ever want to run some shell commands while doing a vi edit session? Like, “what’s the name of that file” I want to use in this script I’m making?

Instead of exiting vi; doing the ls filenamepart*, and going back into vi, you can from a vi session:

enter “:”, then enter “shell”.

This suspends the vi session and gives you a command prompt where you can use any shell command. When finished, enter the “exit” command and you will be returned to the vi session.

How to go a particular line or word in vi/vim

vim.png

You can go to a particular line or word in a file using vi in several ways:

  • To make vi start at a particular line in a file, add +line_num to the command you use to start vi. Replace line_num with the line number, for example: vi +36 foo.c
  • If you’re already in vi, you can use the goto command. To do this, press Esc, type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.
  • You can also use the ex command line to go to a line. For instance, if you wanted to go to line 14, you could press Esc and then enter: :14
  • To search forward for some text, use the / (forward slash) command. Press Esc and then enter /pattern , replacing pattern with the text for which you want to search forward. For example, to find every instance of the word “blimp”, enter: /blimp To look for the next occurrence after the first, either press n or press / again and then press Enter. To go back to a previous occurrence, press Shift-n . To search backwards in a file, use the ? command.
  • To see what line you’re on at any time, press Ctrl-Shift-g . To number all lines, press Esc and enter: :set number

Search and Replace in Vi/Vim

vim.png

In Vi or Vim, use the forward slash </> to search. Then type in your search string and hit <Enter>. You can navigate through occurrences of your search string using <n> to move forward and <N> to move backwards.

Continue reading ‘Search and Replace in Vi/Vim’ »

Copy between files in vi/vim

vim.png

VI editor is a very powerful editor. Suppose you want to copy line numbers 1-10 and 23-77 of file A and paste them on file B at the same time, what will you do ?? Here I am giving a tip to do this :

Continue reading ‘Copy between files in vi/vim’ »

How to Use vi / vim

vim.png

From wikipedia: vi is a screen-oriented text editor written by Bill Joy in 1976 for an early BSD release. The name vi is derived from the shortest unambiguous abbreviation for the command visual in ex; the command in question switches the line editor ex to visual mode. Current releases of vi are free and open source software, usually released under permissive free software licenses> such as the BSD License. vi is the commandline text editor of choice (well, not if you ask the emacs crowd), but the reason for it’s widespread use is that it can fit on a floppy disk to aid system recovery. It is a power editor with many options to navigate and manipulate text and we’ll covers the basics here.

Download the Cheat Sheet: vicheatsheet.pdf (source )

Continue reading ‘How to Use vi / vim’ »