Skip to main content
53 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
52 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.9k
24 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.5k
22 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
  • 27.7k
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
19 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
  • 321
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
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
  • 21.6k
13 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.6k
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.3k
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,789
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
  • 20.1k
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
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.6k
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
  • 21.6k
9 votes
Accepted

Can the command-line be edited/navigated using Vim commands?

Note: F is a key on your keyboard not the input "F" which would be Shift+F There's no inline, rich command-line editing within Vim in the way many might expect (i.e. like Bash command-line ...
B Layer's user avatar
  • 20.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,934
8 votes

When to use :grep and :vimgrep in vim?

One benefit of :[vim]grep over /? is that the results get put into the quickfix list (or location list if you use :l[vim]grep), this means that you can pull up a list of all matches using :cl. You can ...
icc97's user avatar
  • 603
8 votes

Easiest way to switch git branches

The fugitive Git checkout <branch> has a downside that it doesn't autocomplete the branch name. Using fzf.vim I've created this command: function! s:changebranch(branch) execute 'Git ...
kubek2k's user avatar
  • 181
8 votes
Accepted

Automate file reload after command that modifies it?

Your command tells pandoc to filter your file (%) instead of your buffer. This is problematic because there's no guarantee that the content of the buffer and the content of the file are identical. ...
romainl's user avatar
  • 42.3k
8 votes
Accepted

Pass word one-by-one and replace (Search and replace with confirmation)

I think you're looking for the substitute command with confirmation: :%s/word1/word2/gc This will substitute word2 for word1, but every time it will take you to the match and let you decide what to ...
Tumbler41's user avatar
  • 7,796
8 votes
Accepted

How to make command-line abbreviations that only trigger at begining of line

First and foremost, for most cases like this you'll want to use a command! instead of an abbreviation. This allows you to create a custom command-line command that will not mess up other inputs. ...
Tumbler41's user avatar
  • 7,796
8 votes
Accepted

Any recommendations to enforce use of keybindings rather than equivalent command mode commands?

You could try to add this code in your vimrc: let g:my_overlooked_commands = [ \ { 'old': 'vsplit', 'new': 'C-w v' }, \ { 'old': 'split', '...
user852573's user avatar
  • 1,023
8 votes

How to change word under cursor to upper case in command mode with shortcut?

Rather than make a mapping (particularly over top of the helpful <C-u> kill-line), I suggest the following: Open the command-line window. q: from normal mode, or <C-f> if already typing a ...
D. Ben Knoble's user avatar
  • 27.7k
7 votes
Accepted

Is there a way to use an ex command without moving the cursor?

I don't believe there is a way to run an ex command without moving the cursor, but there is a much more convenient way to get back to where you were. When you run an ex command, the current location ...
DJMcMayhem's user avatar
  • 17.9k
7 votes
Accepted

Strange behavior with "map(range ...)"

Looking at :h map: map({expr1}, {expr2}) map() {expr1} must be a List or a Dictionary. Replace each item in {expr1} with the result ...
muru's user avatar
  • 25.1k

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