Some basic Vim commands

28 views
Skip to first unread message

Julius Hamilton

unread,
Apr 17, 2021, 10:48:07 AM4/17/21
to vim...@googlegroups.com
I was curious:

I can jump to the beginning of some text on a line that begins with whitespace with v, w, h, d. Is there a single command to delete all initial whitespace on a line?

I then wanted to jump over a few words to the next number (in brackets). Is there any command to the effect of "find the next number"?

Then I wanted to say: take this word and the next two words, and send them down 3 newlines. Would there be a way to do that?

Thanks very much,
Julius                                                              

Tony Mechelynck

unread,
Apr 17, 2021, 11:45:56 AM4/17/21
to vim_use
To go to he first nonblank on the current line: ^
To go to the first charcter of any kind on the current line: 0
To jump to the next v w h or d at the start of a word: /\<[vwhd]
To delete all initial whitespace on the current line: :s/^\s*//
To delete all final whitespace on all lines: :%s/\s*$//
To go to the next digit: /\d
To go to the next digit immediately after an opening bracket: /(\zs\d

You may want to study the following helpfiles for explanations about
the above and about other similar questions:
:help pattern.txt
:help motion.txt

Best regards,
Tony.

Eli the Bearded

unread,
Apr 17, 2021, 2:15:38 PM4/17/21
to vim...@googlegroups.com
Julius Hamilton <julk...@gmail.com> wrote:
> I can jump to the beginning of some text on a line that begins with
> whitespace with v, w, h, d. Is there a single command to delete all initial
> whitespace on a line?

I'd typically do that in either of two ways:

: {range} s/^[ TAB]*//

With a {range} like ".", ".+2", "1,.", ".,$" or "'a,'e" (my standard
begin and end range marks).

Or without using ex mode commands "^" to jumpt to first non-whitespace on
the line and then "d0" to delete to first column.

> I then wanted to jump over a few words to the next number (in brackets). Is
> there any command to the effect of "find the next number"?

Save search pattern then use next:

/[0-9]/
n

> Then I wanted to say: take this word and the next two words, and send them
> down 3 newlines. Would there be a way to do that?

I'm unclear in particular what this is asking for. Maybe "d3w3jp" ?

Elijah

Romain Lafourcade

unread,
Apr 18, 2021, 4:42:33 AM4/18/21
to vim_use
> Is there a single command to delete all initial whitespace on a line?

    :left<CR>

> Is there any command to the effect of "find the next number"?

    /\d<CR>

> take this word and the next two words, and send them down 3 newlines.

This one is unclear. Do you want to create a new line with just those two words? Do you want to insert them in an existing line? Etc. 

c.willis111

unread,
Apr 18, 2021, 7:33:54 AM4/18/21
to vim...@googlegroups.com
--
/\d<CR> is fine for finding a number if it is being done by the operator. Not so clever as part of a function - unless it is clear that you are starting outside a number. In particular not between the mantissa and exponent of a floating point number in scientific notation. Also what about numbers that start with a minus sign or a decimal point? The latter wd seem to be managed with /[.-]*\d<CR> (unless I've been caught out by vim's strange escape strategy).


Chris W

Tony Mechelynck

unread,
Apr 18, 2021, 8:38:41 AM4/18/21
to vim_use
Hm, in Vim syntax a number can optionally start with a single plus or
minus sign; for an integer all the rest must be digits. A
floating-point number can in addition have a single dot (decimal
point) followed by one or more digits, and then optionally e or E
followed by one or more digits. At script version 2 or higher the
decimal point need not be preceded by any digits. All this is rather
complex, I suppose it can be done, but only by means of a function
(which can start searching with /[-+[:digit:]] and then repeat if what
was found was not a "proper" number). Tricky. If different search
rules must be applied for different programming languages or texts it
becomes even more tricky.

Best regards,
Tony.

Tony Mechelynck

unread,
Apr 18, 2021, 9:32:59 AM4/18/21
to vim_use
P.S. And if the text where the number is found can be in any language,
we must be able to account for the option which is set in COBOL by the
phrase DECIMAL-POINT IS COMMA in the ENVIRONMENT DIVISION, and then if
it can /actually/ be in any language we must account for natural
integers using all of Greek (decimal without zero using lowercase
alphabetic and two kinds of apostrophes), Hebrew (decimal without zero
using Hebrew letters, and possibly with several letters for a higher
hundred), Western Arabic-Indic, Eastern Arabic-Indic, Devanagari (and
possibly other Brahmic) and CJK hanzi/kanji/hanja conventions. That
would make it _really_ complicated. (Both Arabic-Indic and Brahmic
including Devanagari write their natural integers like we do, only
with different sets of ten digits.) (And I have knowingly skipped
Roman numbers with or without the possibility to have an ending i
written as j, Greek acrophonic aka Attic, Maya, Cuneiform and more.
:-P )

Best regards,
Tony.

c.willis111

unread,
Apr 18, 2021, 10:30:56 AM4/18/21
to vim...@googlegroups.com


------ Original Message ------
From: "Tony Mechelynck" <antoine.m...@gmail.com>
To: "vim_use" <vim...@googlegroups.com>
Sent: Sunday, 18 Apr, 2021 At 14:32
Subject: Re: Some basic Vim commands

--
Hi Tony

thanks. What fun!

regards - Chris --
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtCMzycxbZDCoPx9O%2BbLCkm2SmOkmMxjsSOOTH4gt_bTA%40mail.gmail.com.

Julius Hamilton

unread,
Apr 19, 2021, 9:34:00 AM4/19/21
to vim...@googlegroups.com
Thanks very much. I plan on reading through this soon, when I have the time.

I was also curious, I created a split screen with CTRL-W s. But in the lower screen, if I'd like a terminal running there, when I type :sh, the entire Vim application exits, including the top screen.

Would there be any way to have a terminal in the lower screen, and Vim on the top?

Thanks very much,
Julius



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/2f28e3cc.1e60a.178e564221d.Webtop.108%40btinternet.com.

Marc Weber

unread,
Apr 19, 2021, 9:59:28 AM4/19/21
to vim...@googlegroups.com
:sh des start a shell, if you quit it you should be back i vim.

There are various plugins/ extensions  which provide a window with a terminal if you need to keep something running.

https://neovim.io/doc/user/nvim_terminal_emulator.html

:h terminal.txt (?)


Alternatives  :!cmd  or ctrl-z then command fg or use screen and have 2 windows  or various old solutions which try

to provide :h terminal like features but as script code which might work only most of the time.


Marc Weber

Julius Hamilton

unread,
Apr 19, 2021, 4:12:05 PM4/19/21
to vim...@googlegroups.com
Thanks very much.

I had some success with Tmux, actually.

Is there any way to have tabs inside of a split window? I currently have tabs one layer above a split, so if I switch tabs, the split is gone and a single buffer fills the screen.

Thanks very much,
Julius

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

Gary Johnson

unread,
Apr 19, 2021, 4:27:10 PM4/19/21
to vim...@googlegroups.com
On 2021-04-19, Julius Hamilton wrote:

> Is there any way to have tabs inside of a split window? I currently have tabs
> one layer above a split, so if I switch tabs, the split is gone and a single
> buffer fills the screen.

No. A tab contains one or more windows; windows cannot contain
tabs. See:

:help windows-intro
:help tab-page-intro

Regards,
Gary

Jürgen Krämer

unread,
Apr 20, 2021, 1:45:29 AM4/20/21
to vim...@googlegroups.com
Hi,

Julius Hamilton schrieb am 19.04.2021 um 15:33:
> Thanks very much. I plan on reading through this soon, when I have the time.
>
> I was also curious, I created a split screen with CTRL-W s. But in the lower screen, if I'd like a terminal running there, when I type :sh, the entire Vim application exits, including the top screen.
>
> Would there be any way to have a terminal in the lower screen, and Vim on the top?

have you tried

:term

?

Regards,
Jürgen

Reply all
Reply to author
Forward
0 new messages