VIM for linux ( File editing and handling)

VIM for linux ( File editing and handling)

Working with the files in vim can be daunting here is a quick guide to vim

When working with files in the vi editor through the Linux command line interface (CLI), you can perform various file handling operations. Here are some common tasks and commands for handling files in vi:

  1. Opening a file in vi: To open a file in vi, use the following command:

     Copy codevi filename
    

    This command opens the specified file in vi for editing. If the file does not exist, a new file with that name will be created when you save.

  2. Navigating within a file: Once you are in vi, you can use the following navigation commands:

    • Move the cursor:

      • h: Move left

      • j: Move down

      • k: Move up

      • l: Move right

    • Jump to a specific line:

      • :n: Go to line number "n"
  3. Editing a file: While in vi, you can edit the contents of the file:

    • Insert mode: Press i to enter insert mode, where you can type and edit text.

    • Command mode: Press Esc to exit insert mode and enter command mode.

      • Save and exit: In command mode, enter :wq to save the changes and exit vi.

      • Exit without saving: In command mode, enter :q! to exit vi without saving changes.

  4. Deleting text: To delete characters or lines in vi:

    • Delete character: In command mode, move the cursor to the desired character and press x.

    • Delete line: In command mode, move the cursor to the desired line and press dd.

  5. Searching within a file: To search for a specific word or pattern in vi:

    • In command mode, type / followed by the word or pattern and press Enter.

    • To find the next occurrence, press n. To find the previous occurrence, press N.

  6. Copying, cutting, and pasting text: To copy, cut, and paste text in vi:

    • Copy: In command mode, move the cursor to the desired text and type yy to copy a line or yw to copy a word.

    • Cut: In command mode, move the cursor to the desired text and type dd to cut a line or dw to cut a word.

    • Paste: In command mode, move the cursor to the desired location and type p to paste the copied or cut text.

These are some basic commands for handling files in the vi editor. Vi has many more features and commands for advanced editing tasks. To learn more about vi, you can access the built-in vi help by typing :help within vi or refer to external vi tutorials and documentation.