Powerful Command Line Tools P.3 (Linux Development Tools vim)

Time:2024-4-1

Powerful Command Line Tools P.3 (Linux Development Tools vim)

preamble

Previously we talked about the basics of the C language, but also understand some of the data structure, and talked about some of the knowledge of C++, but also learn some of the basic operation of Linux, but also believe that we have a good grasp of today’s blogger to take you to understand the Linux development tools – vim, the following words do not talk about sit still hold on good! We are going to drive!

Introduction to vim

concept

Vim (Vi IMproved) is a text editor widely used on Unix and Unix-like systems. It is an enhanced version of the Vi editor, offering more features and an improved user experience.With powerful editing capabilities and a high degree of customizability, Vim is widely regarded as one of the most popular editors used by programmers and system administrators. Mastering the basic concepts and features of Vim will make your text editing work on Linux systems more efficient and convenient. Through practice and exploration, you can gradually familiarize yourself with and become proficient in the use of Vim.
Powerful Command Line Tools P.3 (Linux Development Tools vim)

specificities

  1. Vi and Vim: Vi is a text editor for Unix systems, and it is the predecessor of Vim.Vim (Vi IMproved) is an improved and enhanced editor for Vi.Vim retains all the functionality of Vi and adds many new features and commands.

  2. Terminal: In Linux, Vim is usually run in a terminal. Terminal is a command-line interface on Linux that allows users to interact with the computer through command-line input.

  3. Modes: Vim has different editing modes, three main ones:

    • Command mode: The default mode entered after starting Vim or pressing Esc. You can execute commands and move the cursor.
    • Insert mode: In command mode, press theiaoetc. character entry mode. Text contents can be entered.
    • Visual mode: In command mode press thevThe mode of entry. Text can be selected and manipulated.
  4. Commands and shortcuts: In command mode, you can use various commands and shortcuts to perform different operations, such as saving files, exiting Vim, copying and pasting text, and so on.

  5. Configuration: Vim has a configuration file.vimrc, which is used to set and customize Vim’s behavior. Users can add custom color schemes, indentation settings, plugin management, and more in the configuration file.

  6. Plugins and extensions: Vim supports a plugin system that allows users to install extensions. There are many community-maintained plug-ins available that can add various features such as code completion, syntax highlighting, etc.

  7. Help documentation: Vim comes with detailed built-in help documentation. You can access this documentation via the command mode:helpcommand opens the help system to find and learn Vim’s commands and features.

Commands related to vim

vim command mode (Normal mode) related commands

Vim’s command mode (Normal mode) isDefault mode entered after starting Vim or pressing the Esc key. In the command mode, you can execute various commands and move the cursor, the following are some common command instructions:

  1. Cursor movement:

    • h: Moves the cursor one character to the left.
    • j: Moves the cursor down one line.
    • k: Moves the cursor up one line.
    • l: Moves the cursor one character to the right.
    • 0: Moves the cursor to the beginning of the current line.
    • $: Moves the cursor to the end of the current line.
    • gg: Moves the cursor to the first line of the file.
    • G: Moves the cursor to the last line of the file.
    • Ctrl+f: Turn down the page.
    • Ctrl+b: Turn the page up.
  2. Text Editor:

    • i: Enter insertion mode to insert text at the current position.
    • a: Enters insertion mode and inserts text at the next character from the current position.
    • o: Inserts a new line below the current line and enters insert mode.
    • O: Inserts a new line above the current line and enters insert mode.
    • x: Deletes the character at the cursor location.
    • dd: Delete the current line.
    • yy: Copies the current line.
    • p: Paste the copied content.
  3. Undo and redo:

    • u: Undo the last operation.
    • Ctrl+r: Redo the last undone operation.
  4. Find and Replace:

    • /keyword:: Finding keywords backwards in a filekeyword
    • ?keyword:: Finding keywords forward in a documentkeyword
    • n: Continue to find the next match in the current direction.
    • N: Continues the search for the previous match in the current direction.
    • :s/old/new: The first occurrence ofoldReplace withnew
    • :%s/old/new/g:: Include all occurrences ofoldReplace withnew
  5. Save and exit:

    • :w: Save the document.
    • :q: Exit Vim.
    • :wq maybe:x: Save and exit Vim.
    • :q!: Force exit from Vim, discarding all changes.

These are just a few of the commonly used command mode commands. The Vim command mode provides numerous commands and functions to cover almost all text editing needs. Through practice and experimentation, you will gradually master more commands and techniques. You can do this by typing:help or consult the documentation for Vim for more information.

Insert mode related commands

Insert mode in Vimis in command mode by pressingiaoWaiting for the character to enter the mode. In insert mode, you can enter and edit text. The following are some commonly used insert mode commands:

  1. Insert text:

    • i: Inserts text before the current cursor position.
    • a: Inserts text after the current cursor position.
    • o: Inserts a new line below the current line and enters insert mode.
    • O: Inserts a new line above the current line and enters insert mode.
  2. Cursor movement:

    • Left Arrow maybeCtrl+h: Moves the cursor one character to the left.
    • Right Arrow maybeCtrl+l: Moves the cursor one character to the right.
    • Up Arrow maybeCtrl+k: Moves the cursor up one line.
    • Down Arrow maybeCtrl+j: Moves the cursor down one line.
    • Home: Moves the cursor to the beginning of the current line.
    • End: Moves the cursor to the end of the current line.
  3. Delete and edit:

    • Backspace maybeCtrl+h: Deletes a character before the cursor.
    • Delete maybeCtrl+d: Deletes a character after the cursor.
    • Ctrl+w: Delete a word before the cursor.
    • Ctrl+u: Deletes all contents of the current line.
    • Ctrl+t: Indent the current line.
    • Ctrl+d: Unindent the current line.
    • Ctrl+v: Enter special characters.
  4. Exits insertion mode:

    • Esc: Exits insertion mode and returns to command mode.

In insert mode, you can freely enter and edit text content. Once you exit the Insert Mode, you can use various commands in the Command Mode, such as saving files, undoing operations, searching, and so on. Through practice and use, you will gradually familiarize yourself with the operation of Insert Mode and be able to edit and modify text files efficiently.

Last line mode related commands

Last Line modeis an operation that begins with a colon in command mode, which is used to perform a series of operations and commands. Some advanced editing and operations can be performed in endline mode, and the following are some commonly used endline mode commands:

  1. Save and exit:

    • :w maybe:write: Save the current file.
    • :w filename maybe:write filename: Saves the current file with the specified filename.
    • :q maybe:quit: Exit Vim.
    • :q! maybe:quit!: Force exit from Vim, discarding all changes.
    • :wq maybe:x maybe:xit maybe:writequit: Save and exit Vim.
  2. Open and edit files:

    • :e filename maybe:edit filename: Open the specified file.
    • :new maybe:new filename: Open the specified file in a new sub-window.
    • :tabnew maybe:tabnew filename: Opens the specified file in a new tab.
    • :split filename: Splits the current window and opens the specified file in the new window.
    • :vsplit filename: Splits the current window vertically and opens the specified file in the new window.
  3. Search and replace:

    • :/pattern maybe:search pattern: Searches backward through the current file for matching patterns.
    • :?pattern maybe:search? pattern: Searches forward in the current file for matching patterns.
    • :s/old/new maybe:substitute/old/new:: Sets the first occurrence of the current line’soldReplace withnew
    • :%s/old/new/g maybe:%substitute/old/new/g:: Remove all occurrences ofoldReplace withnew
  4. Line numbers and jumps:

    • :n maybe:n line_number: Jumps to the specified line number.
    • :n maybe:n +offset: Jumps to the line with the current line number plus an offset.
    • :n maybe:n -offset: Jumps to the line with the current line number minus the offset.
    • :rewind maybe:rew: Jumps to the first line of the file.
    • :last maybe:la maybe:$: Jump to the last line of the file.
    • :first maybe:fi maybe:1: Jumps to the first line of the file.
  5. Window management:

    • :only maybe:on: Closes windows other than the current window.
    • :sp filename maybe:split filename: Splits the current window horizontally and opens the specified file in the new window.
    • :vsp filename maybe:vsplit filename: Splits the current window vertically and opens the specified file in the new window.
    • :close maybe:clo: Closes the current window.
    • :wincmd h/j/k/l maybeCtrl+w h/j/k/l: Use the arrow keys to control the movement of the cursor between windows.

These are some common endline mode commands that you can use to perform various commands and operations in endline mode. By practicing and knowing more commands, you can edit and operate more efficiently.

Simple vim configuration (with configuration links)

To configure a good-looking vim, the native configuration may not be fully functional, you can choose to install plug-ins to improve the configuration, to ensure that the user is the user you want to configure, the next blogger recommended a link inside the detailed configuration process as well as the link, directly in accordance with the above step-by-step believe that the good use of very much.
Powerful Command Line Tools P.3 (Linux Development Tools vim)

Configuration Links:VimForCpp

Recommended Reading:vim from zero to hero

Spanish jasmine (Jasminum grandiflorum)

Thank you for your interest and support for the blog post! While reading this post, we would like to remind you to leave your valuable comments and feedback. If you like this article, you can like, comment and share it with your classmates, which will provide me with great encouragement and support. Also, I plan to keep exploring content related to this article in future updates. I will bring you more in-depth analysis, use cases and fun plays on technical issues of Linux as well as C++ programming. Stay tuned to the blogger’s updates and don’t miss any of the exciting content!

Thank you again for your support and interest. We look forward to establishing closer interaction with you and exploring the mysteries of Linux, C++, algorithms and programming together. We wish you a happy life and a smooth bowel movement!

Powerful Command Line Tools P.3 (Linux Development Tools vim)

Recommended Today

[linux] Permission Understanding

catalogs 1. shell commands and how they work 2. The concept of authority 3. Authority management 2.1 Classification of document visitors (persons) 2.2 File types and access rights (thing attributes) 2.3 Representation of file permission values 2.4 Methods for setting file access rights 3. The file directive 4. Permissions for directories★ 5. Sticky bits★ 6. […]