Hot answers tagged

5

This is the description of c in the help file: ["x]c{motion} Delete {motion} text [into register x] and start insert. The register is optional, but the motion is mandatory. A lone c makes no sense. In other words, we say that c triggers the operator-pending mode. Therefore the distinction between a normal mode i and an operator-pending mode i is ...


5

Vim keeps what you type in memory, even when it seems to have no effect on the screen, this allows you to apply modifiers to commands. To see what modifiers you typed, and will be applied to the next command, you can use :set showcmd. They will appear at the bottom right of the screen. Another good example of that effect is how G will take you to the end of ...


5

The reason why the approach using user commands (with :command!) does not work is that user commands are quite restricted in how they are allowed. They must always start with an uppercase letter (so they don't clash with Vim native commands) and their names may not include special characters (such as <.) Instead of user commands, you can use :cabbrev to ...


3

Based on :help v:count: *v:count* *count-variable* v:count The count given for the last Normal mode command. Can be used to get the count before a mapping. Read-only. Example: > :map _x :<C-U>echo "the count is " . v:count<CR> < Note: The <C-U> is required to remove the line range ...


3

Here's the general idea... func! MakeHLine(...) abort " Default delim char and width let l:ch = '#' let l:tw = 78 " Override defaults per given parameters if a:0 let l:ch = a:1 if a:0 == 2 let l:tw = a:2 endif endif " Do the actual work eval repeat(l:ch, l:tw)->append(...


2

You can give a try to vim-surround plugin. To put a word into quotes you will go ysiw'. The plugin gives you the power to: add (ysiw") word -> "word" change (csiw"') 'word' delete (ds') word the surroundings not only of sigle words but of all kinds of text objects: surround words inside parentheses (ysi)") def func(some ...


2

If you're using the VS Code extension that I think you are then my understanding is that it supports at least some plugins and one of those is vim-surround. If that's the case and you're open to using plugins just jump to the last paragraph. Otherwise, read on. From Normal mode with the cursor on the first character of the word you could do... i"<C-O&...


2

One way to run the command and leave the file intact is :terminal, like in :terminal bash %. Vim will split a terminal running the program and leave you editing the file. It’s also asynchronous in the sense that you can edit while the program runs.


2

No, you have to write such "option parser" yourself. But quite probably there's no need to do this. Just re-write your function to accept dictionary argument. For example, function! SubmitJob(opts) abort let l:opts = extend(copy(a:opts), #{hours: 1, cpus: 1}, 'keep') echo l:opts.hours l:opts.cpus endfunction :call SubmitJob(#{cpus: 2}) &...


2

While I'm not entirely sure deleting this command is a great idea you can do it using an autocommand like this in your vimrc: augroup deletePluginCommand autocmd! autocmd VimEnter * delcommand Windows augroup END If you are not familiar with autocommands, they are a way to trigger some code on an event (see :h autocmd) and here we use the event ...


2

The video shows Vim, not Neovim. In Neovim the output of "bang" is not colorized. If you like long stories you can read this and this and so on. TL;DR they think it's not a big deal, but fixing "bang" may be too hard, so just use :terminal instead.


2

While Christian Brabandt already gave the correct answer in a comment: :echo strftime('%a %b %d %T %Z %Y') I would like to add a few words. The most important part from the help documentation: The accepted {format} depends on your system, thus this is not portable! See the manual page of the C function strftime() for the format. So the actual valid format ...


1

If you want to automate this process I would go with regular vimscript + vim api: let output = system('w3m -dump someurl.com') let output = substitute(output, 'regex', 'replace', 'g') " do smth else with output "... "... " append output to the current buffer after current line call append('.', split(output, '\n')) If you really want to ...


1

User commands must start with an uppercase character, so you could do something like this: :command Akeyword execute 'Ex C:\Users' . $USERNAME . '\randomfolder' The key here is to use :execute, which executes the result of an expression as a command. However, you can shorten this to: :command Akeyword Ex $HOME\randomfolder Since Vim sets the $HOME variable ...


1

The official response from Junegunn is to put the following in your vimrc: command! -nargs=* W w This will make :W behave like :w, while still allowing you to use :Wi (or any other shortening of :Windows) if you want to.


1

I was able to accomplish something reasonable with the following code: function CollectFolds() abort if !exists('s:folds') let s:folds = [] endif const line = line('.') const end = foldclosedend(line) if !exists('s:prev_end') " first one let s:prev_end = end call add(s:folds, [line, end]) elseif end isnot# s:prev_end " new ...


1

EDITED: You can use this: :g/Engine1/.,.+2w! >> Newfile.txt It will find all the occurence of Engine1 and copy his line with the two line below to the file Newfile.txt You can also create a personnal command: :command -nargs=1 MySearch :g/<args>/.,.+2w! >> file.txt After entering this command, if you try writting :MySearch Engine1 It will ...


1

By keys I mean like being Normal mode and pressing e (takes you to end of [next] word), by commands I mean like being in Normal mode and pressing Shift+; and typing :delete. Yes. From Select mode, you can use CTRL-O to switch to Visual mode for the duration of a single command. So you can use <C-o>e to select until the end of the word, or <C-o>:...


1

If you want the user to be able to enter a sequence such as r\<cr> or r\r and have Vim interpret that the same way as it interprets sequences in a double quoted string, the easiest way to do so is to actually assemble it into a double quoted string and use eval() to have Vim interpret it. In your particular case: execute "normal! " . eval('&...


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