Questions tagged [normal-mode]

Command mode is the initial mode. Vim calls this Normal mode. Not to be confused with command-line-mode, which is what you get after you press :, /, ?, or !

Filter by
Sorted by
Tagged with
32
votes
2answers
2k views

Can I see the history of key presses in normal mode?

I know that Vim keeps history for ex commands, searches, jump locations, changes, and possibly others. With showcmd set, Vim also shows you what keys you have entered so far for a normal mode command,...
20
votes
4answers
2k views

Simplest way to delete a “composite” word?

Apologies if "composite" is not the technical term. I mean the following: Hi, I-am-a-composite-word and we are not I would like to delete only the composite word. In command mode, if I move the ...
18
votes
4answers
2k views

How I apply a command to all lines?

If I want to indent all lines in a document, I can type >G to apply it to the current line and below, followed by and >gg to apply it to the lines above. Is there a combination I can use to ...
18
votes
1answer
2k views

How can I map d[count]d?

N.B. This is not a duplicate of How does the "d3fg" command work? Please read it before voting to close! I've come to a bit of an impasse in my quest to get small deletions work like big ...
17
votes
9answers
10k views

How to insert a newline without leaving normal mode

I wonder if I can insert a new line without leaving normal mode. For example, I have two lines: this is line one this is line two And the cursor is on line one. Now I want a new line between line ...
13
votes
1answer
6k views

How to use a variable in the expression of a 'normal' command?

How can one use a variable when executing something via normal! in vimscript? Example: function! MyFunction(someArg) normal! (a:someArg)l endfunction This should move the cursor someArg steps ...
12
votes
7answers
2k views

Can vim automatically turn off Capslock when returning to normal mode?

After almost every time I type something in caps, I forget to turn off capslock when returning to normal mode. I then try to move the cursor and end up joining a bunch of lines and a lot of other ...
11
votes
1answer
513 views

How do I shift the line indent to a specific value?

Many times I run across a situation where a line is not indented properly. Ether through a paste, bad / not preferred indent plugin, or most often extra spaces offsetting the indent value. I usually ...
10
votes
6answers
4k views

How to delete line above/below cursor, but not current line?

Is there a command for deleting line (or n lines) above current one? Above = current not included. I.e., is there an alternative to dk which doesn't delete current line? Similar to how o/O and p/P ...
10
votes
2answers
764 views

What is the mnemonic for Ctrl-Y (in normal mode)?

I know "expose one more line" for Ctrl-E, but why use Ctrl-Y to expose one more line at the top? Is there an easy mnemonic for this that I'm missing?
10
votes
2answers
491 views

How do I flip characters or words like emacs' transpose?

On bash's readline in emacs mode, I recently discovered the transpose functionality, giving me the opportunity to quickly fix a typo like dc dir to cd dir by pressing CTRL+T on the c character. ...
10
votes
1answer
1k views

Is there a way to insert a single character and then exit insert mode?

When I'm going through text and, for instance, adding backticks around certain words or quotes or whatever, it is irritating that I have to press Esc or Ctrl-[ after each insert. The inserts (and ...
10
votes
1answer
2k views

Hand Placement for Vim Navigation

I'm a new Vim user, and I want to ask this somewhat elementary question in order to make sure I start learning Vim the right way and don't develop bad habits. When you use Vim, how do you position ...
10
votes
2answers
283 views

Scrolling issues when the `wrap` option is set

I find myself dealing with this issue every time the wrap option is active (in my particular case whenever I'm working with markdown files). What happens is that, while scrolling up and down the ...
9
votes
4answers
2k views

How to delete content backwards until “=” at the previous line?

I use an example of javascript code: 1 var a = 1; 2 var b = |{}; The cursor is at the position of |( on the character "{" when the cursor shape is block), I find out that I want a ...
9
votes
4answers
464 views

How to replace text inside () with previously yanked text?

Assume I have the text Fnord yanked before and that my cursor resides on the B of the line: M:mock(Baz) How can I change the text inside () with the previously yanked text? Currently, I often make ...
9
votes
2answers
4k views

How to execute a command on vim startup

I just installed a plugin for python which displays methods tree. So I would like to open the tree on startup, so not necessary to push the buttons everytime I open some .py file. But, I want this ...
9
votes
2answers
3k views

Go to last non-whitespace character of previous/next line?

I like the - and <C-M> normal-mode keys for going to the first non-whitespace character of the previous/next line. Are there coresponding keys for going to the last non-whitespace character on ...
9
votes
1answer
571 views

Understanding line reference differences through :g/^/norm and through :%norm

Let's say that I have the following very simple file a b c d e and I've decided that I want to add empty lines after each line. Several different methods immediately jump to my mind. We might just ...
9
votes
1answer
341 views

use case for `gs`

according to documentation for gs: go to sleep for N seconds (default 1) Thus you can put Vim to sleep for 10 seconds using 10gs. What is a good use case for this command?
9
votes
1answer
131 views

Use backspace to modify the current command in normal mode?

Sometimes when entering a command in normal mode you may make a typo, for example if I intend to type 10dk, I might accidentally start typing 19d. Since the command has not been completed/committed ...
9
votes
1answer
150 views

How can I prevent (or at least prompt to confirm) absurdly large numbers from being used to prefix commands?

It doesn't happen as often as you'd think, but it happens occasionally, and I don't even own a cat. Basically if you mash the number row or numpad and then happen to hit a keycombo that triggers a ...
8
votes
4answers
1k views

Grok Vim motions and simple edits

I'm returning to Vim after using Emacs for a few years. I'm trying to grok Vim by reading and watching tutorials, as well as actually using it daily. When editing text, I find the Emacs commands of ...
8
votes
3answers
797 views

How to delete till the end of the previous line?

An example (The ^ is the cursor position): Before: a bc def ghi j k l mn o p q rs ^ After: a bc def ghimn o p q rs ^ or at least: a bc def ghimn o p q rs ^ I know I ...
8
votes
2answers
449 views

Set line numbers only while in normal mode

I don't have much use for line numbers while in insert mode so I would like to turn them off. However they are great for normal mode. Constantly using set nu! is tiresome. Is there a way to tie set ...
8
votes
1answer
164 views

Is it possible to make a numerically-prefixed hotkey run a function that many times?

I find that if you enter a numeric prefix prior to executing an ex command, the convention that it applies is to set up the command to prep an operation across a line range. It is explained in the ...
8
votes
1answer
2k views

Vim normal and insert mode cursor not changing in GNU screen

I use vim in a few different contexts; typically, I like to put this in my .vimrc: let &t_ti.="\<Esc>[1 q" let &t_SI.="\<Esc>[5 q" let &t_EI.="\<Esc>[1 q" let &t_te.=...
7
votes
3answers
310 views

Append bash output to vim buffer

We can execute bash command from vim like this: :! shuf -i1-123124 -n1 which generates random number in the given range. Is there a way to append the output to vim buffer?
7
votes
1answer
405 views

Continue an ex mode command after “norm”?

I often use extremely long macros when handling repetitive editing and refactoring. Whenever possible I write these as ex-mode commands rather than recording them as macros, because they are easier ...
7
votes
1answer
722 views

What is the meaning of 'g'?

Note: this question has two sort of answers on StackOverflow but I thought perhaps a better answer would come from here, and, if not, at least it will be documented where it should be: What are the ...
6
votes
3answers
633 views

Splitting a line into two

We can make from two lines a single with J. It looks as the following: line 1 line 2 after J pressed on line 1 we've got this: line 1 line 2 But is there a combination which what do the opposite (...
6
votes
1answer
634 views

Delete to EOL without entering insert mode

I have a file that looks like this: Bunch of text trailing... Bunch of text trailing... Bunch of text trailing... Bunch of text trailing... Bunch of text trailing... I can ...
6
votes
1answer
13k views

Execute normal command over range

For a file looking like this: 2 AD,42.546245,1.601554,Andorra,376 3 AE,23.424076,53.847818,United Arab Emirates,971 4 AF,33.93911,67.709953,Afghanistan,93 5 AG,17.060816,-61.796428,...
6
votes
1answer
128 views

How to keep in the undo history just one change for this command?

I want to keep in the undo history just one change for a long command such as: d0kJx. (I took the command from this answer.) This command (d0kJx) does this (The ^ is the cursor position): Before: a ...
6
votes
3answers
663 views

How can I delete a function call, leaving its inner content intact?

Let's say I have a line like this: a = x(y(z)); And I want to change it to: a = y(z); What's the most efficient way to do this?
6
votes
1answer
2k views

How to repeat last action with movement?

Assume the content: foo fnord bar;" >> /tmp/foo/derp gnarf foo fnord bar;" >> /tmp/foo/derp I want to jump to the " and delete to end of line and repeat that over the rest of lines. Yet ...
6
votes
1answer
2k views

Define word boundaries

I use, e.g., dw to delete a word based on word boundaries defined by changing character classes, so that this command applied on abc,def,ghi will result in ,def,ghi. (So far so good, and it worked for ...
6
votes
3answers
290 views

Is it possible to execute a Normal mode command only on the first/last line of a range?

I want to comment out a piece of code. For instance this snippet: foo bar foo Should become this: <!--foo bar foo--> So I type the following sequence: vap:norm '<i<!--<C-v><...
6
votes
1answer
758 views

How can I repeat last Ex-mode command in normal mode?

I'm looking for something like . or @@ that will work in normal mode for repeating the last Ex-mode command. As per the rule of the XY problem, I'll also state the broader goal: I have a fancy regex ...
6
votes
2answers
108 views

How can I undo an entire command (e.g. d4b), including the motions?

Say I do d4b, then realize I only needed d3b. If I hit u, it'll only undo the d part, and I'll still be 4 words back as if I just did 4b. I'd like to end up exactly where I was before I executed d4b. ...
6
votes
1answer
588 views

Hardcore vim mode: what is the best way to move vertically? [duplicate]

This question has been migrated from here I have started using vim a while back and have been jumping with my right hand on and off "home row". As I learned more about efficient navigation, using "f,...
5
votes
2answers
449 views

Move to non-existing Nth column

I have some 30 characters in a line. When I press 80|, it should move 50 character to the right, thus move the cursor to 80th character. (30, 50, 80 are for examples) How to achieve this using ...
5
votes
2answers
431 views

Substitution with math goes wrong

I have a large xhtml document that is broken into some 245 long paragraphs, each with a unique id in the form of "ud###" <p class="windowbg" id="ud000"> <!--- lots of content ---> </...
5
votes
4answers
175 views

Delete with search motion in normal command

I am attempting to delete from start of line until string foo. In normal mode, 0d/foo accomplishes this. Now, I would like to do this for every line in my buffer. Reading documentation and SO it ...
5
votes
2answers
2k views

Math calculations in vim?

I saw someone insert the result of an equation in vim, but I don't remember how it was done. For example say I want to insert the result of 7*7? How do I insert the results of an equation?
5
votes
2answers
2k views

Vim jump between words and stop at end of line

In normal mode, b and w are jumping between words, and I would like to stop at the end of line. For example: The cursor is right over here When I press w, what I expect is Instead, the cursor ...
5
votes
2answers
121 views

Change text between two $ symbols

If there is some text between quotations, such as "x = 5" I can type ci" in normal mode to delete the text inside the quotations and switch to insert mode. I often want to perform this same action ...
5
votes
1answer
1k views

Add tab in front of each line

I'm working with python code. After some modifications, I want to update the identation but obviously, select everything and press '=' doesn't work, python being python. So, is there any other way to ...
4
votes
3answers
185 views

Reverse a set of paragraphs

Is there a good way to reverse a set of paragraphs (navigable via cursor motion { and })? My practical use case is reversing the order of blocks of latex code (ie, reversing the order of jobs in a ...
4
votes
1answer
209 views

return to normal mode when the window loses focus

Is it possible to make Vim automatically exit whatever mode it's in and return to normal mode when the terminal window loses focus?