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
1
vote
1answer
35 views

How to jump back to current location after using key-binding `noremap <Leader>bA gg"*yG` without appending `<C-o><C-o>`?

I have created the following key-binding for copying all text in the buffer to the system clipboard: nnoremap <Leader>bA gg"*yG However, it moves the cursor, so I need to append <C-o>&...
2
votes
1answer
57 views

Search and yank in visual line mode with execute normal

I have this in a buffer: aaa bbb ccc ddd eee with the cursor on the first line. I do :execute 'normal! jV/ddd\<CR>y' which I expect should result in the middle three lines yanked. But what ...
1
vote
1answer
44 views

Is it possible to document or add comments to a scriptin file?

I have a lengthy scriptin that I'm using to help me convert JavaScript files to Typescript. There are about 30 commands defined in it so far: :%s/^\(\s*\)params\.\(\S\+\) = \(.*\);/\1 \2: \3,/ :g/...
0
votes
1answer
28 views

Record the mode before pressing <c-\><c-n> in terminal

I want to restore the pos of cursor in terminal when I reopen the terminal: If the mode was terminal mode before, it is easy to feed a 'a' to terminal to change from normal mode to terminal mode. If ...
2
votes
2answers
40 views

Delete the content and the brackets of a level above while inside in the inner level

My cursor is at H { //foo { //bar { //cursor is Here } //bar2 } } How do I delete the outer layer of brackets while keeping the layer where my cursor is intact? End result ...
0
votes
1answer
27 views

Keep open fold open on `o`

I have a file with foldmethod=indent. I have the folds automatically open when I enter them, and close when I leave them. When I sit in Normal mode on the bottom line of a fold and press o, the fold ...
1
vote
3answers
107 views

How can I delete whitespace backwards until end of previous word?

I want to delete whitespace backwards until end of previous word. Say, I have the cursor on the character "d" in the word "dog": horse cat dog If I press Ctrl-W (Insert ...
3
votes
1answer
107 views

How to toggle syntax with a single key

To turn on syntax we normally use: :syntax on and to turn it off we do: :syntax off. I would like to define a single key, maybe using <expr> to toggle syntax. My problem is how to get the ...
0
votes
1answer
24 views

Join values by keys

I would like to use VIM to group a file by keys (e.g. "asian") and join the associated values. The keys are already sorted. Example: asian <==> asiat asian <==> asiatisk asiatic <==&...
1
vote
1answer
43 views

Yank inside quotes of a range of lines to a register and separate them with a new line character

I would like to populate a register with the text inside quotes for a range of lines. The register should contain all yanked text separated with new line characters. Example lines: The "black" cat A "...
0
votes
0answers
29 views

<number>dd not doing anything on an ubuntu machine

I use 999dd as a goto command before pasting/overwriting the entire contents from the clipboard. For some reason this is not working (at all) on a specific ubuntu machine. Why would this not work be ...
-1
votes
1answer
49 views

In Vim, Save in normal mode

I am trying to improve my skill with vim. And I know ESC : w for to save. But in normal mode the shortcut for w is for "to the next word". is there another key for to save quickly? or I need ...
1
vote
0answers
38 views

How to repeat `f <char>` in opposite direction when using `,` as the map leader?

I have set mapleader="," in my ~/.vimrc. How can I continue to repeat f <char> in the opposite direction, when using , as the map leader? Is it possible to remap , in the context of f &...
3
votes
1answer
56 views

Does “:norm! @q” use mapped keys inside the macro?

The documentation for :norm[al][!] states that "mappings will not be used" when the ! is written. Consider the following setup commands: :nnoremap \c Chello<esc> :let @q = '\cIthis is ...
0
votes
5answers
113 views

I keep forgetting which mode I'm in

My main problem is that I don't realize which mode I am in each time I use vim. Sometimes I forget to <ESC> into normal mode, hence pressing vim commands in insert mode. I have to waste time ...
4
votes
1answer
93 views

How to map `/` to `/\v` in Normal mode without moving the cursor?

I've created the following simple mapping in Normal mode, since I don't want to enter \v for "very magic" regex parsing, every time I use the / search command: nnoremap / /\v However, after ...
15
votes
2answers
10k 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 ...
2
votes
3answers
194 views

Execute command for multiple files

I find myself often in the situation in which I want to run multiple vim commands on a multiple files. Consider file1.txt, file2.txt, file3.txt I would need to run :retab and then some :%s/ /, / for ...
4
votes
2answers
50 views

How can I use `ci'` to change the N'th occurrence of single-quoted text in a line?

I find the ci' (and similar commands) very useful, since I can execute it at the start of the line, and it will automatically change the first occurrence of text between single quotes ('...'). However,...
1
vote
0answers
18 views

How to prevent `autocmd` for stripping trailing whitespace for moving the cursor? [duplicate]

I've the following autocmd for stripping trailing whitespace in a buffer, every time the buffer is written to a file: " trim whitespace autocmd BufWritePre * %s/\s\+$//e However, the autocmd has ...
0
votes
0answers
18 views

Why does disabling arrow keys in Insert mode (e.g. `inoremap <left> <nop>`) result in e.g. `0D` being written? [duplicate]

I want to disable the arrow keys in Insert mode, since I want to force myself to always go into Normal mode for performing movements. To achive this, I've made the following mappings for Insert mode, ...
4
votes
1answer
70 views

Break the undo sequence in normal mode

Question: Is there something which is works same as i_CTRL-G_u, but for normal mode? This would be useful in mappings (like nnoremap), because (I think, but fixme) in normal mode, if you are just ...
2
votes
3answers
71 views

How do vim users type/edit while switching between modes?

I'm not talking about learning or introducing commands, but how to work by switching between modes, and using normal known commands. Do most vim users stay more in normal mode instead of in insert ...
1
vote
1answer
18 views

Unable to execute a substitute regex from inside a function

I have this function: function! Insert_article() execute "normal! :r !insert_article.pl\<cr>" execute "normal! :%s/\v^(#+\s+[^\n#]+)\n([^#]*#+)/\1 \2/g\<cr>" ...
1
vote
2answers
54 views

How can I make external command use current line as input and append output to end of same line?

Using Vim 8.0 I'm trying to make a table where the first column is the name of a file and the second column the creation date of such file, to which I have access by the exif data. I would like to ...
39
votes
11answers
40k 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 ...
1
vote
1answer
22 views

How to map a keybinding to a command which includes <C-U> (scroll-up) in my .vimrc?

I want to map a keybinding to a command which includes <C-U> not for clearing the command line but for scrolling the page up. Executing a command like this in my vim session works totally fine: :...
1
vote
1answer
58 views

Is it possible to view a history of commands (per mode) executed in Vim?

I sometimes execute commands in Vim by mistake, either in normal-, visual-, or ex-mode and have no idea what was executed. Is it possible to see a history of executed command per mode in Vim? I know ...
1
vote
2answers
63 views

Check pending command state

Is it possible to check if a normal mapping/command is being typed? That's also when the showcmd setting takes effect. I can't seem to find anything about this in the doc, no autocmd-event nor related ...
1
vote
1answer
29 views

Typing d in insert mode briefly moves cursor backwards

In Vim, when I'm in Insert mode and hit d, the cursor moves back one spot for a second, then jumps back to behind the letter just typed. This is quite distracting when typing texts. It looks like Vim ...
7
votes
4answers
2k 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 (...
0
votes
0answers
22 views

cursor moves in range

I have this function that gets range. From the help: The cursor is still moved to the first line of the range, as is the case with all Ex commands. Can it not do it? I just want to ...
2
votes
2answers
2k views

Remapping tab key to autocomplete in commandline mode in Vim

I am using Vim 7.4 and I wish to map the tab key so I can use new combinations to autocomplete arguments in command mode from the current directory Contents of current directory: Funwithstrings.cs ...
2
votes
0answers
47 views

how to have two different colour schemes for command mode and edit mode in vim?

I have been using vim for some time now but I am always unsure of which mode I am currently in and hence end up pressing Esc too often even in the command mode. This causes an irritating computer ...
0
votes
2answers
48 views

Why do I have to press the caret button twice to go to the beginning of the line?

When I press the caret button in normal mode, vim first prints a caret at the cursor position. Only with the second press of the caret button does the cursor actually move to the beginning of the line....
2
votes
1answer
48 views

Put cursor at arbitrary line and column

Normal, insert, and visual modes restrict cursor movements to locations occupied by some characters. They don't allow moving to the right from the end of line and down beyond end of file. For example:...
2
votes
1answer
64 views

execute + colon character doesn't work

I want to :retab selection in my vimscript function. When I write execute "normal! :'<,'>retab" nothing happens. If I write: let cmd = "normal! :'<,'>retab" echom cmd The output is ...
1
vote
1answer
37 views

How can I use the `:term` command without closing the current window on exit?

I often use the :term command in my projects to create new directories or perform other work. However, if I have multiple windows open, then executing :term from one of them will also close that ...
1
vote
2answers
2k views

key mapping <C-'> (Ctrl single quote) not working

I have this line in my .vimrc nnoremap <C-'> :marks<CR> and want to use Ctrl-' to show all marks. Sadly, it never works, be it on ubuntu, cygwin, or windows 10. After vim 8.0 was ...
7
votes
2answers
3k 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 ...
1
vote
1answer
19 views

Overwrite text object with single char

I'm looking for a way to replace the text print("This is a test") by print("**************") i.e. i want to overwrite every character of a text object (the string inside quotes) or up to a ...
0
votes
1answer
59 views

Simulate backspace in normal mode

I would like to have the delete key work similarly in normal mode as it does in insert mode, and it's been a bit tricky to map this. Here is what I have so far: :nnoremap <Backspace> i<BS>...
16
votes
3answers
2k views

Change an entire line in Vim

Is there a way to delete a full line and start with an insert? Normally I would do: 0 (go to start of line) C (delete to end of line and start insert) But is there a command to do the above without ...
2
votes
0answers
15 views

How to disable mouse scroll wheel when in normal mode?

I want to completely disable the mouse but mouse scrolling in normal mode is not disabled. I have disabled other mouse function but scrolling in normal mode is still on. To disable the mouse I have ...
0
votes
2answers
39 views

Cursor difference with “Esc” and “Ctrl + O”

Say I have a session like this: Sunday|Monday Where | is the cursor in insert mode. If I press Esc, I get this: Sunda█Monday but I want this: Sunday█onday As I want to select the second "word", ...
0
votes
2answers
23 views

Visual mode word behaves differently than in normal mode?

Say I have the text: This is a test! If my cursor is on the first character, "T", and then I do d4w, then I am left with just !. However, if instead I do v4wd then I'm left with nothing (i.e. the ...
1
vote
1answer
54 views

Why doesn't inoremap work in this case

I'm coding c++ with vim and I want to set a shortcut while typing parenthesis and new line. Here is an example, if (a == 1) {}| // the cursor is at the end of the line and the vim is under INSERT ...
2
votes
0answers
13 views

vim command mode g++ doesn't pick the bash alias [duplicate]

I have g++ alias defined in my .bashrc file as alias g++='g++ -Wall -DLOCAL=1' I am invoking following command from vim command/normal mode to compile a program - !g++ % The issue is, this ...
0
votes
0answers
68 views

Remove command echo in status bar

I've noticed that sometimes in ViM the status bar shows me the command I've just executed (for instance, if I keep the key 'l' pressed to keep going right, I see at the bottom right of the screen a ...
0
votes
1answer
62 views

Automatic insert mode and normal mode switching

Coming from emacs, jumping to the end of the line is easy: CTRL + E I have been recently trying out Vim, and I found out you need to first exit insert mode to then use commands. So, in Vim, I need ...

1
2 3 4 5