linux vim editor note

vim editor

1. open the file

# vim /path/to/somefile
      vim + #: Open the file, and positioned at the first # line
      vim +: Open File, navigate to the last row
      vim +/PATTERN: Open File, navigate to the line the first time to the line matching PATTERN

2. close the file

1) line mode close the file
:q Quit
:wq to save and exit
:!q to exit without saving
:w save
:!w forced to save
:wq ->: x
2) exit edit mode
:ZZ Save and Exit

3. move the cursor

1) character by character movement

     h: Left
     l: Right
     j: Down
     k: Up
   #h: move # characters

2) move a word

     w: Move to the first word of the next word
     e: Skip the current or next word endings
     b: Skip the current or previous word first word
     
#w: Beginning to move to the first # words
3) inline jump

     0: Absolute first line
     ^: The first non-white character of the line
     $: The absolute end of the line

4) between the lines jump

     #G: Go to page # row
      G: The last line

4. the scroll (edit mode)

Ctrl + f: scroll down one screen
Ctrl + b: scroll up one screen

Ctrl + d: scroll down half screen
Ctrl + u: scroll up half screen

5. delete a single character

x: delete a single character located at the cursor
#x: Delete at the cursor backward character of #

6. the Delete command

d: command used in combination with a jump command
#dw, #de, #db

dd: delete the current cursor line
#dd: Delete, including the current cursor location, including the line # line;

Line mode:
StartADD,EndADDd
    .: the current row
    $: The last line ($-#, $+#)
    + #: # Row down

7. the Paste command p

p: If you delete or copy the contents of the entire line, then paste it into the bottom of the line where the cursor is, if you copy or delete the contents of the non-integer row, then paste it to the back where the character cursor
P: If you delete or copy the contents of the entire line, then paste it to the top of the line where the cursor is, if you copy or delete the contents of the non-integer row, then paste it to the front where the character cursor

8. the copy command y

    the same as d command in use

9. first delete the contents, then converted to the input mode

    c: the same as d command in use

10. replace

r: replace a single character
R: direct access to replace mode

11. undo edits

u: before you undo the last editing operation

Undo Undo the last operation: Ctrl + r

12. repeats the last editing operation

.

13. visual mode

v: Choose by character
V: select a rectangular block

14. find

/ PATTERN order to find
? PATTERN descending find

15. find and replace

Use s command line mode
ADDR1, ADDR2s @ PATTERN @ string @ gi
    .: the current row
$: The last line ($-#, $+#)
+#: #Row down
%: find full text

16. edit multiple files using vim

vim FILE1 FILE2 FILE3
: Next switch to the next file
: Prev Switch to the previous file
: Last switch to the last file
: First switch to the first file

drop out
: Qa all out

17. split screen displays a file

Ctrl + w, s: horizontal split window
Ctrl + w, v: vertical split window

Switch between windows cursor:
Ctrl + w, ARROW

:qa Close all windows

18. sub-window editing multiple files

vim -o: horizontal split display
vim -O: vertical split display

19. the front part of the contents of the file saved as another file

Use w command line mode
:w
:ADDR1, ADDR2w /path/to/somewhere

20. fill the part of the other file's contents to the current file

:r /path/to/somefile

21. with interactive shell

:!COMMAND

22. Advanced Topics

1) display or suppress line numbers

:set number
:set nu

:set nonu

2) Show ignored or distinguish the character case

:set ignorecase
:set ic

:set noic

3) set up automatic indentation

:set autoindent
:set ai
:set noai

4) the found text is highlighted or cancel

:set hlsearch
:set nohlsearch

5) syntax highlighting

: Syntax on
: Syntax off

23. profile

/etc/vimrc
~/.vimrc

Pingbacks are closed.

Comments are closed.