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
0
votes
2answers
32 views

How to execute a shell script from a line in a file with `%` in it

I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use Y:!^R", but this particular script has % in it, which is ...
1
vote
1answer
53 views

VI mode when using colon (:)

I was wondering how can I enable VI normal mode when typing a colon (:) cmd in VIM or NeoVIM. For example: If I type a long search and replace cmd and realized I made a mistake now I want to move back ...
1
vote
2answers
40 views

Can I navigate backwards by word (not WORD) in command-line mode?

If I'm in command-line mode in vim, and I have the current command line entered (cursor position shown with |): :somecommand somefilename.txt| I'd like to navigate backwards so that the cursor is ...
1
vote
1answer
10 views

How to get current line string without visual selection?

I'm usually working with a file list for sorting/deleting/etc files, and I like to sometimes run arbitrary command on those files (which have either a full path or already present in current directory)...
3
votes
1answer
42 views

Curious behavior of :%normal g_lD (remove trailing spaces in file)

This is a noob attempt of mine, to remove trailing spaces in a file. The first attempt is: :%normal g_lD It worked, and I was happy. Then I tried it on a single line where there was no trailing ...
0
votes
0answers
28 views

JavaScript equivalent of :perldo?

Is there a JavaScript equivalent of :perldo that allows writing one-liners that perform inline replacement of the file (or file lines) based on small, ad hoc JavaScript programs? For example, this ...
2
votes
1answer
41 views

Passing arguments function with --argument or -a format

Is it possible to pass arguments to Vimscript functions with the --argument or -a format, similar to arguments in the command line? I am writing a command that submits a job in a remote machine. I ...
0
votes
0answers
25 views

How to use `<count>` and `-count` to make command repeatable?

I am trying to use <count> and -count to make a command repeatable. This is the command I have right now: command! -count=1 Hello :d <count>. But I got this error instead when I run :...
1
vote
2answers
36 views

How to call a plugin in a mapping?

I'm doing a project-wise refactor and I want to change variable names from camelCase to snake_case. I have YCM and vim-abolish installed. Let's say I have the following source file: dueDate = ... ...
2
votes
1answer
43 views

How to recover colon command removed by <C-U>?

In terminal, the command of the line of the input prompt can be cleared with <C-U>, and is recoverable with <C-Y>. In vim, the colon command can be cleared with <C-U>, but it is not ...
1
vote
1answer
51 views

How do I center in search and replace?

Everytime I do this: :%s/```sh/```ctags/gc I end up with hidden code blocks at the bottom of the screen that I can't see. I tried 'zz' but it does not work. I did read this and this but that's for ...
2
votes
1answer
99 views

Why Vim is slow when I execute vim commands without a terminal?

I want to edit files by executing Vim commands from inside node.js as the following: const child_process = require("child_process"); child_process.execSync(`time vim /home/user/file -c ':%s/^...
1
vote
2answers
47 views

How to prevent cnoremap taking effect for “/” searching?

I have created the following mapping for Ex mode to prevent having to enter :FZF capitalized to invoke FZF: cnoremap fzf FZF The problem is that this key mapping also affects "/" searching, ...
0
votes
0answers
22 views

How to read the starting/ending line number of my visual selection?

So what I would like to achieve is when I selected a block of texts using shift-v, is it possible to read the starting and ending lines' line number within command mode? (Something like we could read ...
0
votes
1answer
40 views

Why does the cursor end up on the wrong line when <Esc><Esc> is mapped to something?

In vim --clean, I insert these lines: One Two Three Four Five Six Then I do: :set mouse=a :nnoremap <Esc><Esc> <Nop> (From my observations, the mapping could be to anything. :...
0
votes
0answers
23 views

How do I disable messages like “written” and “2 fewer lines”?

How do I disable these messages. In the messages I always see: Messages maintainer: Bram Moolenaar <Bram@vim.org> 2 fewer lines; before #526 7 seconds ago "somefile" 190L 6771B written
0
votes
0answers
38 views

Map left command key to left control key in terminal only?

I've asked this question over on AskDifferent without any luck. I'm using neovim to edit code and am needing to create a mapping to bind to <cmd-w> to <C-w>. How would I go about this on ...
0
votes
1answer
38 views

Open vim with vsp and tabs on startup

I want the following configuration: Tab1: file 1 || file 2 Tab2: file 1 || file 3 I can open vsp with vim using vim -O file1 file2 I can open tabs with vim using vim -p file1 file2 Can I combine the ...
1
vote
2answers
88 views

Copy to clipboard or save to file substitution command

I'm trying to answer a vim question in U&L, which involves a very complex and long regex substitution. I would like to copy to clipboard the command, or save it in a file, so I don't have to make ...
1
vote
2answers
57 views

Is there any way of copying a macro inside a register to a different register?

I've discovered I can execute vim macros from the command line using the following command: vim myfile -c "argdo norm @aZZ" This command executed from the command line will execute a macro ...
0
votes
1answer
42 views

How to pass argument to a ex command after chaining it with <bar>?

I'm trying to make my life easier with vim fugitive and ex command line, by creating an abbreviation to a frequent task, which is switching to develop, pulling it and creating new branch. That's my ...
0
votes
1answer
66 views

Intercepting & modifying commands

Is it possible to intercept incoming user commands? For example, if the user executes :echo 'hello', then I would like to compare the string and the command, and change it to execute :echoerr 'hello' ...
0
votes
0answers
21 views

How to automatically show suggestions while typing in command line?

Is there any inbuilt switch to enable this? Another approach is using :cnoremap <on text change trigger autocomplete (<C-Z>)> but :cnoremap doesn't have enough info for me to get started. ...
1
vote
2answers
35 views

How to remove periods within visual selections in a cmd composition?

I'd like to remove the period between the 6th comma and the 9th comma for the multiple lines of the following texts. Change from: 4,Afghanistan,2,Medium,1951,1951.5,4134.756,3705.395,7840.151,12.009 4,...
2
votes
1answer
59 views

Use feedkeys then do command

I want to write a mapping that does feedkeys(":cd " . getcwd()), waits for me to edit the directory and then press enter, and then runs a command such as :Rg from the fzf plugin. I tried ...
0
votes
1answer
27 views

Can you open two files from command line and go to end?

On Windows I'm trying to start editing two files and check or edit the end of both files. I didn't manage to jump to the end of both files. It only works for the first file: gvim -O "+norm Go&...
0
votes
0answers
32 views

Effect of changing directories in a vim command [duplicate]

When executing a vim command, such as the following: :w!<CR>:!cd %:p:h What is the effect after the command is finished? Is the new cwd the directory that I've cd'ed into? Or does that only ...
-1
votes
1answer
30 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 ...
1
vote
3answers
93 views

Is it possible for a command or function to end in command line mode?

It's possible to configure a mapping such that command line mode is active after the key press. For example, with a mapping :map H :help , pressing H results in command line mode being entered with :...
1
vote
1answer
20 views

Simple way to store additionnal config in the scope of the actual directory [duplicate]

I have my .vimrc with some global/local configurations, but when I am working in a project, I know that I often create configs (settings, mapping, command, abbreviations, etc.) specifically for this ...
0
votes
1answer
261 views

How can I run awk script with in vim?

We know that we can run commands from vim using :!command <args>. For example: :%!awk '{ print $2,$1,$3 }' FS=',' OFS=',' :%!sort I am having trouble running an awk script within vim. I can run ...
4
votes
1answer
63 views

Why do some Ex commands not need a white space before a path argument?

For example, why does this work: edit/home/foo/bar.txt (I had to enter visual to see the changes) I was expecting a whitespace after edit, like: edit /home/foo/bar.txt I couldn't find a reference in ...
-1
votes
1answer
29 views

Delete word or whole line part after cursor in colon-command mode with keybinding

I would like my NeoVim to have Emacs-style keybindings in all "direct input" modes, in particular - Alt+d and Ctrl+k for forward word and line part deleting. I've done it for insert mode as ...
1
vote
1answer
28 views

How to escape the end of a filename in a :read command?

I want to insert a skeleton to .sh files without any plugins. Vim complains that it can't find the file ~/.vim/skeletons/sh<CR><ESC>l. How do I indicate that /sh is the end of the filename ...
1
vote
3answers
249 views

How do I make my own function to insert text in vim?

I have a folder of third party libraries called add-libraries and the location for this specific library is /home/yapjiahong/projects/cpp/add-libraries/plog/include. I want to write a function called ...
3
votes
1answer
69 views

add buffer to vim from the shell command line

I am currently trying to externally add a new buffer to a vim instance from the command line. That means I have already opened vim and I modify the files of interest to me. Then I want to go back to ...
0
votes
2answers
40 views

How to insert a blank line above another line

I have these lines; Question1. Is this true? a. Yes b. No Question2. How is the weather a. Good b. Bad Question3. The sky is a. Dark b. Blue I wanted to change it to; Question1. Is this true? a. Yes ...
0
votes
1answer
18 views

Can I create a file and read in shell command output in one line?

I want to create a file and read in function declaration to be able to edit it further. e() { echo $FUNCNAME } vim FILE < <(declare -f e ) but that doesn't seem to work and the filename expands ...
2
votes
1answer
205 views

Disabling relativenumber in Command Mode

I have au InsertEnter * set norelativenumber au InsertLeave * set relativenumber So that I have relativenumber in normal mode but not insert mode. I want to extend this to command mode. I tried ...
2
votes
1answer
65 views

Print bound autocmds to a file

I would like to print all of my current autocmds to a file so that I can grep through and do further analysis. From within vim, the list of autocmds can be found with :autocmd, but this prints to a ...
2
votes
1answer
91 views

Define w< command

I often type :w< instead of :wq, so I wanted to redefine it (in order to avoid the creation of a < file) as following: command! w< w But it seems to not be allowed: Error detected while ...
-1
votes
1answer
34 views

Remove right text (line numbers , ALL) in command line

I am using neovim and i want to remove the indicated text (0,0-1 ALL).
0
votes
1answer
44 views

Disable command but allow to write in command mode

I have fzf.vim installed, and therefore I have a :W command. I prefer working with buffers, so I save a lot with :w. However, accidentally using a capital W invokes :W which annoys me. I tried ...
1
vote
1answer
53 views

Different word boundaries in command mode

I very commonly use CTRL-W to adjust a previous path in the command line, like I'll bring up the directory of the current file or perhaps a previous :e ... command from history that's close, and use ...
2
votes
1answer
121 views

How to display a list of all folds?

How can I show a list of all folds? e.g., maybe a list something like: 1-3 12-18 13-16 where <start-line>-<end-line> are the starting and ending lines of the fold. Is there a command-line ...
0
votes
1answer
63 views

why does vim insert a range when we press a number before pressing colon to go to command line mode?

I was trying to make a mapping to run a command that takes a count, something like the following: nnoremap gb :execute('buffer ' . v:count)<CR> When I run the mapping, I see the following error:...
4
votes
0answers
26 views

Tweak command-line position and size

The command-line is obviously a very convenient tool in vim. However, especially when working with splits, it can feel uncomfortable to have to look back and forth between window and command-line (e.g:...
3
votes
1answer
148 views

Any ways to display lolcat output in Vim?

I known lolcat for a while now, and wondered if it was possible to display the text that it output, inside of Vim correctly. So i tried: :%! lolcat But while it update the buffer, the text doesn't ...
2
votes
1answer
22 views

Substitute: previous match with confirm

If I do a replace like this: :%s/May/June/gc afterward I keep hitting y or n as needed. But sometimes it hit n on accident and need to go back. I read that you can use N for this purpose, but it ...
4
votes
1answer
193 views

How can I write all named buffers?

I would like a command that saves every buffer that has a filename. :h :wall gives this: *:wa* *:wall* :wa[ll] Write all changed buffers. Buffers without a file ...

1
2 3 4 5
8