67 votes
Accepted

Dump the output of internal vim command into buffer

You can use :redir to redirect the output to a variable, register, or file. Example of redirecting to the unnamed register: :redir @">|silent scriptnames|redir END|enew|put Alternatively Tim Pope'...
Peter Rincker's user avatar
51 votes
Accepted

Execute current buffer as bash script from vim

I wrote a pretty extensive answer about this over on stack-overflow. The basic idea is that since the write command is about writing not saving, you can write the text in your buffer into an external ...
DJMcMayhem's user avatar
  • 17.4k
48 votes
Accepted

How to go to previous open buffer from Vim command line?

The jumplist is not the best way to do buffer navigation. Vim has a great number of buffer navigation tools which are probably better used for this task. <c-^>/<c-6> - jump to the ...
Peter Rincker's user avatar
47 votes

Close and unload a buffer without exiting Vim

You can completely wipe out a buffer using the :bwipeout (or :bw) command. This completely removes the buffer from memory, including any marks, option settings, etc. that you have added to it. ...
Soylent17's user avatar
  • 571
32 votes

How can I easily move a line?

If I want to swap one line with the line above I usually do the following ddkP Explanation dd will delete the line and add it to the default register. k will move up a line (j would move down a ...
venkatvb's user avatar
  • 421
23 votes
Accepted

When to use :grep and :vimgrep in vim?

As the doc say: Vim has two ways to find matches for a pattern: Internal and external. In a nutshell, :vimgrep uses Vim's grep mechanism to read and find in files. :grep uses an external commands to ...
nobe4's user avatar
  • 15.9k
21 votes
Accepted

Is there a version of Vim or plugin with a Command Mode auto completion?

I really don't think that having autocompletion or not will help you learning how to use Vim. Your main problem in my opinion is to learn the basics of the editor and then learn more and more commands....
statox's user avatar
  • 49.4k
20 votes
Accepted

Can I search through 'oldfiles' with a specific name or extension?

Assuming you have Vim 8 you can use :filter :browse filter /pattern/ oldfiles For more help see: :h :browse :h :filter :h oldfiles :h new-items-8
Peter Rincker's user avatar
20 votes
Accepted

How do I use a variable or return value in option, command, or mapping?

The reason your example attempts don't work is that in many locations text is simply seen as a literal string, rather than VimScript. So functions, variables, and the like don't work. For example, if ...
D. Ben Knoble's user avatar
  • 25.3k
19 votes
Accepted

Easiest way to switch git branches

To summarize the answers, here are the ways to accomplish this: Vanilla Terminal Vim in a shell with job control Press CTRL-Z in normal mode will drop you back in to the shell and suspend Vim. After ...
Sukima's user avatar
  • 1,192
18 votes

How do I insert the output of an external command at the cursor position?

In normal mode press double !, then enter the command, or just type the following: :.!ls
Ruslan Osmanov's user avatar
17 votes

vim doesn't show the command that is being typed

This behaviour is controlled by the showcmd option. Try: :set showcmd and see if that brings it back.
joeytwiddle's user avatar
  • 3,592
17 votes
Accepted

What is the difference between :quit and :close commands?

Open Vim and enter :close. You'll get: E444: Cannot close last window And this is the difference. We can also see this in the source implementation (from ex_docmd.c): /* * ":quit": quit current ...
Martin Tournoij's user avatar
17 votes

How to go to previous open buffer from Vim command line?

You can also use ctrl + o to go to the previous jump list, which might be buffer, going backwards. You can keep pressing the same command to go to the previous, previous buffer/jump list. You can also ...
Kaka Ruto's user avatar
  • 301
16 votes
Accepted

How to delete a multi-line match?

The feasibility of deleting parts of lines is elusive and a better vimmer than I will have to explain that. If anyone cares to donate an explanation I'd be happy to add it to this answer. But it's ...
Peter Lewerin's user avatar
16 votes
Accepted

How do I run Homebrew vi on macOS instead of the older version Apple provided?

This is happening because the OS's vi is ahead of Homebrew vi in the PATH. While you could fix it by putting /usr/local/bin ahead of /usr/bin in the PATH, that would be a security hole since Homebrew ...
Warren Young's user avatar
15 votes
Accepted

How can I use Readline shortcuts in the vim command line?

Is there a plugin or setting which provides this? Yes, rsi.vim plugin: Features Readline mappings are provided in insert mode and command line mode. Normal mode is deliberately omitted. ...
mMontu's user avatar
  • 6,600
15 votes
Accepted

'<,'> in command prompt

Seeing '<,'> in the command line when you press : indicates that you currently have a visual range selected (e. g. with v, V, or Ctrl-v), and vim is helpfully prefixing the markers for '...
DopeGhoti's user avatar
  • 276
14 votes
Accepted

Switching arrow key mappings for wildmenu tab completion

You can do this by mapping the keys to behave differently when the wildmenu is visible: set wildcharm=<C-Z> cnoremap <expr> <up> wildmenumode() ? "\<left>" : "\<up>" ...
Rich's user avatar
  • 31.3k
13 votes

Easiest way to switch git branches

Use the vim-merginal plugin (fugitive extension). It offers interactive TUI for: Viewing the list of branches Checking out branches from that list Creating new branches Deleting branches Merging ...
adelarsq's user avatar
  • 594
12 votes

How to search for lines matching current line in vim

Especially for mapping purposes, I find using getline() more elegant than doing the yanking yourself. Calling getline() with a string '.' returns the line under the cursor. There are two good options ...
Sakari Cajanus's user avatar
12 votes
Accepted

What does :%! mean?

:%! command pipes the current file's contents to command's stdin, and replaces the file's contents with command's stdout. So, :%! sort is pretty much the same as (from a shell) cat file | sort > ...
theonlygusti's user avatar
  • 2,229
11 votes
Accepted

How to avoid to press ENTER twice, when compiling with :make inside Vim?

Vim displays the "Press ENTER" prompt when the number of lines printed in the command area is greater than the number of lines it has available. This is to ensure the user doesn't miss a message. The ...
joeytwiddle's user avatar
  • 3,592
11 votes
Accepted

Is there a way to paste text from a buffer into your command using just the keyboard?

Yep, just like in insert mode: Ctrl-R followed by the register name, or " for the default one (i.e. Ctrl-R "). See :h c_CTRL-R.
VanLaser's user avatar
  • 9,620
11 votes

How can I insert text from the command prompt?

Press CtrlF (or in normal mode, press q:): OPEN c_CTRL-F q: q/ q? There are two ways to open the command-line window: 1. From Command-line mode, use the key ...
muru's user avatar
  • 24.7k
11 votes

Enable incremental search and highlight while typing a search term?

This is done by setting just two options: set is hls (incremental search and highlight all matches). Make sure you've also read the appropriate help topics, excerpted below: :h 'is' While typing a ...
Matt's user avatar
  • 20.4k
10 votes
Accepted

vim doesn't show the command that is being typed

Add this line into you .vimrc , either source it or restart vim. set showcmd And yes If you are experimenting with your vimrc and tired of sourcing it after every change, add this line. autocmd ...
dsyed's user avatar
  • 216
10 votes
Accepted

cnoremap and the <esc> key

I don't know why <esc> doesn't work, but you can use <C-c>. I.e.: cnoremap $ <C-c> Edit: Found the reason for this behavior in :h c_<Esc>: In macros or when 'x' present ...
Tumbler41's user avatar
  • 7,706
10 votes
Accepted

How can I insert text from the command prompt?

In addition to the CtrlF, which provides complete navigation on the command history, you could use CtrlR+: in insert mode (faster but works only for the latest command): CTRL-R {0-9a-z"%#*+:.-=} ...
mMontu's user avatar
  • 6,600
10 votes
Accepted

Difference between full and short command

There is no actual difference but in :h usr_20.txt, you can read: It is recommended that in Vim scripts you write the full command name. That makes it easier to read back when you make later ...
statox's user avatar
  • 49.4k

Only top scored, non community-wiki answers of a minimum length are eligible