Jair López
  • Member for 5 years, 10 months
  • Last seen more than a month ago
What is the meaining of '#' symbol in function name?
Accepted answer
20 votes

That's part of the autoload mechanism. From Autoloading at Learn Vimscript the Hard Way and :help autoload: Autoload lets you delay loading code until it's actually needed, so if the following ...

View answer
How to use :g to insert?
Accepted answer
11 votes

What comes after the second / is an Ex command. In this case you could use the :normal command, which executes its argument as if you typed it in normal mode (see :help :normal) :g/^#/normal I# or ...

View answer
How do I replace a character with its hex value?
Accepted answer
10 votes

In that way, printf expects a decimal number to be converted to a hexadecimal one. All you need to do is convert the character to a number as follows: s/\([a-z]\)/\=printf("%#02x", char2nr(submatch(0)...

View answer
What is an atom?
Accepted answer
9 votes

A pattern is made up of atoms, from :help /atom: An atom can be one of a long list of items. Many atoms match one character in the text. It is often an ordinary character or a character class. ...

View answer
What does :%! mean?
9 votes

From :help :%: % equal to 1,$ (the entire file) *:%* From :help :range!: :{range}![!]{filter} [!][arg] *:range!* Filter {range} lines through the external ...

View answer
Diffing two time stamps under selection
Accepted answer
6 votes

You could try the following code: " line1 is the line number the first timestamp is on. " line2 is the line number the second timestamp is on. function! GetTimeDifference(line1,line2) " Get line ...

View answer
How to modify visually selected block with external command?
Accepted answer
6 votes

You can also try: gg ^V G t# d :%!column -t gg P From :h :visual_example: Currently the ":" command works on whole lines only. When you select part of a line, doing something like ":!date" will ...

View answer
Exclude start and end match from region
Accepted answer
5 votes

There are a couple of nuances that need to be grasped in order to make it work: The "." in buferr matches ' and will eat it up before the pattern in buflit can see it and, as a result, the buflit ...

View answer
gqip for VHDL comments does not work
Accepted answer
5 votes

You should tell Vim what a comment is using: :set comments+=:--,b:-- Explanation: The comments option contains a comma separated list of strings that can start a comment line. :-- specifies the ...

View answer
Replace selection with output of external command
5 votes

If you put the cursor on such a line you can: 0 to put the cursor in the first column. f Space to put the cursor in the first blank. i Enter Esc to split the line. l to move the cursor one line up. :....

View answer
What's the difference between "qp and <c-r><c-r>q when you store a macro?
Accepted answer
4 votes

what's the difference between these two methods? p inserts the content of a register as it is, regardless of the encoding, but CTRL-R CTRL-R encodes sequences of bytes before inserting them. ...

View answer
Open multiple files in tabs from Explore mode
Accepted answer
4 votes

Let's Vim do it for you. You can put the following code at the end of your vimrc file: function! NetrwOpenMultiTab(current_line,...) range " Get the number of lines. let n_lines = a:lastline -...

View answer
set formatprg dynamically based on textwidth?
4 votes

That's when the OptionSet event comes in handy, but it doesn't work when it's triggered on startup so you need the VimEnter event too. If your workflow includes several files opened in different ...

View answer
`system()` can't get output of shell command in vimrc
3 votes

@Matt is absolutely right; you might use double backslashes: let s:os = system("sed -n 's/^NAME=\\(.*\\)/\\1/p' /etc/os-release") or switch to a single-quoted string: let s:os = system('sed -n "s/^...

View answer
How can I shift only inner contents of HTML element?
Accepted answer
3 votes

That's a great opportunity to leverage text objects (see :help text-objects). The following code extends the normal behavior of the it text object (see :help it and :help tag-blocks) to make it ...

View answer
How to add accent to letters in normal mode?
3 votes

You could put one of the following codes at the end of your vimrc file to make the - key toggle the vowel under the cursor between the accented and unaccented form: The intuitive solution function! ...

View answer
Is there a one-key command to insert before the first character of the line?
Accepted answer
3 votes

What you need is I (uppercase letter i). From :help I I Insert text before the first non-blank in the line [count] times.

View answer
Should the output of the -w {scriptout} flag work to replay actions using the -s {scriptin} flag?
Accepted answer
2 votes

This is a bug registered on March 17th, 2019 and reported on February 24th, 2019. From :help known-bugs: Bug: script written with "-W scriptout" contains Key codes, while the script read with "-s ...

View answer
How do I configure the path to match Python's site-package location?
Accepted answer
2 votes

You might check out tpope's apathy.vim for global site-packages.

View answer
Pass variable in vimscript function to split
Accepted answer
2 votes

Many commands in Vim, including :botright and :vsplit, expect plain text, no variables or expressions ( see :help 41.3 and :help expression to know what a expression means). But there are commands ...

View answer
Map key to copy to next window
Accepted answer
2 votes

Because you are in visual mode when you press F2, you need to map this key in visual mode, so you need to substitute :map for :vmap. But be careful with spaces because they move the cursor to the ...

View answer
Match any number of digits NOT followed by
Accepted answer
1 votes

You're almost there, what you need is \> at the end of the regular expression like so: :%s/^\(\s*\d\+\)\.\@!\>/\1\. Or even better: :%s/^\s*\d\+\.\@!\>\zs/. Note: A . in the replacement ...

View answer
Custom mapping for ex command -> still show typing in ex console
Accepted answer
1 votes

With :cabbrev you can achieve what you want so Christian Brabandt has made a great suggestion. Now you have two different approaches, on one hand you could try Christian's suggestion and type in: :...

View answer
Paste without messing up indentation in insert mode
Accepted answer
1 votes

From :help i_CTRL-R_CTRL-P: CTRL-R CTRL-P {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-P* Insert the contents of a register literally and fix the indent, like |[<MiddleMouse>|. Does ...

View answer
Insert carriage return in a vimscript variable
Accepted answer
1 votes

The first argument of writefile must be a list and each list item represents a line in the new file. Using split() you could make a pattern-separated list out of longstring as follows: call ...

View answer
Conversion from XML to KML
1 votes

If the XML file only have lines in that format you could try this shorter command: :%s/\v\S{-}([0-9.-]+)\_.{-}([0-9.-]+)\S*/<Point><coordinates>\2,\1<\/coordinates><\/Point> ...

View answer
How do I get matchit to work with '/>' (self-closed tags)?
Accepted answer
1 votes

Let's suppose you have the following lines in your ~/.vimrc source $VIMRUNTIME/macros/matchit.vim filetype plugin on If the offending lines are in a .html file, then: b:match_words = '<:>,' ....

View answer