Linear selection in VIM

How can I select all lines that do not contain the word “hello” in VIM? I need him to jerk and then save the file. How can I do it? I am looking for something like:

: v /! (hello)> file

+3
source share
10 answers
:g!/hello/ yank A

Lines are now stored in register a, to insert them, execute "ap

Edit: May be reduced to

:g!/hello/y A

For those interested in what this means for vim:

: g =
!= , /hello/ = ""
y = , "yank"
A = "yank". 'a', , .

+11

grep , :

:!grep -v hello % > file
+9

, , .

,

:redir > file
:g!/hello/
:redir END

.

:help redir
:help verbosefile
+6

:g/hello/d

. , "", , yank - , , , , u. , , .

+5

fgm

: v ,

, "hello", eee, , .

:v/hello/ . w!>>eee
+4

:

:g/hello/ . w!>> file 
+1

,

:v/hello/ |redir >> file
+1

Vim

:let @a='' | g!/hello/normal "Ayy

, "hello" "a". "ap normal"

:let @*=@a

"Ctrl + V" Windows "Cmd + V" Mac Os " " Linux .

:

@a - Vim, , 'a'.
"ap, " bp, "cp,.. Vim, .
@* - Vim, .
let @* = @a 'a' System.

.vimrc .

function s:copy_unmathced_lines(pattern)
   let result_lines = []

   for line in getline(1, '$')
      if line !~ a:pattern
         call add(result_lines, line)
      endif
   endfor

   let @* = join(result_lines, "\n")
endfunction

command -nargs=1 CopyUnmatchedLines call s:copy_unmathced_lines(<q-args>)

:

CopyUnmatchedLines hello

.

0

Blixtor: , :: verbosefile.

. ": e/tmp/new_file" ": h verbosefile", blixtor copy-cat:

:redir > /tmp/verbosefile_instructions
:g/verbosefile/
:redir END

II. , legth :

:match ErrorMsg /\%>73v.\+/
:so /bin/greetings.vim

III. Mutt.

0

: , :

  • ":"

  • :

    : '<,' > ! > ../new_file_in_a_subdirectory

Error: the colors will be copied to the file, and in fact it does not cope with cropping and pasting.

0
source

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


All Articles