The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [user-commands]

Questions about :command and how the user can define custom commands.

Filter by
Sorted by
Tagged with
0
votes
1answer
26 views

How to use variables in a user defined command? [duplicate]

I have this user defined command: command! PS silent! w | PlugSnapshot! ~/.vim/plugins/plugins.lock How could I change it to take the filepath from a variable, something like this: let ...
2
votes
1answer
57 views

What is the purpose of user `command` in Vi/Vim?

What is the purpose of user command in Vi/Vim? I noticed that a lot of commands are usually used to call functions like this: command! TrimWhitespace call TrimWhitespace() From my observation, ...
0
votes
1answer
24 views

Is it possible to non-recursively remap a command?

So Fugitive defines :Glog. This is, apparently, aliased to a call to the script-local s:Log() function (according to :command Glog.) My muscle-memory has been using glog at the command-line, for ...
3
votes
2answers
109 views

How to edit a file in a new tab?

I want to map :e file.txt to :tabnew file.txt, or the equivalent setting for editing file in a new tab. What do I need to put into my vimrc?
0
votes
1answer
305 views

Using arguments in a .vimrc command

I've discovered that I can edit the .vimrc file to create custom commands and would like to create simpler search and replace alternative commands, but have no idea how to edit %s/foo/bar/gc so that ...
0
votes
2answers
149 views

Mapping using tpope/vim-surround only works with command

I have this mapping to surround a Word with jQuery id selector $("#...") and it works fine using a command: command! JqId normal viwo^[i#^[ysiW"ysiW)i$^[E nnoremap <Leader>jqid :JqId<CR> ...
0
votes
2answers
45 views

Extract JavaScript variable (feature example): how to improve it?

I am a Vim newbie with one week experience and I'm already enjoying it. I've successfully written an (ugly) command+function+mapping with which I can extract some code to a new variable in JavaScript....
1
vote
2answers
2k views

Passing visual range to a :command as its argument

I have a command: command! -nargs=1 TmuxSession !tmux.session "<args>" and I want to run it in visual mode so that selected text will be passed as argument. By selected text I mean selected in ...
1
vote
1answer
225 views

How to create user command without a capital letter as first letter?

I know I can set user-defined commands using the :command Foo bar syntax, but I want a way to set a command without using capitals. For example, to save all open buffers, the command is :wa, but that'...
2
votes
1answer
410 views

Better “bro ol”

Inspired by a nice solution on a Stack Overflow, the following was put in my vimrc: command! Bro :vnew +setl\ buftype=nofile | 0put =v:oldfiles \| nnoremap <buffer> <CR> :e <C-r>=...
0
votes
1answer
48 views

Why does the <count> escape sequence insert the current line number in my user command?

I've added the following to my .vimrc in order to test how <count> works in a user defined command because I was noticing odd behaviour: :command! -count=1 CountTest :exe "echo " . <count>...
1
vote
1answer
49 views

Why only part of a command is executed

I have created a new command command! Tags execute '!GTAGSFORCECPP=1 gtags' | cscope kill -1 | cscope add GTAGS However, for some reason cscope add GTAGS doesn't execute when I execute :Tags. Can ...
2
votes
2answers
470 views

Filtering text out to new tab with custom command

I would like to add to my vimrc a custom command (:customFilter {pattern}) for filtering text and placing result in a new tab. I tried using :global or :vimgrep /{pattern}/ % but the problem is that ...
7
votes
2answers
3k views

Is there a command to enter Visual Block mode?

I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work). Is there any ...
2
votes
1answer
901 views

How to define a custom user defined command to filter a range?

I want to select some lines in visual mode, and enter a custom command :Ex<CR> so that: '<,'>!expand -t4 is run to expand all tabs in selected range. How to define the Ex command? I ...