简体   繁体   中英

How do I select a specific block of text in vim?

These are the contents in my file

-r-xr-xr-x 1 dinesh eng  29072 Aug 26  2004 config.sub
-r-xr-xr-x 1 dinesh eng  38515 Aug 26  2004 config.guess
-r-xr-xr-x 1 dinesh eng   5643 Aug 26  2004 install-sh
-r-xr-xr-x 1 dinesh eng    767 Aug 26  2004 mkinstalldirs
-r-xr-xr-x 1 dinesh eng   6328 Aug 26  2004 missing
-r-xr-xr-- 1 dinesh eng    440 Aug 27  2004 build.sh
-r--r--r-- 1 dinesh eng    975 Apr  2  2015 Makefile.am
-r--r--r-- 1 dinesh eng   1153 Apr  2  2015 configure.ac
-r-xr-xr-- 1 dinesh eng    952 Apr  2  2015 autogen.sh
drwxrwxr-x 4 dinesh eng   4096 Nov 30  2016 Scripts
lrwxrwxrwx 1 dinesh eng     35 Dec  1  2016 ltmain.sh -> /usr/share/libtool/config/ltmain.sh
-rw-rw-r-- 1 dinesh eng   2801 Dec  1  2016 config.h.in
lrwxrwxrwx 1 dinesh eng     32 Dec  1  2016 depcomp -> /usr/share/automake-1.11/depcomp
drwxrwxr-x 7 dinesh eng   4096 Dec  1  2016 install
-rw-rw-r-- 1 dinesh eng  41966 Feb 14 00:30 aclocal.m4
drwxr-xr-x 2 dinesh eng     81 Feb 14 00:30 autom4te.cache
-rwxrwxr-x 1 dinesh eng 606261 Feb 14 00:30 configure
drwxrwxr-x 3 dinesh eng   4096 Feb 14 00:30 bin
drwxrwxr-x 3 dinesh eng     53 Feb 14 00:30 preinstall
drwxrwxr-x 4 dinesh eng   4096 Feb 14 00:30 share
drwxrwxr-x 7 dinesh eng     97 Feb 14 00:30 test
-rw-rw-r-- 1 dinesh eng  26776 Feb 14 00:30 Makefile.in
drwxrwxr-x 9 dinesh eng   4096 Feb 14 00:31 build
-rw-rw-r-- 1 dinesh eng     10 Feb 14 00:35 stamp-h.in
drwxrwxr-x 3 dinesh eng   4096 Feb 23 09:25 conf
drwxrwxr-x 2 dinesh eng   4096 Apr  3 01:34 SCCS
drwxrwxr-x 4 dinesh eng   4096 Apr  3 01:34 doc
drwxrwxr-x 5 dinesh eng  12288 Apr  3 01:48 lib
drwxrwxr-x 3 dinesh eng   4096 Apr  3 01:48 src
drwxrwxr-x 8 dinesh eng     79 Jun  9 02:58 BitKeeper

i want to select and delete all the junk information except for the name of the file in one shot from vim. How can I do it?

只需使用Ctrl-v选择该块,然后使用d将其删除。

With :help :normal and a simple normal mode command:

:%normal! d8W

Which means "on every line in the buffer, delete until the 8th WORD".

With a substitution:

:%s/^\(\S\+\s\+\)\{8}

Which means "substitute every sequence of height groups made of one or more non-whitespace characters followed by one or more white-space characters, starting from the beginning of the line".

Hey VIM support virtual block mode .

In which you have choice of columnar selection of data.

1: Open you file using vim , press Ctrl+v .

2: Select all columns you wanna delete and press d .

3: To save file and exit press :wq

输入以下命令:

:1,$s/.* //g

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM