Questions tagged [command-line]

Questions on ex- or colon-commands. For questions about command-line options used to launch the editor, use the [invocation] tag.

Filter by
Sorted by
Tagged with
32 votes
8 answers
25k views

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

I am trying to write a Vim function which should make the window go to the previous open buffer. How can I do it from the command line? My first idea was to find out some Ctrl-O command line ...
-1 votes
0 answers
34 views

How do I align columns in a CSV file?

I'm using this csv plugin to view my csv file. I use command :67,68ArrangeColumn to align my file, but it does not align well. The manual mentions a command like :[range]ArrangeColumn[!] [<Row>]...
1 vote
1 answer
63 views

How can I echo a variable and redirect it to a file, register or the clipboard?

I'm using a colour scheme which makes some text unreadable in the vim terminal. Therefore I want to alter g:terminal_ansi_colors. :echo g:terminal_ansi_colors This shows me the value of the variable, ...
2 votes
1 answer
102 views

Vim command-line just say 'saved' upon save

In Vim, at the the bottom. There is statusline. And below it there is, I think, the command line. When I press save, this command line, displays something like: "index" 160 lines, 2097 ...
1 vote
1 answer
128 views

Vim command-line mode encoding error when using global search in autocmd

Update Found the issue due to souce the menu this cause encoding=utf-8 and fileencoding=cp936 in _vimrc but in txt files it shows encoding=utf-8 fileencoding=utf-8 The way to fix is reset fenc=utf-8 ...
-2 votes
1 answer
55 views

MacVim: how to prevent :[range]!say to remove text? [duplicate]

I am writing some prose and I find very useful to hear what I wrote from an external voice. I found the command say which I guess is only available on MacOsX (perhaps other OS have some equivalent). ...
1 vote
1 answer
79 views

Put the mutiple search or replace results into different split window

Dsecription I am using :g/regex to do global search and it always list --More-- So I need to click Enter or Space to see the full results, it takes too much time. I found one way to achieve my goal ...
1 vote
1 answer
49 views

How to save the files when global replace completed in one command line

I have so many huge size of files and always need to do search and replacement so I map the command as nnoremap aa :let i=1 \| g/regexp/ s/^/\=printf("%1d. ",i)/g \|let i =i+1\|:w! 1.txt ...
11 votes
6 answers
30k views

How do I copy and paste between two Vim instances - shared clipboard?

I use gnu screen and I run vim file1.txt and vim file2.txt in two windows. How can I copy part of the text from file1.txt and paste it to file2.txt without using temporary files or opening two files ...
1 vote
1 answer
257 views

How to pass custom arguments to the shell invoked by :terminal?

I would like to specify the startup command to run on the :terminal shell. E.g. bash -c ls. The shell can be specified with set shell=bash, but how to specify the arguments? In another use case, I ...
0 votes
1 answer
117 views

How to delete all lines in a command script without provoking error?

I'm trying to write a Vim command script (a file containing Ex commands) that removes all existing lines in a file (and then read in some new text, and do some further editing operations). I use the ...
4 votes
1 answer
103 views

How to get autocomplete for :set?

E.g. I am trying to change foldmethod to syntax: :set foldmethod=s^I^I When I press tab after typing s, I get ^I instead of auto-completing to syntax. Only possible options are manual,indent,expr,...
11 votes
3 answers
191 views

Auto completion for option values on the cmdline

I cannot count the number of times I have tried to do this: :set foldmethod=syn^I It seems that completion doesn't work on option values! In some cases options are complex strings where completion ...
0 votes
1 answer
69 views

Stop flushing the last command when hitting enter

Suppose I wrote this command: command! -nargs=1 E echo ' -> <args>' and when user feeds an argument, :E abc I intend to see the following effect as they hit Enter: :E abc -> abc Of ...
0 votes
1 answer
19 views

Convert sequence of external commands to a Vim custom command

To reformat Markdown tables, I use the following sequence of external commands (e.g. after visually selecting my table lines): :<,>! sed 's/[[:space:]]\{1,\}\|/\#\|/g' :<,>! column -t -s '\...
1 vote
1 answer
50 views

List Vim arguments options

Is there a way to list the command line arguments showed by vim -h or vim --help from within Vim? Besides :r!vim -h which seems to be a workaround to achieve this.
5 votes
1 answer
547 views

How to use -complete=lua for command-completion?

If you check the help for :command-completion, there is a line that reads: -complete=lua Lua expression But it does not give further instructions about how to use it, or how to provide a Lua ...
0 votes
1 answer
60 views

NeoVim - Interact with the thing that pop ups when you type in a command

Questions How can I type something in there? What even is the name of this thing? Problem If you type in for example :!echo 'Hello World' This kinda terminal thing pops up I want to interact with ...
2 votes
1 answer
231 views

How to obtain Vim's command line?

I want to see what shell command line were used to start Vim. For example, I used command vim -S Session.vim argv() and argc() don't show switches and it's parameters. Command :echo tr(join(readfile(&...
137 votes
8 answers
195k views

How can I easily move a line?

What is the command (or shortcut) to move a line up or down in vim? My current workflow is to yank (copy) the line and than delete that line and than to put (paste) that line.
0 votes
4 answers
53 views

How to repeat substitution on the consequent lines?

Say I want to fix a mistake in the following php code: $line1 = intval($line[$1]); $line2 = intval($line[$2]); $line3 = intval($line[$3]); and do substitution on the first line with: :s/\$\(\d\)/\1/ #...
2 votes
2 answers
604 views

Applying commands to buffer from Neovim command line with complex plugin managers

I come from the following problem: I'm using Neovim (0.8.3) with AstroNvim as plugin/everything-manager. I've successfully set up multiple LSP servers from within that, which use the right servers, ...
4 votes
1 answer
1k views

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

How can I edit the text of a Vim command I've started typing out in the Vim command line? Example: If I type out a long search and replace command and realized I made a mistake. Now I want to move ...
0 votes
2 answers
71 views

How to open files from terminal in desired pattern (tabs, vertical and horizontal splits on desired files)

So, I wrote next bash script: #!/bin/bash if [ "$#" -gt 1 ]; then path=$1 else path=$(cat subject.txt | tr -d '\n') fi nvim -p 1 "setup/$path/body.tex" -p 1 preamble/...
1 vote
1 answer
70 views

Map to for loop

How can I make a mapping that includes a for-loop? xnoremap <leader>y :for i in [1, 2, 3, 4] | echo i | endfor errors E121: Undefined variable: i and xnoremap <leader>y :for line in ...
0 votes
0 answers
12 views

Why recording typed characters by "qa" into reg a has different behavior for typed <M-Z> vs. <M-z>?

Case 1: In Excmd line I give qa to begin recording. I type \Alt Z (upper case Z) error message: E11: Invalid in command-line window:\<blank\>:q<CR> closes the window I give q for end ...
1 vote
1 answer
30 views

Why does the command ":g x" show all lines matching the last search?

I accidentally stumbled on a solution for a problem I had: I wanted to get an overview over all occurrances of the word under the cursor, after I used # to find them individually. For some reason I ...
1 vote
1 answer
81 views

Multiple "1 line >ed" messages

When I perform multiple shift :> operations, vim shows me a notification for each line that's shifted. Is there a way to avoid these multiple notifications? For example, I'm currently editing a ...
0 votes
1 answer
80 views

How in Vim to visual select lines from command mode?

In vim we can move, copy or delete lines from command line Copy from 12 to 14 code and paste here: :12,14t. Move code from lines 14 - 16 to 20: :14,16m20 But how to make visual selection from line ...
1 vote
0 answers
348 views

How to create a (lua) function to run a particular command in the shell on the currently open file, within neovim

If I'm working on a file I might want to run a particular command which uses the file within the shell. Example - running black (python formatter) on an open file. Ideally I'd like to be able to enter ...
1 vote
2 answers
46 views

Make ":w" command throw an error on filenames starting with a colon ":"

From time to time I accidentally create files with names like ":w" or ":q". This happens when instead of writing :wq I type :w:q and sometimes, for some reason, even :w:w or :w :w. ...
10 votes
2 answers
2k views

:silent makes my vim go blank

When I used :silent to run a terminal command in the background, my vim screen goes blank, until I navigate through my code, at which point each line I move to reappears. What gives?
0 votes
1 answer
327 views

How to get the total lines of a file before it's loaded into a buffer?

As title. My target is to disable a plugin before it is applied to a buffer that will be loaded with the content of a file. I can get the file name before it is loaded. The file to be opened is ...
1 vote
1 answer
109 views

How to add action before "gf"?

I'm using NVIM 0.8.2 I'd like to replace the default gf command (goto file under the cursor) to do something before and after the action. For example: echo "do something before" goto file/...
1 vote
1 answer
99 views

ci" or ci' doesn't work in vim key bindings for zsh command line editing [closed]

I have vim keybindings enabled for command line editing by bindkey -v. When I am trying to use ci", ci', di" or di' it doesn't work. For example: If I have a command echo "hello" '...
1 vote
2 answers
110 views

Ignore/map case in command prompt :edit fileName

I would like to use case-ignoring completion in the file arguments I pass to (n)vim in the internal command prompt: For example, :edit case<tab> should suggest caselower.txt and Caseupper.txt. ...
1 vote
1 answer
28 views

vim in FCEDIT=...vim... does not work with more than one option

When I write in a bash commamd line vim -u /root/.vimrc -c "set textwidth=0" this works as expected. When using same in FCEDIT= it does not work: FCEDIT='vim -u /root/.vimrc -c "set ...
0 votes
0 answers
9 views

Why Neovim has different color than Vim [duplicate]

I just installed Neovim and when I execute for example this command nnoremap <leader>gd :!clear<CR>:!git diff<CR> I'm getting this output for Neovim: and this output for Vim: How ...
5 votes
1 answer
263 views

How can I edit a regular expression search string as if it were a file?

Sometimes a regular expression starts to get pretty complex, and it's hard to edit in Vim's commandline. It seems the obvious way is to edit the search term as though it's a file and be able to ...
1 vote
1 answer
38 views

@: does not work to repeat the :qa command

I open the diff files between 2 code revisions using git difftool. I can use :qa to close the current diff and go to the next one. Rather than pressing :qa repeatedly, I would like to use @:, but I ...
12 votes
1 answer
3k views

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

I have a variable foo with let foo='value', and a function F like function F() return 'value' endfunction and I want to use them in an option: :set option=foo, :set option=F(); or in a command: :...
0 votes
1 answer
54 views

How do I use variables with the delete command? (i.e., how to expand/reference variables for command arguments?)

I'm using variables for line numbers, and I want to delete a range of lines using these variables. How do I do that? let x = 5 let y = 20 " I want to delete the range of lines from x ...
15 votes
4 answers
31k views

How to split a line into multiple lines efficiently?

I've been receiving logged data in a text file that is just one long line with each value separated by a space. Is there a command or set of commands that will split one line into multiple lines?
0 votes
1 answer
60 views

NeoVim runs part of mapping while starting

I am using a Raspberry Pi for learning C. I use NeoVim and Mingw-GCC on the Pi over SSH. Building is done with a custom script named build. Initial builds were done by calling ./build from the command ...
1 vote
4 answers
52 views

Programatically enter Command line window

I have bind q to :qa that hides q:. Is there a command to enter the Command Line Window that is not q:? How to access the Command Line Window without typing: q:?
1 vote
0 answers
56 views

Completion for ++flags in command-line mode

Is there any way to turn on tab completion for the various ++[flag] flags that some commands take? For example, :e ++ff=unix whatever.txt overrides fileformat to unix for whatever.txt, but :e ++<...
1 vote
1 answer
462 views

In neovim, can I use Enter to accept a command completion instead of executing the command?

Using neovim (v0.8.1 on Fedora 37) with its default configuration in my home directory, when I type :e <tab> the completion menu pops up, the first entry (here Desktop) is highlighted and the ...
1 vote
2 answers
178 views

Vim fill command line with currently highlighted word in substitution

I have incsearch on, so when I type :s/thingS it will highlight the thingS part of thingSoFar in the below text see, this thing is the thingSoFar thing When I am typing that command line with my ...
0 votes
0 answers
160 views

How to tab autocomplete in command-line and search using CoC?

How can I have autocompletion in the colon command-line and during / search just as autocomplete works in my buffers?
0 votes
1 answer
43 views

vert command works but v doesn't

To open a buffer in a vertical split, you can use the word "vert". For example : :vert term #it opens a terminal in a vertical split :vert sb1 #it opens the buffer 1 in a vertical split ...

1
2 3 4 5
10