Select first words multiple lines vim

I would like to copy the first words from several lines.

Code example:

apiKey := fmt.Sprintf("&apiKey=%s", args.ApiKey)
maxCount := fmt.Sprintf("&maxCount=%d", args.MaxCount)
id := fmt.Sprintf("&id=%s", args.Id)
userid := fmt.Sprintf("&userid=%s", args.Userid)
requestFields := fmt.Sprintf("&requestFields=%s", args.RequestFields)

I would like to have this in my clipboard:

apiKey
maxCount
id
userid
requestFields

I tried using ctrl-v and after e, but it copies as in the image: enter image description here

+4
source share
2 answers

You can add every first word to an empty register (say q) using

:'<,'>norm! "Qyiw

That is, in each line of visual selection, execute a sequence of "Qyiwcommands normalto add the (first) "inner word" to the register q.

You need to have >in cpoptionsfor the new line to be added between yanks ( :set cpoptions+=>), otherwise the words will be combined into one line.

, qqq ( qaq a).

: ("") , , "qp , p .

+8

, , .

, , , . , tabular, Align easy-align.

:Tab/: :

apiKey        : = fmt.Sprintf("&apiKey=%s", args.ApiKey)
maxCount      : = fmt.Sprintf("&maxCount=%d", args.MaxCount)
id            : = fmt.Sprintf("&id=%s", args.Id)
userid        : = fmt.Sprintf("&userid=%s", args.Userid)
requestFields : = fmt.Sprintf("&requestFields=%s", args.RequestFields)

, , u, .

+1

Source: https://habr.com/ru/post/1673136/


All Articles