Skip to main content
71 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.7k
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
24 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
  • 16.1k
22 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
  • 50.1k
21 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
  • 26.6k
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
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
18 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
  • 311
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
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

'<,'> 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
  • 32.2k
13 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 > ...
minseong's user avatar
  • 2,363
13 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.9k
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
  • 25k
11 votes

What does :%! mean?

From :help :%: % equal to 1,$ (the entire file) *:%* From :help :range!: :{range}![!]{filter} [!][arg] *:range!* Filter {range} lines through the external ...
Jair López's user avatar
  • 1,854
11 votes
Accepted

How do you make the command mode case insensitive?

You can dynamically toggle smartcase using autocmds, so when in a : command line, it is off and when in a / command line it is on: " assumes set ignorecase smartcase augroup dynamic_smartcase ...
Mass's user avatar
  • 14.2k
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,756
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,670
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
  • 50.1k
10 votes
Accepted

source the current file

:so % % refers the current buffer's filename. This works not just for :source, but for all of the commandline; see :help cmdline-special.
Naumann's user avatar
  • 2,759
10 votes
Accepted

How to navigate using vim keybindings in command line mode?

You can type q: to see command history and edit it like any other buffer. Press Enter on the line with the command you want to execute. p.s.: q/ works the same but for search history.
Neaţu Ovidiu Gabriel's user avatar
10 votes
Accepted

How to run multiple commands sequentially in nvim?

I guess the LspInstall user command is configured to take multiple parameters. No matter, you can use multiple -c flags, each with their own command(s). Specifically... You can use up to 10 "+&...
B Layer's user avatar
  • 20k
9 votes

How to split a line into multiple lines efficiently?

The easiest way I've found to split lines in Vim is the normal mode command gq (type both letters in quick succession in normal or visual mode). In visual mode, it will split whatever is selected, in ...
vdicarlo's user avatar
  • 123
9 votes

How to predefine the cursor position in command?

You can use that: nnoremap <key> :s//nextposition/g<c-b><right><right> The mapping will first go into command mode: : Then write s//nextposition/g in the command lines Go ...
statox's user avatar
  • 50.1k
9 votes
Accepted

selecting a range of lines from command line

The boundaries of a visual mode selection are defined by the < and > marks. Thus, the following command will enter visual mode with lines 5 through 10 (inclusive) selected: :5mark < | ...
Rich's user avatar
  • 32.2k
9 votes
Accepted

How to get the names of all open buffers?

I suppose by "open files" you mean active buffers (see :h windows-intro). That could be achieved with the command :ls a (use h-flag to get hidden buffers if needed). To pack it into a function you ...
Matt's user avatar
  • 20.9k
8 votes
Accepted

Access a file under subdirectories of a path through gf command

You can add ** to your path: set path+=** This way it will find every file recursively based on your current directory. But apparently it's not recommended. If you want to add other paths, you can ...
nobe4's user avatar
  • 16.1k
8 votes

Dump the output of internal vim command into buffer

For completeness, I want to present this awesome functions that I collected (stole) from romainl " redirect the output of a Vim or external command into a scratch buffer function! Redir(cmd) if ...
3N4N's user avatar
  • 5,774

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