Oeasy teaches you to play VIM – 16 and jump to a certain line

Time:2022-5-9

Jump to a line

Recall the last lesson

  • Up and down

    • towardsloweryesj👇
    • towardsupperyesk👆
  • Uplink and downlink head

    • towardslowerTo non empty character at the beginning of line+
    • towardsupperTo non empty character at the beginning of line-
    • thesemotionCan be added[count]To double
  • First and last lines

    • The first line isg g
    • The last line isG
    • g g = GIs auto indent all
    • GThere seem to be other uses?
  • What usage?
  • First useNo configurationofviopenoeasy.java

Jump directly to a line

Oeasy teaches you to play VIM - 16 and jump to a certain line

  • Jump directly to a line goto line

    • 2 GSkip to step2that ‘s ok
    • 3GSkip to step3that ‘s ok
    • 4GSkip to step4that ‘s ok
    • ggSkip to step1that ‘s ok
    • GSkip to the last line
  • This is really convenient

    • Especially when the compiler reports an error and a line has a problem
    • DirectlyGotoIt’s over
  • If there are too many lines

    • How can I get to the line where I’m going?
    • This requires the line number to be displayed

set number

  • :set numberYes display line number

    • :setIs a command that can set various properties
    • numberyes:setParameter option
    • Is a switch attribute responsible for displaying the line number
  • We can pass:h :setTo view various properties

    • These help manuals are inoptions.txtin

Oeasy teaches you to play VIM - 16 and jump to a certain line

  • We can not only opennumberswitch

    • :set numberopennumberswitch
    • set number
  • It can also be closednumberswitch

    • numberAdd beforenoRepresents turning off the switch
    • :set nonumberclosenumber, do not display line numbers
  • Abbreviation

    • :se[t] nu[mber]Can be abbreviated as:se nu
    • :se[t] nonu[mber]Can be abbreviated asse nonu

Show relative line numbers

  • We can not only display the absolute line number
  • Relative line numbers can also be displayed
  • Alsooptions.txtIn this document
  • This switch is calledrelativenumber

    • Relative line number
    • :set relativenumber

Oeasy teaches you to play VIM - 16 and jump to a certain line

  • You can see the corresponding position of the current cursor0that ‘s ok

    • The upward line number is calculated from the current line
    • The downward line number is also calculated from the current line
    • In this way, the up and down movement will be more accurate
    • 4jYou can know that the cursor falls on the lower mark4My line
    • 5kYou can know that the cursor falls on it5My line
  • If I set it at the same timese nuWhat will happen?

    • The current line displays the absolute line number, and the upper and lower parts display the relative line number
  • Relative line number abbreviation

    • set relativenumberAbbreviated asse rnu
    • set norelativenumberAbbreviated asse nornu

Line command mode jump

Oeasy teaches you to play VIM - 16 and jump to a certain line

  • We can also use command-line mode jump

    • :30Skip to step30that ‘s ok
    • :40Skip to step40that ‘s ok
    • :40Skip to step50that ‘s ok
    • :6000000Skip to the end if the whole text doesn’t6000000If you can
  • How do I know how many lines there are in the current file?

    • Remember:f[ile]Are you?
    • The shortcut key isctrl g

Display location

Oeasy teaches you to play VIM - 16 and jump to a certain line

  • We can passctrl gSee:

    • file name
    • Current line number
    • Total number of rows
    • Current position percentage
    • Current column position

summary

  • Jump to line number

    • 200G
  • Set line number options

    • set number :se nu
    • Show relative line numbers:se rnu
  • How to jump from the command line:100
  • But sometimes I can’t remember how many lines I jump to
  • Can you make a mark and leave a mark?
  • Next time