qid int64 4 8.14M | question stringlengths 20 48.3k | answers list | date stringlengths 10 10 | metadata list | input stringlengths 12 45k | output stringlengths 2 31.8k |
|---|---|---|---|---|---|---|
19,410 | <p>Consider the following text snippet:</p>
<pre><code>value1,
value2
</code></pre>
<p>Now, if the cursor is at <code>(1,1)</code> (the <code>'v'</code> of <code>value1</code>), <code>W</code> takes me to <code>(2,5)</code> (the <code>'v'</code> of <code>value2</code>) which is as expected. But if I do <code>dW</... | [
{
"answer_id": 19431,
"author": "Tanath",
"author_id": 712,
"author_profile": "https://vi.stackexchange.com/users/712",
"pm_score": 1,
"selected": false,
"text": "<p>I don't think those exceptions apply because the end of the motion is not in column 1.</p>\n\n<p><code>:h WORD</code> says... | 2019/04/02 | [
"https://vi.stackexchange.com/questions/19410",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20568/"
] | Consider the following text snippet:
```
value1,
value2
```
Now, if the cursor is at `(1,1)` (the `'v'` of `value1`), `W` takes me to `(2,5)` (the `'v'` of `value2`) which is as expected. But if I do `dW` at the same position, what I expect is:
```
value2
```
But what I get is:
```
<empty_line>
value2
... | some contents of :help WORD
```
Another special case: When using the "w" motion in combination with an
operator and the last word moved over is at the end of a line, the end of
that word becomes the end of the operated text, not the first word in the
next line.
```
There is another special case if there exists trail... |
19,432 | <p>I use vim for prose and and code, and when it comes to prose I use spelling a lot to help me out. I have it set up and already, and I'm already working with <code>z=, zg, zw, [s</code> , and <code>]s</code> to work with spelling. </p>
<p>The thing is, I write in both Portuguese and English, and I want some words to... | [
{
"answer_id": 19431,
"author": "Tanath",
"author_id": 712,
"author_profile": "https://vi.stackexchange.com/users/712",
"pm_score": 1,
"selected": false,
"text": "<p>I don't think those exceptions apply because the end of the motion is not in column 1.</p>\n\n<p><code>:h WORD</code> says... | 2019/04/04 | [
"https://vi.stackexchange.com/questions/19432",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14568/"
] | I use vim for prose and and code, and when it comes to prose I use spelling a lot to help me out. I have it set up and already, and I'm already working with `z=, zg, zw, [s` , and `]s` to work with spelling.
The thing is, I write in both Portuguese and English, and I want some words to be valid for both languages and... | some contents of :help WORD
```
Another special case: When using the "w" motion in combination with an
operator and the last word moved over is at the end of a line, the end of
that word becomes the end of the operated text, not the first word in the
next line.
```
There is another special case if there exists trail... |
19,446 | <p>I can source a file, e.g. my <code>vimrc</code> with <code>:so %</code> or <code>:so <filename></code>. But what do I do when I need to source only part of a file. I want some way to visually select a portion of the file with <code>:h v</code> and then source it. Kinda like emacs's <code>M-x eval-region</code>... | [
{
"answer_id": 19447,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 5,
"selected": true,
"text": "<p>After you've done your Visual selection run this:</p>\n\n<pre><code>y:@\"<CR>\n</code></pre>\n\n<p><code>y</code>... | 2019/04/05 | [
"https://vi.stackexchange.com/questions/19446",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16280/"
] | I can source a file, e.g. my `vimrc` with `:so %` or `:so <filename>`. But what do I do when I need to source only part of a file. I want some way to visually select a portion of the file with `:h v` and then source it. Kinda like emacs's `M-x eval-region` | After you've done your Visual selection run this:
```
y:@"<CR>
```
`y` copies the selection to the unnamed register (`"`) since we didn't explicitly name a register. Then `:@"` executes the contents of that register as Ex commands.
See `help :@` and <https://stackoverflow.com/questions/20262519/vim-how-to-source-a-... |
19,451 | <p>I want to VISUAL select a piece of text character-wise and pass it to an external command.</p>
<p>For example I want to select only the URL from the the text below</p>
<pre><code>abcde www.google.com abcde
</code></pre>
<p>and open it in the default browser.</p>
<p>But after I VISUAL selected it and ran the comm... | [
{
"answer_id": 19452,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 4,
"selected": true,
"text": "<p>prototype of system is:</p>\n\n<pre><code>system({cmd} [, {input}])\n</code></pre>\n\n<p>according to :help system()</p... | 2019/04/05 | [
"https://vi.stackexchange.com/questions/19451",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18651/"
] | I want to VISUAL select a piece of text character-wise and pass it to an external command.
For example I want to select only the URL from the the text below
```
abcde www.google.com abcde
```
and open it in the default browser.
But after I VISUAL selected it and ran the command
```
:call system('xdg-open', @*)
`... | prototype of system is:
```
system({cmd} [, {input}])
```
according to :help system()
```
If {input} is a string it is written to a pipe and passed as
stdin to the command. The string is written as-is, line
separators are not changed.
```
so your final command becomes something like this:
```
echo www.google.co... |
19,459 | <p>I use (neo)vim with <code>mouse=a</code> and <code>scrolloff=5</code>. Clicking on one of the top or bottom five lines with the mouse causes the screen to jump (so that the new cursor position is more centered), which distracts me. Is there any way to disable "<code>so=5</code>" for mouse-clicking only?</p>
| [
{
"answer_id": 19452,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 4,
"selected": true,
"text": "<p>prototype of system is:</p>\n\n<pre><code>system({cmd} [, {input}])\n</code></pre>\n\n<p>according to :help system()</p... | 2019/04/06 | [
"https://vi.stackexchange.com/questions/19459",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21684/"
] | I use (neo)vim with `mouse=a` and `scrolloff=5`. Clicking on one of the top or bottom five lines with the mouse causes the screen to jump (so that the new cursor position is more centered), which distracts me. Is there any way to disable "`so=5`" for mouse-clicking only? | prototype of system is:
```
system({cmd} [, {input}])
```
according to :help system()
```
If {input} is a string it is written to a pipe and passed as
stdin to the command. The string is written as-is, line
separators are not changed.
```
so your final command becomes something like this:
```
echo www.google.co... |
19,465 | <p>I used to store macros in insert mode as <code><c-r><c-r>q</code>, but that fails if the macro contains a special character such as <code><C-Right></code></p>
<p>If I record a macro as </p>
<pre><code>qq<C-Right>q.
</code></pre>
<p>the result of <code><c-r><c-r>q</code> in inse... | [
{
"answer_id": 19467,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 2,
"selected": false,
"text": "<p>There are several ways to insert the content of a registers. I'm going to briefly discuss some that are inserted when in... | 2019/04/07 | [
"https://vi.stackexchange.com/questions/19465",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | I used to store macros in insert mode as `<c-r><c-r>q`, but that fails if the macro contains a special character such as `<C-Right>`
If I record a macro as
```
qq<C-Right>q.
```
the result of `<c-r><c-r>q` in insert mode is :
```
<80>ýV
```
the result of `"qp` in normal mode is :
```
<80><fd>V
```
If I copy... | >
> what's the difference between these two methods?
>
>
>
[`p`](https://vimhelp.org/change.txt.html#p) inserts the content of a register
as it is, regardless of the encoding, but [`CTRL-R CTRL-R`](https://vimhelp.org/insert.txt.html#i_CTRL-R_CTRL-R)
encodes sequences of bytes before inserting them.
### Explanati... |
19,473 | <p>I compiled vim 8.1 for Ubuntu 16.04 x64, from source, by following Valloric's excellent <a href="https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source" rel="nofollow noreferrer">guide</a> on the subject. Although that guide is for an older version, it was really simple to check out the correct vers... | [
{
"answer_id": 19479,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 3,
"selected": true,
"text": "<p>I build Vim 8.1 on Ubuntu 16.04 and install it to the custom directory <code>/opt/vim</code>.</p>\n\n<p>My steps:</p>\n\n... | 2019/04/07 | [
"https://vi.stackexchange.com/questions/19473",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11789/"
] | I compiled vim 8.1 for Ubuntu 16.04 x64, from source, by following Valloric's excellent [guide](https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source) on the subject. Although that guide is for an older version, it was really simple to check out the correct version I wanted using git.
I ran `./config... | I build Vim 8.1 on Ubuntu 16.04 and install it to the custom directory `/opt/vim`.
My steps:
```
INST_DIR="/opt/vim"
./configure --prefix=${INST_DIR} --mandir=${INST_DIR}/share/man ...
make
make test
make install
```
This works as expected.
You can run `make -n install`. Then make just prints what it would instal... |
19,501 | <p>Is there a nondestructive way to search a pattern in all registers, like redirecting <code>:reg</code> to some register and then paste it to a new buffer and perform the search there? </p>
| [
{
"answer_id": 19502,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 1,
"selected": false,
"text": "<p><a href=\"https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7\" rel=\"nofollow noreferrer\">Here is a gist ... | 2019/04/09 | [
"https://vi.stackexchange.com/questions/19501",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21649/"
] | Is there a nondestructive way to search a pattern in all registers, like redirecting `:reg` to some register and then paste it to a new buffer and perform the search there? | You can have the list of registers that match a pattern with:
```
:let regs=split('abcdefghijklmnopqrstuvwxyz0123456789/-".', '\zs')
:echo filter(regs, 'getreg(v:val) =~ "the_pattern"')
```
Or if you really prefer to paste all registers into a buffer in order to search interactively (and not programmatically) -- I ... |
19,506 | <p>I have some text with two dashes:</p>
<pre><code>This is some text -- with two dashes.
</code></pre>
<p>I want to delete the space before and after the dashes:</p>
<pre><code>This is some text--with two dashes.
</code></pre>
<p>Is there a way this can be done without simply pressing <code>x</code> on each space?... | [
{
"answer_id": 19507,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 2,
"selected": true,
"text": "<p>I'd go for a substitution:</p>\n\n<pre><code>:%s/ \\+-- \\+/--/gc\n</code></pre>\n\n<p>With <code>g</code> flag to be ... | 2019/04/09 | [
"https://vi.stackexchange.com/questions/19506",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11931/"
] | I have some text with two dashes:
```
This is some text -- with two dashes.
```
I want to delete the space before and after the dashes:
```
This is some text--with two dashes.
```
Is there a way this can be done without simply pressing `x` on each space?
I thought maybe vim-surround works with spaces, so I tried... | I'd go for a substitution:
```
:%s/ \+-- \+/--/gc
```
With `g` flag to be executed globally on the lines (not only first occurrence per line) and `c` to confirm (to make sure it does not change things you did not want) |
19,531 | <p>As I see the substitution command e.g.:</p>
<pre><code>:% s/a/b/
</code></pre>
<p>puts a into the register "/ but the text that is being replaced is not saved in a register.
Now, I would like to replace a with b but keep the result of a in a specific register where I can any moment retrieve it and paste it back at... | [
{
"answer_id": 19532,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 0,
"selected": false,
"text": "<p>You might want <code>&</code>, which is the original matched pattern:</p>\n\n<pre><code>:% s/^\\(.*\\)\\t\\(.*\\)... | 2019/04/11 | [
"https://vi.stackexchange.com/questions/19531",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21739/"
] | As I see the substitution command e.g.:
```
:% s/a/b/
```
puts a into the register "/ but the text that is being replaced is not saved in a register.
Now, I would like to replace a with b but keep the result of a in a specific register where I can any moment retrieve it and paste it back at the same position where i... | By default, the matched text in a substitution, won't be captured into a register, however it will always be available as atom `&` in the replace part of your `:s` command.
Having said that, you can of course store the matched text inside a specific register using the special atom [`\=`](https://vimhelp.org/change.txt... |
19,550 | <p>assume you you have some text like this:</p>
<pre><code>
<-------unknown area
<-------blank lines
.....0.....<-------dot represent unknown character
.....1.....
.....*.....<-------unknown number of lines, the 6th column is not blank
.....3.....
.....4.....
.....5.....<-------you... | [
{
"answer_id": 19532,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 0,
"selected": false,
"text": "<p>You might want <code>&</code>, which is the original matched pattern:</p>\n\n<pre><code>:% s/^\\(.*\\)\\t\\(.*\\)... | 2019/04/12 | [
"https://vi.stackexchange.com/questions/19550",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | assume you you have some text like this:
```
<-------unknown area
<-------blank lines
.....0.....<-------dot represent unknown character
.....1.....
.....*.....<-------unknown number of lines, the 6th column is not blank
.....3.....
.....4.....
.....5.....<-------your cursor at 5
.....6.....
...... | By default, the matched text in a substitution, won't be captured into a register, however it will always be available as atom `&` in the replace part of your `:s` command.
Having said that, you can of course store the matched text inside a specific register using the special atom [`\=`](https://vimhelp.org/change.txt... |
19,553 | <p>POD is a markup format that is used by Perl. It's sometimes found <a href="https://metacpan.org/pod/distribution/perl/pod/perlpod.pod#Embedding-Pods-in-Perl-Modules" rel="nofollow noreferrer">embedded within the code</a>. You can find more information on it from the official docs on <a href="https://metacpan.org/pod... | [
{
"answer_id": 19554,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 2,
"selected": false,
"text": "<p>You can do the following mappings:</p>\n\n<pre><code>\" *D*elete *P*od\nnnoremap <leader>dp gg/^=[^\\s]<cr&g... | 2019/04/12 | [
"https://vi.stackexchange.com/questions/19553",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5078/"
] | POD is a markup format that is used by Perl. It's sometimes found [embedded within the code](https://metacpan.org/pod/distribution/perl/pod/perlpod.pod#Embedding-Pods-in-Perl-Modules). You can find more information on it from the official docs on [`perlpod`](https://metacpan.org/pod/perlpod), and [`perlpodspec`](https:... | Just use an ex command with searches for ranges:
```
:/^=[^\s]/,/^=cut/ delete
```
Repeat with `@:`. Or, for the whole file,
```
:g/^=[^\s]/,/^=cut/ delete
```
You can make it a hotkey with `dp`
```
:nnoremap <leader>dp :g/^=[^\s]/,/^=cut/ delete<cr>
``` |
19,575 | <p>I have some long text on Yank var
e.g. "Hello all how are you ?"</p>
<p>I have a rectangular selection between abc and ABC <code>/a llC-vjj</code></p>
<pre><code>a A
b B
C C
</code></pre>
<p>And I want to past my long text without having to type it</p>
<p>To get this:</p>
<pre><code>a Hello all how are you... | [
{
"answer_id": 19590,
"author": "joanis",
"author_id": 21446,
"author_profile": "https://vi.stackexchange.com/users/21446",
"pm_score": 2,
"selected": false,
"text": "<p><strong>TL;DR</strong></p>\n\n<p>You can accomplish this by using <code>q</code> to record a sequence of operations an... | 2019/04/14 | [
"https://vi.stackexchange.com/questions/19575",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16022/"
] | I have some long text on Yank var
e.g. "Hello all how are you ?"
I have a rectangular selection between abc and ABC `/a llC-vjj`
```
a A
b B
C C
```
And I want to past my long text without having to type it
To get this:
```
a Hello all how are you ? A
b Hello all how are you ? B
c Hello all how are you ? C
```
... | **TL;DR**
You can accomplish this by using `q` to record a sequence of operations and `@` to replay it.
**Assumptions**
I think you want this output:
```
a Hello all how are you ? A
b Hello all how are you ? B
c Hello all how are you ? C
```
A paste like you describe would be quite a useful feature, I agree, but ... |
19,576 | <p>I want my vim statusline to have some color and I can't figure out why it does not with this code:</p>
<pre><code>set laststatus=2
set statusline+=%1*\ %f\ %*
set statusline+=%2*\ %<%F%*
set statusline+=%2*%m%*
set statusline+=%=
set statusline+=%1*%=%5l%*
set statusline+=%2*/%L%*
hi User1 guifg=#eea040 guibg=%2... | [
{
"answer_id": 19577,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>according to <code>:h gui-colors</code></p>\n\n<pre><code> You can also specify a color by its Red, Green and Blue ... | 2019/04/14 | [
"https://vi.stackexchange.com/questions/19576",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21794/"
] | I want my vim statusline to have some color and I can't figure out why it does not with this code:
```
set laststatus=2
set statusline+=%1*\ %f\ %*
set statusline+=%2*\ %<%F%*
set statusline+=%2*%m%*
set statusline+=%=
set statusline+=%1*%=%5l%*
set statusline+=%2*/%L%*
hi User1 guifg=#eea040 guibg=%222222
hi User2 gu... | according to `:h gui-colors`
```
You can also specify a color by its Red, Green and Blue values.
The format is "#rrggbb", where
"rr" is the Red value
"gg" is the Green value
"bb" is the Blue value
All values are hexadecimal, range from "00" to "ff". Examples: >
:highligh... |
19,578 | <p>I have 50 lines of code</p>
<pre class="lang-php prettyprint-override"><code>private const CODE = 0;
private const DESC = 1;
// ...
private const TRIM = 19; // instead of 24
private const SMURF = 35; // instead of 25
private const DOG = 31; // instead of 26
// ...
private const CAT = 49;
private const AMOUNT = 50... | [
{
"answer_id": 19577,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>according to <code>:h gui-colors</code></p>\n\n<pre><code> You can also specify a color by its Red, Green and Blue ... | 2019/04/15 | [
"https://vi.stackexchange.com/questions/19578",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13172/"
] | I have 50 lines of code
```php
private const CODE = 0;
private const DESC = 1;
// ...
private const TRIM = 19; // instead of 24
private const SMURF = 35; // instead of 25
private const DOG = 31; // instead of 26
// ...
private const CAT = 49;
private const AMOUNT = 50;
```
As you can see, numbers are not sorted ri... | according to `:h gui-colors`
```
You can also specify a color by its Red, Green and Blue values.
The format is "#rrggbb", where
"rr" is the Red value
"gg" is the Green value
"bb" is the Blue value
All values are hexadecimal, range from "00" to "ff". Examples: >
:highligh... |
19,587 | <p>When writing code, I often have code of the form</p>
<p><code>variableA operator variableB</code></p>
<p>and I would like to edit it to be</p>
<p><code>variableB operator variableA.</code></p>
<p>Right now, I do this by deleting/pasting <code>variableB</code> to be in front of <code>variableA</code> and then del... | [
{
"answer_id": 19577,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>according to <code>:h gui-colors</code></p>\n\n<pre><code> You can also specify a color by its Red, Green and Blue ... | 2019/04/15 | [
"https://vi.stackexchange.com/questions/19587",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18196/"
] | When writing code, I often have code of the form
`variableA operator variableB`
and I would like to edit it to be
`variableB operator variableA.`
Right now, I do this by deleting/pasting `variableB` to be in front of `variableA` and then deleting/pasting `operator` to be in between them. Is there a slicker way to d... | according to `:h gui-colors`
```
You can also specify a color by its Red, Green and Blue values.
The format is "#rrggbb", where
"rr" is the Red value
"gg" is the Green value
"bb" is the Blue value
All values are hexadecimal, range from "00" to "ff". Examples: >
:highligh... |
19,597 | <p>A plugin I've recently started maintaining currently checks to see if any bindings exist to its functions before creating the default ones. This makes it easy to setup custom bindings and not have to do anything about the default ones.</p>
<pre><code>if !hasmapto('<Plug>MyFunction', 'n')
nmap <buffer&g... | [
{
"answer_id": 19600,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": true,
"text": "<p>You can use the <a href=\"http://vimhelp.appspot.com/eval.txt.html#mapcheck%28%29\" rel=\"nofollow noreferrer\"><cod... | 2019/04/16 | [
"https://vi.stackexchange.com/questions/19597",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/267/"
] | A plugin I've recently started maintaining currently checks to see if any bindings exist to its functions before creating the default ones. This makes it easy to setup custom bindings and not have to do anything about the default ones.
```
if !hasmapto('<Plug>MyFunction', 'n')
nmap <buffer> <Leader>f <Plug>MyFunct... | You can use the [`mapcheck()`](http://vimhelp.appspot.com/eval.txt.html#mapcheck%28%29) function to check if the user mapped a key to something:
```
:echo json_encode(mapcheck('<F1>', 'n'))
""
:echo mapcheck('<F11>', 'n')
:set cursorcolumn!<CR>:set cursorcolumn?<CR>
```
So in your mapping, you can do:
```
if !hasm... |
19,598 | <p>To find errors in a latex document, I open vim on the .log file. Then I type manually</p>
<pre><code>/^l\.\|[Ee]rr\|[Ww]ar followed by RETURN
</code></pre>
<p>This extended regular expression works well. It matches a line starting with ell followed by a fullstop (period) OR the word "error", possibly capitalized O... | [
{
"answer_id": 19599,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 1,
"selected": false,
"text": "<p>your mapping should be:</p>\n\n<pre><code>nnoremap % /^l\\.\\|[Ee]rr\\|[Ww]ar<CR>\n</code></pre>\n\n<p><code>&l... | 2019/04/16 | [
"https://vi.stackexchange.com/questions/19598",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21842/"
] | To find errors in a latex document, I open vim on the .log file. Then I type manually
```
/^l\.\|[Ee]rr\|[Ww]ar followed by RETURN
```
This extended regular expression works well. It matches a line starting with ell followed by a fullstop (period) OR the word "error", possibly capitalized OR the word "warning", poss... | your mapping should be:
```
nnoremap % /^l\.\|[Ee]rr\|[Ww]ar<CR>
```
`<CR>` is a carriage return, your "enter key".
And `nnoremap` instead of `map` so that it is done only in Normal mode and does not recursively calls mappings if anything in your mapping is itself a mapping. |
19,607 | <p>I'm familiar with vertical blocks, and I often <code>ctrl+v</code> <code>down</code> <code>down</code> <code>down</code> <code>shift+I</code> <code>foobar</code> <code>esc</code> to write foobar in various locations at once.
This is useful if I want to replace <code><td></code> to <code><th></code> in a... | [
{
"answer_id": 19608,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 3,
"selected": true,
"text": "<p>Aside from the suggested plugin <code>vim-multiple-cursors</code>, you have different options:</p>\n\n<p>For example y... | 2019/04/16 | [
"https://vi.stackexchange.com/questions/19607",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21826/"
] | I'm familiar with vertical blocks, and I often `ctrl+v` `down` `down` `down` `shift+I` `foobar` `esc` to write foobar in various locations at once.
This is useful if I want to replace `<td>` to `<th>` in a chain, for instance.
Since not all the text blocks are of equal size, I don't know how to do the same for `</td>... | Aside from the suggested plugin `vim-multiple-cursors`, you have different options:
For example you can go on the parent tag (`tr` I guess?) and visual select in the tag:
```
vit
```
Then do a substitution in the `tr` tag only:
```
:'<,'>s/td/th/g
```
If you want to do a more complex change than a substitution, ... |
19,611 | <p>I use Vim on windows (not gVim) because I think, that windows menu bar is ugly. So I use Vim, but I cannot fullscreen it. When I try it caps at cmd max size (1/4 size of screen) and won't be bigger.</p>
<p>Is there a way to either:</p>
<ul>
<li>make Vim fullscreen</li>
</ul>
<p>or</p>
<ul>
<li>hide menu bar from... | [
{
"answer_id": 19614,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>I believe that it's not Vim that you can't fullscreen: Vim in terminal mode runs in a terminal emulator. On Windows I thi... | 2019/04/16 | [
"https://vi.stackexchange.com/questions/19611",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21827/"
] | I use Vim on windows (not gVim) because I think, that windows menu bar is ugly. So I use Vim, but I cannot fullscreen it. When I try it caps at cmd max size (1/4 size of screen) and won't be bigger.
Is there a way to either:
* make Vim fullscreen
or
* hide menu bar from gVim? | I believe that it's not Vim that you can't fullscreen: Vim in terminal mode runs in a terminal emulator. On Windows I think you can't make the console go full screen so this is absolutely not related to Vim.
However if you want to remove the menu bar from gVim you can read [`:h 'guioptions'`](http://vimhelp.appspot.co... |
19,639 | <p>If <code>git</code> is performing a 3-way merge and has a conflict it can't resolve, it marks up that area of the file like this:</p>
<pre><code>No unresolvable conflicts here
<<<<<<< HEAD
xyz
||||||| parent of ...
abc
=======
123
>>>>>>> ...
</code></pre>
<p>Is there a wa... | [
{
"answer_id": 19760,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 4,
"selected": true,
"text": "<p>In your Vim config, you can do the following (change the colors and styling to your liking):</p>\n\n<pre><code>functio... | 2019/04/17 | [
"https://vi.stackexchange.com/questions/19639",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8071/"
] | If `git` is performing a 3-way merge and has a conflict it can't resolve, it marks up that area of the file like this:
```
No unresolvable conflicts here
<<<<<<< HEAD
xyz
||||||| parent of ...
abc
=======
123
>>>>>>> ...
```
Is there a way (and, if so, how) to change the background color of these 3 "sections":
* `<... | In your Vim config, you can do the following (change the colors and styling to your liking):
```
function! ConflictsHighlight() abort
syn region conflictStart start=/^<<<<<<< .*$/ end=/^\ze\(=======$\||||||||\)/
syn region conflictMiddle start=/^||||||| .*$/ end=/^\ze=======$/
syn region conflictEnd start=... |
19,651 | <p>I was wondering what is the proper way to test whether a substring is included in some other string. If I want to check if string <code>a</code> is part of string <code>b</code>, I'm currently using </p>
<pre><code>matchstr(b, a) != ""
</code></pre>
<p>to check if a is a substring of b. Is there a more "proper" wa... | [
{
"answer_id": 19652,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 5,
"selected": true,
"text": "<p>For this there is the function <code>stridx()</code>.</p>\n\n<pre><code>let a = \"Vi and Vim\"\nlet b = \"and\"\necho str... | 2019/04/19 | [
"https://vi.stackexchange.com/questions/19651",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21269/"
] | I was wondering what is the proper way to test whether a substring is included in some other string. If I want to check if string `a` is part of string `b`, I'm currently using
```
matchstr(b, a) != ""
```
to check if a is a substring of b. Is there a more "proper" way of doing it, since this seems like a bit of a ... | For this there is the function `stridx()`.
```
let a = "Vi and Vim"
let b = "and"
echo stridx(a, b)
" echos 3
```
If the substring is not found `stridx()` returns `-1`.
The function also supports a third argument to specify the start index to search from.
See `:help stridx()`. |
19,653 | <p>I would like to extract a list of distinct words from a set of lines. Is there a way of doing this ?</p>
<p>Say for example I have lines that look like this:</p>
<pre><code>[
[(isPhysicallySettledFxFwd, NO,"Y"),(isPhysicallySettledFxFwd,isPhysicallySettledFxSwap,"N")],
[(isPhysicallySettledFxSwap,NO,"Y"),(isPhysic... | [
{
"answer_id": 19654,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": true,
"text": "<p>You can do something like this:</p>\n\n<pre><code>:let a=[]\n:%s/\\w\\+/\\=add(a, submatch(0))/gn\n:new\n:put =un... | 2019/04/19 | [
"https://vi.stackexchange.com/questions/19653",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21293/"
] | I would like to extract a list of distinct words from a set of lines. Is there a way of doing this ?
Say for example I have lines that look like this:
```
[
[(isPhysicallySettledFxFwd, NO,"Y"),(isPhysicallySettledFxFwd,isPhysicallySettledFxSwap,"N")],
[(isPhysicallySettledFxSwap,NO,"Y"),(isPhysicallySettledFxSwap, is... | You can do something like this:
```
:let a=[]
:%s/\w\+/\=add(a, submatch(0))/gn
:new
:put =uniq(sort(a))
```
This will first declare a list `a` to work with. Then we run a `:%s` command, to capture all word-characters (`\w\+`) and act on all matches (`g` flag of the `:s` command), but won't actually replace (`n` fla... |
19,656 | <p>I'm trying to modify this file, by extracting the very <em>first</em> line in the file and prepend it to each of the consecutive lines until end of the file</p>
<pre><code>black
widow
card
Friday
berry
</code></pre>
<p>I used <code>ex</code> command (which doesn't work as expected) which prepends the string <code>... | [
{
"answer_id": 19660,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 2,
"selected": false,
"text": "<p>You can use registers (see <code>:h reg</code>) to store a word of a line. For you particular case, you would have to pe... | 2019/04/19 | [
"https://vi.stackexchange.com/questions/19656",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21865/"
] | I'm trying to modify this file, by extracting the very *first* line in the file and prepend it to each of the consecutive lines until end of the file
```
black
widow
card
Friday
berry
```
I used `ex` command (which doesn't work as expected) which prepends the string `black` from 2nd line onward without deleting the ... | @D.BenKnoble has already given you a terrific answer explaining all the ins and outs of batch mode, but in case you were looking for a one liner similar to the one you already tried, here's one that I think is a bit simpler than the existing ones in the current answers:
```
ex -sc 'norm!ggy$dd' -c '%norm!i^R0: ' -c 'x... |
19,672 | <p>When I do <code>Vi{y</code> to select inside a <code>{</code> block and yank it, it doesn't paste how I expect.</p>
<p>I noticed that after <code>V</code> (which puts me into VISUAL-LINE mode), the <code>i{</code> object takes me into <code>VISUAL</code> mode.</p>
<p>Here's a gif:</p>
<p><a href="https://i.stack.... | [
{
"answer_id": 19660,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 2,
"selected": false,
"text": "<p>You can use registers (see <code>:h reg</code>) to store a word of a line. For you particular case, you would have to pe... | 2019/04/21 | [
"https://vi.stackexchange.com/questions/19672",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9024/"
] | When I do `Vi{y` to select inside a `{` block and yank it, it doesn't paste how I expect.
I noticed that after `V` (which puts me into VISUAL-LINE mode), the `i{` object takes me into `VISUAL` mode.
Here's a gif:
[](https://i.stack.imgur.com/oQ1Fn.g... | @D.BenKnoble has already given you a terrific answer explaining all the ins and outs of batch mode, but in case you were looking for a one liner similar to the one you already tried, here's one that I think is a bit simpler than the existing ones in the current answers:
```
ex -sc 'norm!ggy$dd' -c '%norm!i^R0: ' -c 'x... |
19,688 | <p>I'm trying to remove the verilog block comment start: <code>/*</code></p>
<p>I'm trying to do this inside a function:</p>
<pre><code>call setline(line('.'), substitute(getline('.'), '/*','',''))
</code></pre>
<p>Of some reason, it doesn't to anything.
I tried to use \V, I tried escaping.
It seems that no matter ... | [
{
"answer_id": 19689,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 3,
"selected": true,
"text": "<ul>\n<li><p>You can use normal <code>:h :substitute</code> ex-command:</p>\n\n<pre><code>s:/\\*::\n</code></pre></li>\n<li>... | 2019/04/22 | [
"https://vi.stackexchange.com/questions/19688",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19833/"
] | I'm trying to remove the verilog block comment start: `/*`
I'm trying to do this inside a function:
```
call setline(line('.'), substitute(getline('.'), '/*','',''))
```
Of some reason, it doesn't to anything.
I tried to use \V, I tried escaping.
It seems that no matter what I do, it never removes the comment.
Th... | * You can use normal `:h :substitute` ex-command:
```
s:/\*::
```
* You can use setline in the following manner:
```
call setline(line('.'), substitute(getline('.'), "/\\*", '', ''))
```
* Or you can use `:h substitute()` in the following manner:
```
call setline(line('.'), substitute(getline('.'), '/\*', '', ''))... |
19,690 | <p>I'm looking for a good way to generate lists that are automatically bulleted. I tried the markdown plugin. It generates bullets automatically but not numbered lists. I also tried the vim-pandoc plugin which handles markdown but it doesn't do automated bullets or numbers.</p>
<p>Thanks.</p>
| [
{
"answer_id": 19689,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 3,
"selected": true,
"text": "<ul>\n<li><p>You can use normal <code>:h :substitute</code> ex-command:</p>\n\n<pre><code>s:/\\*::\n</code></pre></li>\n<li>... | 2019/04/22 | [
"https://vi.stackexchange.com/questions/19690",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2021/"
] | I'm looking for a good way to generate lists that are automatically bulleted. I tried the markdown plugin. It generates bullets automatically but not numbered lists. I also tried the vim-pandoc plugin which handles markdown but it doesn't do automated bullets or numbers.
Thanks. | * You can use normal `:h :substitute` ex-command:
```
s:/\*::
```
* You can use setline in the following manner:
```
call setline(line('.'), substitute(getline('.'), "/\\*", '', ''))
```
* Or you can use `:h substitute()` in the following manner:
```
call setline(line('.'), substitute(getline('.'), '/\*', '', ''))... |
19,694 | <p>I'm doing some string processing in vimscript. I obtained a <strong>byte</strong> index for a character in the string and now want to obtain the character at that byte index.
For single-byte charsets (like latin1) this is not a problem:</p>
<pre><code>let char = string[offset]
</code></pre>
<p>But what if the stri... | [
{
"answer_id": 19707,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 2,
"selected": false,
"text": "<p>To answer my own question:</p>\n\n<p>1) There is no internal function to get a character at a <strong>byte</strong> offs... | 2019/04/22 | [
"https://vi.stackexchange.com/questions/19694",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19763/"
] | I'm doing some string processing in vimscript. I obtained a **byte** index for a character in the string and now want to obtain the character at that byte index.
For single-byte charsets (like latin1) this is not a problem:
```
let char = string[offset]
```
But what if the string is (potentially) multi-byte?
I impl... | Patch 8.2.2233 introduced the charidx() function that returns the character index given the byte index in a string. You can pass this index to the strgetchar() function to get the character at that index. |
19,698 | <p>I have a .cpp file in which I would like to change all less-than symbols to double quotes but maintain any instances of double-greater-than symbols, i.e. change < to " while leaving all occurrences of << alone.</p>
<p>I am very new to vim and as such am still trying to figure out the best way to replace ch... | [
{
"answer_id": 19702,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 0,
"selected": false,
"text": "<p>It's tricky to match single <code><</code>, you have to consider behind and after character, which might also be st... | 2019/04/22 | [
"https://vi.stackexchange.com/questions/19698",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21914/"
] | I have a .cpp file in which I would like to change all less-than symbols to double quotes but maintain any instances of double-greater-than symbols, i.e. change < to " while leaving all occurrences of << alone.
I am very new to vim and as such am still trying to figure out the best way to replace characters in situati... | Just to make an answer out of my comment above: you could substitute all ocurences of `<` without a successor `<`:
```
%s/\(^\|[^<]\)<\($\|[^<]\)/\1"\2/g
```
Or, using the very-magic flag, as suggested by @d-ben-knoble:
```
%s/\v(^|[^<])\<($|[^<])/\1"\2/g
```
That means:
`%s` substitute in all lines
`/\v` start... |
19,735 | <p>I move around using the arrows ←↓↑→, never really got used to the hjkl thing. I know I'm supposed to use the hjkl thing.</p>
<p>When hitting ↓, it reaches a point where the caret is on the lower side of the display, until I hit some ↑ hits.</p>
<p>Most of the time I need more context down. How do you move the doc ... | [
{
"answer_id": 19737,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You're looking for <a href=\"http://vimhelp.appspot.com/options.txt.html#%27scrolloff%27\" rel=\"noreferrer\"><code>:h 's... | 2019/04/25 | [
"https://vi.stackexchange.com/questions/19735",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13260/"
] | I move around using the arrows ←↓↑→, never really got used to the hjkl thing. I know I'm supposed to use the hjkl thing.
When hitting ↓, it reaches a point where the caret is on the lower side of the display, until I hit some ↑ hits.
Most of the time I need more context down. How do you move the doc down while not mo... | You're looking for [`:h 'scrolloff'`](http://vimhelp.appspot.com/options.txt.html#%27scrolloff%27):
```
'scrolloff' 'so' number (default 0)
global
Minimal number of screen lines to keep above and below the cursor.
```
So you can add something like this in your `.vimrc`:
```
set scrolloff=10
``` |
19,738 | <p>I use <a href="https://github.com/ludovicchabant/vim-gutentags" rel="nofollow noreferrer">gutentags</a> and <a href="https://github.com/skywind3000/gutentags_plus" rel="nofollow noreferrer">gutentags-plus</a> for generating and managing tag files. When I use the key combinations setup by them ( cX usually ), it open... | [
{
"answer_id": 19743,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<p>To close the quickfix window, you use <code>:cclose</code>, as @statox mentioned in the comments.</p>\n<p>This won't affect w... | 2019/04/25 | [
"https://vi.stackexchange.com/questions/19738",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21955/"
] | I use [gutentags](https://github.com/ludovicchabant/vim-gutentags) and [gutentags-plus](https://github.com/skywind3000/gutentags_plus) for generating and managing tag files. When I use the key combinations setup by them ( cX usually ), it opens the relevant lines in a quickfix window and I can use :cnext etc for naviga... | To close the quickfix window, you use `:cclose`, as @statox mentioned in the comments.
This won't affect which code buffer you're viewing, though. Vim doesn't distinguish between the buffer you were looking at originally and the buffers you navigated to via the quickfix, so to go back you are going to have to use Vim'... |
19,751 | <p>I am given an account on a new server these days. The new server does not have x11 install, neither do I have sudo. So I cannot install system packages, and I cannot compile with the option <code>-with-x</code>. </p>
<p>But I still want to use vim when I am working on my server, and I need to use the clipboard feat... | [
{
"answer_id": 20330,
"author": "bk2204",
"author_id": 22677,
"author_profile": "https://vi.stackexchange.com/users/22677",
"pm_score": 1,
"selected": false,
"text": "<p>If you want to use the clipboard directly from Vim, you'll need a version compiled with either the <code>+clipboard</c... | 2019/04/26 | [
"https://vi.stackexchange.com/questions/19751",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18259/"
] | I am given an account on a new server these days. The new server does not have x11 install, neither do I have sudo. So I cannot install system packages, and I cannot compile with the option `-with-x`.
But I still want to use vim when I am working on my server, and I need to use the clipboard feature to allow me to co... | ### Checking for X11-clipboard support in terminal
From the console, type:
```
vim --version | grep clipboard
```
If you see `+clipboard` or `+xterm_clipboard`, you are good to go. If it's `-clipboard` and `-xterm_clipboard`, you will need to look for a version of Vim that was compiled with clipboard support.
### ... |
19,753 | <p>I want to search lines beginning with certain string in Vim, and then add something at the end of file. I have tried the following but it removed everything instead of appending</p>
<pre><code>:%s/^12138/*something_at_end_of_file/g
</code></pre>
<p>This search all lines which begin with <code>12138</code> but it r... | [
{
"answer_id": 19755,
"author": "João A. Toledo",
"author_id": 11384,
"author_profile": "https://vi.stackexchange.com/users/11384",
"pm_score": 2,
"selected": false,
"text": "<p>You may try this:</p>\n\n<pre><code>%s/\\v^(12138.*)/\\1something_at_end_of_line/g\n</code></pre>\n\n<p>That m... | 2019/04/26 | [
"https://vi.stackexchange.com/questions/19753",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21179/"
] | I want to search lines beginning with certain string in Vim, and then add something at the end of file. I have tried the following but it removed everything instead of appending
```
:%s/^12138/*something_at_end_of_file/g
```
This search all lines which begin with `12138` but it removes everything and add `something_... | use the `:g` command:
```
:g/^12138/s/something-at-the-end$/something-new-at-the-end/
```
More information on `:help :g` |
19,767 | <p>I'm trying to determine how many <code>#</code> characters are at the beginning of a line.</p>
<p>In perl, I can so something like this:</p>
<pre><code>$match =~ m/^(#+)[^#])/;
$length = length $1;
</code></pre>
<p>Trying to do something similar in vim:</p>
<pre><code>getline(a:lnum) =~ '\v^(#+)[^#]'
let length ... | [
{
"answer_id": 19755,
"author": "João A. Toledo",
"author_id": 11384,
"author_profile": "https://vi.stackexchange.com/users/11384",
"pm_score": 2,
"selected": false,
"text": "<p>You may try this:</p>\n\n<pre><code>%s/\\v^(12138.*)/\\1something_at_end_of_line/g\n</code></pre>\n\n<p>That m... | 2019/04/27 | [
"https://vi.stackexchange.com/questions/19767",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2021/"
] | I'm trying to determine how many `#` characters are at the beginning of a line.
In perl, I can so something like this:
```
$match =~ m/^(#+)[^#])/;
$length = length $1;
```
Trying to do something similar in vim:
```
getline(a:lnum) =~ '\v^(#+)[^#]'
let length = strlen \1
```
I believe the `\v` allows me to write... | use the `:g` command:
```
:g/^12138/s/something-at-the-end$/something-new-at-the-end/
```
More information on `:help :g` |
19,793 | <p>I have a file that looks similar to this:</p>
<pre><code>module.exports = {
blank: {
area: 'frontend',
name: 'Magento/blank',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
'css/email',
'css/email-inline'
],
... | [
{
"answer_id": 19794,
"author": "Krzysztof Wołowski",
"author_id": 22027,
"author_profile": "https://vi.stackexchange.com/users/22027",
"pm_score": 0,
"selected": false,
"text": "<p>Thank you guys for the answers. <code>awk</code> (<code>gawk</code> in this particular case) is indeed the... | 2019/04/30 | [
"https://vi.stackexchange.com/questions/19793",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22027/"
] | I have a file that looks similar to this:
```
module.exports = {
blank: {
area: 'frontend',
name: 'Magento/blank',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
'css/email',
'css/email-inline'
],
dsl: 'less'... | The problem isn't the `\r` characters in your string, but the fact that the string *also* contains literal newline characters, and Vim is including these in the replacement [as NUL characters](https://stackoverflow.com/a/12389839/328936) after the linebreaks. If you remove the latter from your bash script, then the rep... |
19,810 | <p>Say I've got three splits open with code in, and I suddenly want to make the one I'm in fullscreen, temporarily. How can I do that?</p>
| [
{
"answer_id": 19811,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 4,
"selected": true,
"text": "<p>When focused on it, run:</p>\n\n<pre><code>:tabe %\n</code></pre>\n\n<p>To open a new tab with the same file. You can ... | 2019/05/01 | [
"https://vi.stackexchange.com/questions/19810",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13555/"
] | Say I've got three splits open with code in, and I suddenly want to make the one I'm in fullscreen, temporarily. How can I do that? | When focused on it, run:
```
:tabe %
```
To open a new tab with the same file. You can navigate tabs with `gT` and `gt` among other, if you want to go back to your split.
Once you are done with it, on the "fullscreen" one, run:
```
:q
```
to close the tab (technically closes the focused window, which is the only... |
19,828 | <p>I have been trying to make UltiSnips work with VimWiki to no avail, as they share mappings for expand snippet/next link (on <code><tab></code>).</p>
<p>I tried setting VimWiki's bindings to something else by using the following, which sadly didn't work, as the snippets didn't expand:</p>
<pre><code>" vimwiki... | [
{
"answer_id": 19894,
"author": "Tomáš Sláma",
"author_id": 22081,
"author_profile": "https://vi.stackexchange.com/users/22081",
"pm_score": 1,
"selected": true,
"text": "<p>The solution to this issue can be found in <a href=\"https://github.com/vimwiki/vimwiki/issues/357\" rel=\"nofollo... | 2019/05/03 | [
"https://vi.stackexchange.com/questions/19828",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22081/"
] | I have been trying to make UltiSnips work with VimWiki to no avail, as they share mappings for expand snippet/next link (on `<tab>`).
I tried setting VimWiki's bindings to something else by using the following, which sadly didn't work, as the snippets didn't expand:
```
" vimwiki plugin settings
filetype plugin on
le... | The solution to this issue can be found in [this thread](https://github.com/vimwiki/vimwiki/issues/357).
The only thing one has to do is to add this line to `~/.vimrc`, which allows to both use Tab in normal mode to cycle through links, and to expand links in Insert mode:
`let g:vimwiki_table_mappings = 0` |
19,836 | <p>I've opened an empty buffer with just <code>vim</code>.</p>
<p>I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout.</p>
<p>In my empty buffer, I wrote the following.</p>
<pre><code>select * from foo;
</code></pre>
<p>I want to pass the ... | [
{
"answer_id": 19837,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "<p>Two methods you tried:</p>\n\n<ul>\n<li><code>% !exec-sql.sh</code>\n<a href=\"https://vimhelp.org/change.txt.html#%3A... | 2019/05/04 | [
"https://vi.stackexchange.com/questions/19836",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22095/"
] | I've opened an empty buffer with just `vim`.
I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout.
In my empty buffer, I wrote the following.
```
select * from foo;
```
I want to pass the entire contents of the file over to my script, `exe... | Two methods you tried:
* `% !exec-sql.sh`
[:h :range!](https://vimhelp.org/change.txt.html#%3Arange%21) filter {range} lines through the external program. also check [:h !](https://vimhelp.org/change.txt.html#%21) .
* `w !exec-sql.sh`
[:h :w\_c](https://vimhelp.org/editing.txt.html#%3Aw_c) execute {cmd} with [range] l... |
19,841 | <p>By default, vim lets you type 5G (5 then shift + g) to go to line 5. Instead, I don't want to have to press the shift key. Pressing <code><S-g></code> does something different than just <code>5<S-g></code>. How can I remap a command that takes a number for repeated executions?</p>
<p>Something like: <co... | [
{
"answer_id": 19842,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 4,
"selected": true,
"text": "<pre><code>nnoremap g G\n</code></pre>\n\n<p>But this will not work well, as there are a lot of key mapping beginning with <... | 2019/05/04 | [
"https://vi.stackexchange.com/questions/19841",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22104/"
] | By default, vim lets you type 5G (5 then shift + g) to go to line 5. Instead, I don't want to have to press the shift key. Pressing `<S-g>` does something different than just `5<S-g>`. How can I remap a command that takes a number for repeated executions?
Something like: `nnoremap <number>g <number>G` | ```
nnoremap g G
```
But this will not work well, as there are a lot of key mapping beginning with `g`. So Vim has to wait a timeout (default 1000 msec) to be sure that no other key is pressed after the `g`. The `g` could be the start of 'gg' or 'g$' or ...
So after you pressed `5g` nothing will happen for one seco... |
19,853 | <p>I wrote a function for selecting a text region and replacing in it certain predefined characters:</p>
<pre><code>fun! Tstrepl() range
s/\%Va/\="\u2227"/ge " 'a' to '∧'
s/\%Vb/\="\u2228"/ge " 'b' to '∨'
endfun
vnoremap QQ :call Tstrepl()<CR>
</code></pre>
<p>The problem is that the function doesn't... | [
{
"answer_id": 19859,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 3,
"selected": true,
"text": "<p>I think this is because you use multi-byte characters in the replacement field of the substitution commands. And be... | 2019/05/05 | [
"https://vi.stackexchange.com/questions/19853",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1378/"
] | I wrote a function for selecting a text region and replacing in it certain predefined characters:
```
fun! Tstrepl() range
s/\%Va/\="\u2227"/ge " 'a' to '∧'
s/\%Vb/\="\u2228"/ge " 'b' to '∨'
endfun
vnoremap QQ :call Tstrepl()<CR>
```
The problem is that the function doesn't behave as expected and I cannot... | I think this is because you use multi-byte characters in the replacement field of the substitution commands. And because Vim – probably – keeps track of the start/end of the visual selection via *byte* indexes (not character indexes). When you replace a character whose weight is 1 byte, with a character whose weight is... |
19,860 | <p>For setting breakpoints, I was wondering if there is any way to copy the location of a line in a file opened in vim, to gdb rather than typing the whole file path and linenumber in the gdb shell?</p>
| [
{
"answer_id": 19861,
"author": "In78",
"author_id": 4513,
"author_profile": "https://vi.stackexchange.com/users/4513",
"pm_score": 0,
"selected": false,
"text": "<p>I have found one way which is to use the : terminal feature of vim to start a new shell, run gdb in it and paste the filen... | 2019/05/05 | [
"https://vi.stackexchange.com/questions/19860",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4513/"
] | For setting breakpoints, I was wondering if there is any way to copy the location of a line in a file opened in vim, to gdb rather than typing the whole file path and linenumber in the gdb shell? | Good, since you're using `tmux` then you can use `send-keys` (alias: `send`), a tmux command for inputting text into a different pane than the current one. You can call it from Vim using whatever data you need from there. For current (full) path and line number that would be `expand('%:p')` and `line('.')`
The followi... |
19,886 | <p>I'm trying to write a 2D matrix of characters. I can get a string of random characters with <code>pwgen 4 1</code>, for example. That gives me something like this.</p>
<pre><code>ia6e
</code></pre>
<p>Is there a way to split this string up by characters in vanilla Vim? I need to quote each individual character and... | [
{
"answer_id": 19887,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 2,
"selected": true,
"text": "<p>Would the following substitutions help you?</p>\n\n<pre><code>:s/\\(.\\)/'\\1', /g\n:s/, $//\n</code></pre>\n\n<p>The ... | 2019/05/08 | [
"https://vi.stackexchange.com/questions/19886",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22095/"
] | I'm trying to write a 2D matrix of characters. I can get a string of random characters with `pwgen 4 1`, for example. That gives me something like this.
```
ia6e
```
Is there a way to split this string up by characters in vanilla Vim? I need to quote each individual character and put some spaces in between. Eventual... | Would the following substitutions help you?
```
:s/\(.\)/'\1', /g
:s/, $//
```
The first wraps all the characters with quotes and with comma and space afterwards (in the current line only).
The second removes the last comma and space from the line (again, current line only). |
19,896 | <p>In the help for move:</p>
<pre><code>:[range]m[ove] {address} *:m* *:mo* *:move* *E134*
Move the lines given by [range] to below the line
given by {address}.
</code></pre>
<p>and help for address:</p>
<pre><code>Line numbers may be specified w... | [
{
"answer_id": 19897,
"author": "Jürgen Krämer",
"author_id": 2636,
"author_profile": "https://vi.stackexchange.com/users/2636",
"pm_score": 3,
"selected": true,
"text": "<p>The behavior is correct. When you move a line down below the next line (which means two lines down) your original ... | 2019/05/08 | [
"https://vi.stackexchange.com/questions/19896",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22159/"
] | In the help for move:
```
:[range]m[ove] {address} *:m* *:mo* *:move* *E134*
Move the lines given by [range] to below the line
given by {address}.
```
and help for address:
```
Line numbers may be specified with: *:range* *E14* *{add... | The behavior is correct. When you move a line down below the next line (which means two lines down) your original line is deleted afterwards, thus resulting in a new location which is only one line down from its original location. |
19,907 | <p>I'm trying to <a href="https://stackoverflow.com/questions/56064538/how-to-separate-erroneously-combined-words-in-ocred-text">bulk correct some OCR formatting issues</a>. I tried recording a macro that would:</p>
<ol>
<li><code>]s</code> (advance to the next spelling error)</li>
<li><code>z=</code> (view the sugges... | [
{
"answer_id": 19908,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 1,
"selected": false,
"text": "<p>First assign the macro. Lets use register <code>s</code>:</p>\n\n<pre><code>:let @s=\"]sz=1\\<cr>\"\n</code></pre>... | 2019/05/09 | [
"https://vi.stackexchange.com/questions/19907",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22180/"
] | I'm trying to [bulk correct some OCR formatting issues](https://stackoverflow.com/questions/56064538/how-to-separate-erroneously-combined-words-in-ocred-text). I tried recording a macro that would:
1. `]s` (advance to the next spelling error)
2. `z=` (view the suggested corrections)
3. `1` (choose the first suggested ... | The simple answer is to use a count as @Mass and @D.BenKnoble suggest:
1. `]s`
2. `1z=`
But let's take a closer look at why your original macro was failing, because it's not quite as simple as @Ralf implies.
First try recording your steps into register `"r`:
`q``r``]``s``z``=``1``Enter``q`
Then use @Ralf's `:let` ... |
19,911 | <p>Tried </p>
<pre><code>:s/\\\/\\/g
</code></pre>
<p>but VIM will search for <code>\\/\</code> instead.</p>
<p>So is there any way I can do this in Vim?</p>
| [
{
"answer_id": 19913,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 4,
"selected": true,
"text": "<p>In <code>s/\\\\\\/\\\\/</code>:</p>\n\n<ol>\n<li>the first <code>\\</code> escapes the second <code>\\</code>; </li>\n<li>the... | 2019/05/10 | [
"https://vi.stackexchange.com/questions/19911",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21700/"
] | Tried
```
:s/\\\/\\/g
```
but VIM will search for `\\/\` instead.
So is there any way I can do this in Vim? | In `s/\\\/\\/`:
1. the first `\` escapes the second `\`;
2. the second `\` is escaped, so it's no longer special; and
3. the third `\` isn't escaped, so it escapes the `/` after it.
So you need to escape the third `\` like the second was:
```
:s/\\\\/\\/g
``` |
19,919 | <p>When debugging my vimrc, I often want to log informational messages, e.g. things like "skipping function X because a necessary plugin isn't available". I can use <code>echom</code> statements to do that, but they block. At least, they do under gvim; I get an error window on startup that must be dismissed.</p>
<p>I ... | [
{
"answer_id": 19913,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 4,
"selected": true,
"text": "<p>In <code>s/\\\\\\/\\\\/</code>:</p>\n\n<ol>\n<li>the first <code>\\</code> escapes the second <code>\\</code>; </li>\n<li>the... | 2019/05/11 | [
"https://vi.stackexchange.com/questions/19919",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20175/"
] | When debugging my vimrc, I often want to log informational messages, e.g. things like "skipping function X because a necessary plugin isn't available". I can use `echom` statements to do that, but they block. At least, they do under gvim; I get an error window on startup that must be dismissed.
I want a way to log mes... | In `s/\\\/\\/`:
1. the first `\` escapes the second `\`;
2. the second `\` is escaped, so it's no longer special; and
3. the third `\` isn't escaped, so it escapes the `/` after it.
So you need to escape the third `\` like the second was:
```
:s/\\\\/\\/g
``` |
19,927 | <p>I know that the autocommand <code>autocmd BufEnter</code> will be triggered every time a buffer is entered. Is there a way to define an <code>autocmd</code> that will be triggered only the first time a buffer is entered?</p>
| [
{
"answer_id": 19913,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 4,
"selected": true,
"text": "<p>In <code>s/\\\\\\/\\\\/</code>:</p>\n\n<ol>\n<li>the first <code>\\</code> escapes the second <code>\\</code>; </li>\n<li>the... | 2019/05/11 | [
"https://vi.stackexchange.com/questions/19927",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16602/"
] | I know that the autocommand `autocmd BufEnter` will be triggered every time a buffer is entered. Is there a way to define an `autocmd` that will be triggered only the first time a buffer is entered? | In `s/\\\/\\/`:
1. the first `\` escapes the second `\`;
2. the second `\` is escaped, so it's no longer special; and
3. the third `\` isn't escaped, so it escapes the `/` after it.
So you need to escape the third `\` like the second was:
```
:s/\\\\/\\/g
``` |
19,932 | <p>the goal is to be able to write functions names that follow PEP8 as easily and naturally as writing this sentence.</p>
<p>there are many types of situations that need handling</p>
<ul>
<li>insert <code>_</code> (underscores) for lines that
<ol>
<li>start with <code><optional indentation>def</code></li>
<li>... | [
{
"answer_id": 19933,
"author": "xyx",
"author_id": 15254,
"author_profile": "https://vi.stackexchange.com/users/15254",
"pm_score": 2,
"selected": false,
"text": "<p>This remap <code><space></code> to <code>_</code> if the line starts with <code>def</code>, which is the key to dec... | 2019/05/11 | [
"https://vi.stackexchange.com/questions/19932",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20087/"
] | the goal is to be able to write functions names that follow PEP8 as easily and naturally as writing this sentence.
there are many types of situations that need handling
* insert `_` (underscores) for lines that
1. start with `<optional indentation>def`
2. end with `.<optional_start_of_method_name>`
only when the c... | This remap `<space>` to `_` if the line starts with `def`, which is the key to declare a function in python.
```
inoremap <expr> <space> getline('.')[0:3] == 'def ' ? "_" : "<space>"
```
Try also the autocmd way:
```
autocmd FileType python inoremap <expr> <space> getline('.')[0:3] == 'def ' ? "_" : "<space>"
```
... |
19,945 | <p>Suppose we have the following very simple file:</p>
<pre><code>1 x 3 x
x 3 x 1
</code></pre>
<p>Now I'd like to have a pattern that matches all lines containing <em>both</em> <code>1</code> and <code>3</code>. The order and position should not matter.</p>
<p>(Note that I used a very simple file on purpose. The fi... | [
{
"answer_id": 19946,
"author": "myrdd",
"author_id": 19901,
"author_profile": "https://vi.stackexchange.com/users/19901",
"pm_score": 2,
"selected": false,
"text": "<p>One option is to use a pattern with multiple lookaheads:</p>\n\n<pre><code>magic: ^\\(.*1\\)\\@=\\(.*3\\)\\@=\n ... | 2019/05/14 | [
"https://vi.stackexchange.com/questions/19945",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19901/"
] | Suppose we have the following very simple file:
```
1 x 3 x
x 3 x 1
```
Now I'd like to have a pattern that matches all lines containing *both* `1` and `3`. The order and position should not matter.
(Note that I used a very simple file on purpose. The file could contain many more lines, and the ”words“ could be wor... | Another way is to use [:h /\&](https://vimhelp.org/pattern.txt.html#%2F%5C%26) , it works a bit like `&&` in most coding language:
```
pattern0\&pattern1
```
Above expression will match pattern1 if pattern0 also match at the same position.
To solve your example:
```
\v^(.*1&.*3).*$
```
* `\v` very magic
* `^` st... |
19,966 | <p>I know I can write a buffer to an external program with <code>:w !<command></code>, but is there a way to pipe the contents of the spelling correction list I get with <code>z=</code> into an external program (i.e. dmenu)? If the function(s) behind <code>z=</code> are written in vimscript, can I modify them or... | [
{
"answer_id": 19967,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 2,
"selected": true,
"text": "<p>I don't have <code>dmenu</code> installed, but I tried with <code>zenity</code>: </p>\n\n<pre><code>:echo system(\"zenity... | 2019/05/15 | [
"https://vi.stackexchange.com/questions/19966",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22239/"
] | I know I can write a buffer to an external program with `:w !<command>`, but is there a way to pipe the contents of the spelling correction list I get with `z=` into an external program (i.e. dmenu)? If the function(s) behind `z=` are written in vimscript, can I modify them or is it hard coded ? | I don't have `dmenu` installed, but I tried with `zenity`:
```
:echo system("zenity --list --column=Suggestions 2>/dev/null", spellsuggest(expand("<cword>")))
```
* `expand("<cword>")` expands to the word under the cursor.
* `spellsuggest(...)` returns a list of spelling suggestions
* `system("zenity...", ...)` cal... |
19,978 | <p>I would like to copy several lines with line numbers; the text from <code>set number</code> isn't copied. Is there any way to do this?</p>
| [
{
"answer_id": 19979,
"author": "toraritte",
"author_id": 7706,
"author_profile": "https://vi.stackexchange.com/users/7706",
"pm_score": 3,
"selected": true,
"text": "<p>You have several alternatives. </p>\n\n<ol>\n<li><p><strong>Use the <code>TOhtml</code> command</strong> to let Vim ge... | 2019/05/15 | [
"https://vi.stackexchange.com/questions/19978",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7706/"
] | I would like to copy several lines with line numbers; the text from `set number` isn't copied. Is there any way to do this? | You have several alternatives.
1. **Use the `TOhtml` command** to let Vim generate an HTML file, which includes the line numbers, and then copy and paste from that file.
2. **Replace each line by its line number plus its content**, so you can copy it with the line number. This can be done by visually selecting the li... |
19,988 | <p>If I'm editing a text file with <code>:set spell</code>, is there any way to
have vim not check words within the boundaries of certain characters against the word list? I want to be able to write things like proper nouns or technical vocabulary (or even 'sic' quotations) but not have to add them to the wordlist.</p... | [
{
"answer_id": 19991,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p>You can add your own syntax element (probably overriding existing one):</p>\n\n<pre><code>syntax match quoteblock /\"... | 2019/05/16 | [
"https://vi.stackexchange.com/questions/19988",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22258/"
] | If I'm editing a text file with `:set spell`, is there any way to
have vim not check words within the boundaries of certain characters against the word list? I want to be able to write things like proper nouns or technical vocabulary (or even 'sic' quotations) but not have to add them to the wordlist. | You can add your own syntax element (probably overriding existing one):
```
syntax match quoteblock /"[^"]\+"/ contains=@NoSpell
```
* `syntax match`: Tells vim this is a syntax command
* `quoteblock`: The name of our match (Could be anything)
* `/"..."/`: Match things between quotes
* `[^"]\+`: Match anything that'... |
20,002 | <p>I edit DocBook XML files. In my plugin, i want to implement a function that would increase or decrease the section numbers recursively, assuming that cursor is at the toplevel section. For example, when my cursor is at the top <code><sect2</code> element, it means to turn</p>
<pre><code><sect2>
<sect3&... | [
{
"answer_id": 19991,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p>You can add your own syntax element (probably overriding existing one):</p>\n\n<pre><code>syntax match quoteblock /\"... | 2019/05/17 | [
"https://vi.stackexchange.com/questions/20002",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22283/"
] | I edit DocBook XML files. In my plugin, i want to implement a function that would increase or decrease the section numbers recursively, assuming that cursor is at the toplevel section. For example, when my cursor is at the top `<sect2` element, it means to turn
```
<sect2>
<sect3>
<sect4>
<para>some text</para>
... | You can add your own syntax element (probably overriding existing one):
```
syntax match quoteblock /"[^"]\+"/ contains=@NoSpell
```
* `syntax match`: Tells vim this is a syntax command
* `quoteblock`: The name of our match (Could be anything)
* `/"..."/`: Match things between quotes
* `[^"]\+`: Match anything that'... |
20,005 | <p>I want to create a function like this:</p>
<pre><code>function Foo()
copy something from buffer into a register
do something
restore register
endfunction
</code></pre>
<p><code>Foo</code> must have no side effect, every register should remain the same after you call it, how should i do it?</p>
<p><str... | [
{
"answer_id": 21817,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 3,
"selected": false,
"text": "<p>You've identified most of the issues - I think the best one can do is using the unnamed register, saving its contents... | 2019/05/17 | [
"https://vi.stackexchange.com/questions/20005",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | I want to create a function like this:
```
function Foo()
copy something from buffer into a register
do something
restore register
endfunction
```
`Foo` must have no side effect, every register should remain the same after you call it, how should i do it?
**Attempt**
**unnamed register**
```
function ... | If your Vim contains the patch [8.2.0924](https://github.com/vim/vim/releases/tag/v8.2.0924), then try to use `getreginfo()`:
```
function Foo()
let save_cb = &cb
let regInfo = getreginfo('"')
try
norm! y{motion}
do something
finally
let &cb = save_cb
call setreg('"', re... |
20,015 | <p>Say I have a line <code>1234text5678</code>, where I have selected <code>text</code> in visual mode. I would like to have a command <code><Shift>+</code>, that moves <code>text</code> to the right one character and selects <code>text</code> again. I.e. the result should be <code>12345text678</code>, and <code>... | [
{
"answer_id": 20016,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 0,
"selected": false,
"text": "<pre><code>xnoremap * dp`[v`]\n</code></pre>\n\n<ul>\n<li><code>dp</code> shift right</li>\n<li><code>`[v`]</code> select... | 2019/05/18 | [
"https://vi.stackexchange.com/questions/20015",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Say I have a line `1234text5678`, where I have selected `text` in visual mode. I would like to have a command `<Shift>+`, that moves `text` to the right one character and selects `text` again. I.e. the result should be `12345text678`, and `text` being selected. From playing around, I got
```
xnoremap * dpgv=gv
```
b... | Choice of Mapping
=================
I personnally like to use `v_*` for searching the visually selected text, similar to what `n_*` does in normal mode for the word under the cursor. Using `v_*` for shifting a visual selection sideways is in conflict with [vim-visualstar](https://github.com/thinca/vim-visualstar) whic... |
20,032 | <p>I want to create a function that I can call to replace a specific string pattern with <code>md5sum</code> of current buffer.</p>
<p>I have no experience writing VimL before and can't figure out the way to do it.</p>
<p>This is what I roughly have in my mind:</p>
<pre><code>" Calculate text hash and replace the ol... | [
{
"answer_id": 20016,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 0,
"selected": false,
"text": "<pre><code>xnoremap * dp`[v`]\n</code></pre>\n\n<ul>\n<li><code>dp</code> shift right</li>\n<li><code>`[v`]</code> select... | 2019/05/20 | [
"https://vi.stackexchange.com/questions/20032",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7247/"
] | I want to create a function that I can call to replace a specific string pattern with `md5sum` of current buffer.
I have no experience writing VimL before and can't figure out the way to do it.
This is what I roughly have in my mind:
```
" Calculate text hash and replace the old one
function! HashBuffer()
:redir @... | Choice of Mapping
=================
I personnally like to use `v_*` for searching the visually selected text, similar to what `n_*` does in normal mode for the word under the cursor. Using `v_*` for shifting a visual selection sideways is in conflict with [vim-visualstar](https://github.com/thinca/vim-visualstar) whic... |
20,038 | <p>Suppose I'd like to create a list</p>
<pre><code>- "1"
- "2"
- "3"
</code></pre>
<p>what Is the smartest way to create such?</p>
<p>My attempt would be to <kbd>i</kbd><code>- "1"</code><kbd>ESC</kbd><kbd>yy</kbd><kbd>pp</kbd> to get</p>
<pre><code>- "1"
- "1"
- "1"
</code></pre>
<p>and then jump to the second l... | [
{
"answer_id": 20039,
"author": "padawin",
"author_id": 21621,
"author_profile": "https://vi.stackexchange.com/users/21621",
"pm_score": 1,
"selected": false,
"text": "<p>I would do it as follow:</p>\n\n<ul>\n<li>Somewhere in your file (before where you want your list), add a line with t... | 2019/05/20 | [
"https://vi.stackexchange.com/questions/20038",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19041/"
] | Suppose I'd like to create a list
```
- "1"
- "2"
- "3"
```
what Is the smartest way to create such?
My attempt would be to `i``- "1"``ESC``yy``pp` to get
```
- "1"
- "1"
- "1"
```
and then jump to the second line's 1 `r``2``j``r``3`
BUT: doing this for a list of e.g. 100 (also thinking about the second digit) ... | Depending on your usecase the following might be useful:
Create the entries all with the number "1":
```
- "1"
- "1"
- "1"
- "1"
```
Then go to the second "1" and press `V` to start line-wise visual. Then move down to the last "1". So now all but the first "1" is selected.
Now hit `g``Ctrl-a` and you get
```
- "1... |
20,062 | <p>I have a document that contains lines like</p>
<pre><code>
</code></pre>
<p>This is the format for images in Markdown.</p>
<p>I have constructed a regular expression which I believe should be able to find the image tags:</p>
<pre><code>!\[(.*)\]\((.+)\)
</code></pre>
<p>But when I... | [
{
"answer_id": 20075,
"author": "jarhill0",
"author_id": 22376,
"author_profile": "https://vi.stackexchange.com/users/22376",
"pm_score": 0,
"selected": false,
"text": "<p><a href=\"https://stackoverflow.com/a/1631687/8033766\">Vim doesn't require escaping of parentheses by default</a>.<... | 2019/05/23 | [
"https://vi.stackexchange.com/questions/20062",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22376/"
] | I have a document that contains lines like
```

```
This is the format for images in Markdown.
I have constructed a regular expression which I believe should be able to find the image tags:
```
!\[(.*)\]\((.+)\)
```
But when I try the command `/!\[(.*)\]\((.+)\)`, I get `E486: Patt... | I use "very magic" setting (`\v`) so that I can use normal regex patterns and not have to convert it into vim's awkward regex format.
First, I would do search as the original regex search term, but prepend with `\v` to enable "very magic" regex setting:
```
/\v!\[(.*)\]\((.+)\)
```
After testing it to make sure it ... |
20,078 | <p>I'm looking for functionality which may or may not exist. Basically, I'd like to have a location list split at the <em>top</em> of each writable buffer which shows the last line of each enclosing indentation level. So for the code:</p>
<pre><code>def some_function(x, y, z):
some code
some more code
even... | [
{
"answer_id": 20089,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>I was intending to write an answer explaining how you might go about doing this, but when I embarked on doing so I ended up w... | 2019/05/23 | [
"https://vi.stackexchange.com/questions/20078",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19915/"
] | I'm looking for functionality which may or may not exist. Basically, I'd like to have a location list split at the *top* of each writable buffer which shows the last line of each enclosing indentation level. So for the code:
```
def some_function(x, y, z):
some code
some more code
even more code
if var... | I was intending to write an answer explaining how you might go about doing this, but when I embarked on doing so I ended up with a prototype implementation instead. Writing code is often more fun than writing documentation, I'm afraid!
```
function! ShowContext() abort
let items = []
let l = line('.')
let indent... |
20,081 | <p>Consider the following text file.</p>
<pre><code>1 1 3
1
1
5
</code></pre>
<p>One can rank row 1 with the command <code>y$</code> with the cursor on row 1, column 1.
However, to yank the first column, the only way I know is to <code><C-v>3jy</code>.</p>
<p>Mostly out of curiosity, is it possible to yank the... | [
{
"answer_id": 20082,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 1,
"selected": false,
"text": "<p><code>y<c-v>G</code></p>\n\n<p>This yanks to the bottom of the file, forcing block mode. This only works in some ... | 2019/05/23 | [
"https://vi.stackexchange.com/questions/20081",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1750/"
] | Consider the following text file.
```
1 1 3
1
1
5
```
One can rank row 1 with the command `y$` with the cursor on row 1, column 1.
However, to yank the first column, the only way I know is to `<C-v>3jy`.
Mostly out of curiosity, is it possible to yank the column **without ever entering visual block mode?** | You can create a blockwise text object to do this kind of job, if you bound it to `ic` , you can copy with `yic`, select it with `vic`, no count needed. But it's not easy, feel free to skip it and use some existing plugins, forgot the plugin name, you can google it.
Text object can be created directly or from a motion... |
20,105 | <p>I often don't remember what was copied lately. So I don't know if I need to do <code><C-r>0</code> or <code><C-R>1</code> in insert mode.</p>
<p>I tend to rely only on the <code>*</code> register, or type <code>:reg</code>, look at everything and then decide.</p>
<p>This is cumbersome. Is there a be... | [
{
"answer_id": 20082,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 1,
"selected": false,
"text": "<p><code>y<c-v>G</code></p>\n\n<p>This yanks to the bottom of the file, forcing block mode. This only works in some ... | 2019/05/25 | [
"https://vi.stackexchange.com/questions/20105",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18375/"
] | I often don't remember what was copied lately. So I don't know if I need to do `<C-r>0` or `<C-R>1` in insert mode.
I tend to rely only on the `*` register, or type `:reg`, look at everything and then decide.
This is cumbersome. Is there a better way to do this? | You can create a blockwise text object to do this kind of job, if you bound it to `ic` , you can copy with `yic`, select it with `vic`, no count needed. But it's not easy, feel free to skip it and use some existing plugins, forgot the plugin name, you can google it.
Text object can be created directly or from a motion... |
20,107 | <p>I'm trying to install gvim on WSL (under windows 10) and use <a href="https://mobaxterm.mobatek.net" rel="nofollow noreferrer">MobaXterm</a> as my X server. </p>
<p>Bash informed me that:</p>
<pre><code> Command 'gvim' not found, but can be installed with:
sudo apt install vim
</code></pre>
<p>Which I did and v... | [
{
"answer_id": 20109,
"author": "Warren Young",
"author_id": 6852,
"author_profile": "https://vi.stackexchange.com/users/6852",
"pm_score": 0,
"selected": false,
"text": "<p>I don't have WSL in front of me at the moment, but going on the assumption that you're using the Ubuntu environmen... | 2019/05/25 | [
"https://vi.stackexchange.com/questions/20107",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22412/"
] | I'm trying to install gvim on WSL (under windows 10) and use [MobaXterm](https://mobaxterm.mobatek.net) as my X server.
Bash informed me that:
```
Command 'gvim' not found, but can be installed with:
sudo apt install vim
```
Which I did and vim was installed but not gvim. Anyone know what I'm doing wrong or how... | Yes I had truncated the list of commands suggested by apt. I wasn't sure how apt determines the list of packages it suggests.
When I ran:
```
sudo apt install vim-gtk3
```
gvim did install and did display the expected file contents using a window created by MobaXterm.
While gvim appeared to be working based on m... |
20,125 | <p>I am having trouble crafting a command that would copy the text from the current window and paste this text into a <code>terminal</code> buffer opened in the split below.</p>
<p>Here are a few things I tried:</p>
<pre><code>normal yaw<c-w>j<c-w>"0
:execute "normal yaw\<c-w>j\<c-w>\"0"
:ex... | [
{
"answer_id": 20128,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>The problem is that you can't really use <code>:normal</code> in terminal mode, since that mode is special, it does... | 2019/05/27 | [
"https://vi.stackexchange.com/questions/20125",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/307/"
] | I am having trouble crafting a command that would copy the text from the current window and paste this text into a `terminal` buffer opened in the split below.
Here are a few things I tried:
```
normal yaw<c-w>j<c-w>"0
:execute "normal yaw\<c-w>j\<c-w>\"0"
:execute 'normal yaw<c-w>j<c-w>"0'
let cmd = "normal yaw\<... | The problem is that you can't really use `:normal` in terminal mode, since that mode is special, it doesn't really behave like Normal/Insert mode in a normal vim buffer.
Instead, you can use the [`term_sendkeys()`](https://vimhelp.org/eval.txt.html#term_sendkeys()) function to send the buffer to the terminal.
This sh... |
20,138 | <p>Consider the following function and mapping.</p>
<pre><code>function! DoMagic()
if s:isActive
echom "Performing magic!"
else
" Perform default action of whatever key was mapped to this function
endif
endfunction
map F :call DoMagic()<CR>
</code></pre>
<p>Is there a magic command th... | [
{
"answer_id": 20128,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>The problem is that you can't really use <code>:normal</code> in terminal mode, since that mode is special, it does... | 2019/05/28 | [
"https://vi.stackexchange.com/questions/20138",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1750/"
] | Consider the following function and mapping.
```
function! DoMagic()
if s:isActive
echom "Performing magic!"
else
" Perform default action of whatever key was mapped to this function
endif
endfunction
map F :call DoMagic()<CR>
```
Is there a magic command that tells vim to pretend the mapp... | The problem is that you can't really use `:normal` in terminal mode, since that mode is special, it doesn't really behave like Normal/Insert mode in a normal vim buffer.
Instead, you can use the [`term_sendkeys()`](https://vimhelp.org/eval.txt.html#term_sendkeys()) function to send the buffer to the terminal.
This sh... |
20,139 | <p>I'm wondering if this is possible, more for curiosity's sake, but also it might be useful to know.</p>
<p>I have several ascii data tables and I want to combine them all into a single file. So I combined all of the files into a single file with the file name to signify the start of the new data. What I'd like to do... | [
{
"answer_id": 20141,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>The general pattern we'll be using is: insert text at the beginning of a range of lines.</p>\n\n<p>We have two ... | 2019/05/28 | [
"https://vi.stackexchange.com/questions/20139",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22456/"
] | I'm wondering if this is possible, more for curiosity's sake, but also it might be useful to know.
I have several ascii data tables and I want to combine them all into a single file. So I combined all of the files into a single file with the file name to signify the start of the new data. What I'd like to do is search... | **vim (it's ugly)**
```
g /\S/ if getline('.') =~# '^file' | d | else | norm! PJ | endif
```
* `/\S/` match none blank line
* `if getline('.') =~# '^file' | d` delete line starts with "file" to default register. Note that default register is line wise after deletion.
* `norm! PJ` paste above current line from defaul... |
20,151 | <p>I am writing an RMarkdown file, which is a document that is a hybrid of text and R code. Here is an example of what that document could look like:</p>
<pre><code>Here is an example of text within my Rmarkdown file.
This is used to describe the code block below:
```{r}
dataframe <- outcome.df %>%
na.omit()... | [
{
"answer_id": 20141,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>The general pattern we'll be using is: insert text at the beginning of a range of lines.</p>\n\n<p>We have two ... | 2019/05/29 | [
"https://vi.stackexchange.com/questions/20151",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22464/"
] | I am writing an RMarkdown file, which is a document that is a hybrid of text and R code. Here is an example of what that document could look like:
```
Here is an example of text within my Rmarkdown file.
This is used to describe the code block below:
```{r}
dataframe <- outcome.df %>%
na.omit() %>%
group_by(Hosp... | **vim (it's ugly)**
```
g /\S/ if getline('.') =~# '^file' | d | else | norm! PJ | endif
```
* `/\S/` match none blank line
* `if getline('.') =~# '^file' | d` delete line starts with "file" to default register. Note that default register is line wise after deletion.
* `norm! PJ` paste above current line from defaul... |
20,171 | <p>I often want to open files using the wildcards like</p>
<pre><code>:e **/foo.bar
</code></pre>
<p>However every now and then I get an</p>
<pre><code>E77: Too many file names
</code></pre>
<p>What I would like to have would be to add to that error message a list of the files found. That way, I can get the path to... | [
{
"answer_id": 20172,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>I don't like <code>quickfix</code> in this case, i think <code>input</code> is better. I did both of them, choose the ... | 2019/05/31 | [
"https://vi.stackexchange.com/questions/20171",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2170/"
] | I often want to open files using the wildcards like
```
:e **/foo.bar
```
However every now and then I get an
```
E77: Too many file names
```
What I would like to have would be to add to that error message a list of the files found. That way, I can get the path to the one I want. I know that I can do something l... | ### Completion
Use `<tab>` to complete a filename. If you know there are going to be many candidates then you can use `<c-d>` to list out the candidates. May want to look into `'wildmenu'` & `'wildemode'` settings as well.
### Argument List
You can use `:next` with your argument to populate the argument list.
```
:... |
20,179 | <p>First, I typed <code>2V</code> to select two lines, and <code>y</code> to yank them. Then I typed <code>3V</code>, and instead of selecting 3 lines, Vim selects 6 lines. Next I typed <code>4V</code> and Vim selected 8 lines. It seems that 3 or 4 in the later selections are multiplied by the 2 in the first selection... | [
{
"answer_id": 20172,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>I don't like <code>quickfix</code> in this case, i think <code>input</code> is better. I did both of them, choose the ... | 2019/05/31 | [
"https://vi.stackexchange.com/questions/20179",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22494/"
] | First, I typed `2V` to select two lines, and `y` to yank them. Then I typed `3V`, and instead of selecting 3 lines, Vim selects 6 lines. Next I typed `4V` and Vim selected 8 lines. It seems that 3 or 4 in the later selections are multiplied by the 2 in the first selection for yanking.
Why is that? | ### Completion
Use `<tab>` to complete a filename. If you know there are going to be many candidates then you can use `<c-d>` to list out the candidates. May want to look into `'wildmenu'` & `'wildemode'` settings as well.
### Argument List
You can use `:next` with your argument to populate the argument list.
```
:... |
20,192 | <p>How can I show the mappings for all function keys <code><F1></code> to <code><F12></code> at once? I know that <code>:map <F1></code> shows the mapping for <code><F1></code>, and I can repeat this 12 times for each key. But is there a faster way? I have tried <code>:map <F</code> but that... | [
{
"answer_id": 20172,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>I don't like <code>quickfix</code> in this case, i think <code>input</code> is better. I did both of them, choose the ... | 2019/06/03 | [
"https://vi.stackexchange.com/questions/20192",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21495/"
] | How can I show the mappings for all function keys `<F1>` to `<F12>` at once? I know that `:map <F1>` shows the mapping for `<F1>`, and I can repeat this 12 times for each key. But is there a faster way? I have tried `:map <F` but that doesn't work. | ### Completion
Use `<tab>` to complete a filename. If you know there are going to be many candidates then you can use `<c-d>` to list out the candidates. May want to look into `'wildmenu'` & `'wildemode'` settings as well.
### Argument List
You can use `:next` with your argument to populate the argument list.
```
:... |
20,200 | <p>With other editors we can select vertical-blocks where each line has the same start column but not the same end-column.</p>
<p>For example: </p>
<pre><code>print("", s.field1);
print("", s.field_long);
print("", s.f);
</code></pre>
<p>Is there a way in Vim (with a plugin or not) to select the block from the snipp... | [
{
"answer_id": 20202,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>If memory serves:</p>\n\n<pre><code>/field1<CR><C-v>2jf)\n</code></pre>\n"
},
{
"answer_id"... | 2019/06/03 | [
"https://vi.stackexchange.com/questions/20200",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1542/"
] | With other editors we can select vertical-blocks where each line has the same start column but not the same end-column.
For example:
```
print("", s.field1);
print("", s.field_long);
print("", s.f);
```
Is there a way in Vim (with a plugin or not) to select the block from the snippet above:
```
field1
field_long
... | Go to the first letter of the word, and press
```
<C-v>w
```
that selects the word. You may use
```
<C-v>5w
```
to select e.g. 5 words. Then you do whatever you want, e.g. to copy to clipboard you do
```
" * y
``` |
20,206 | <p>I am trying to remap <code><PageUp></code> key to call this function:</p>
<pre><code>function! PageUp()
let l:line = line('.')
if(l:line != 1)
if(l:line != winline())
:set syntax=off
<PageUp>
:set syntax=on
else
normal! 1G
e... | [
{
"answer_id": 20207,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>First of all, you use the <kbd>PageUp</kbd> key in Normal mode so the underlying functionality is a Normal mode comman... | 2019/06/03 | [
"https://vi.stackexchange.com/questions/20206",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15254/"
] | I am trying to remap `<PageUp>` key to call this function:
```
function! PageUp()
let l:line = line('.')
if(l:line != 1)
if(l:line != winline())
:set syntax=off
<PageUp>
:set syntax=on
else
normal! 1G
endif
endif
endfunction
```
but ... | First of all, you use the `PageUp` key in Normal mode so the underlying functionality is a Normal mode command. You can't use such commands directly while in an Ex command-line or function/script. You need to use the Ex command [`:norm`](https://vimhelp.org/various.txt.html#:norm) for this.
Further, to use "key codes... |
20,233 | <p>I'm on windows 10 with the Windows subsystem for linux. What I'd like to do with netrw is be able to jump from my home folder in Ubuntu to my home folder in windows. In Ranger I type <code>gh</code> and it takes me to my Ubuntu home folder immediately. I mapped <code>ga</code> to go to my Windows home folder so I ca... | [
{
"answer_id": 20234,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 3,
"selected": true,
"text": "<p>Netrw supports bookmarks, which could be used for this. See <a href=\"https://vimhelp.org/pi_netrw.txt.html#netrw-bookmark\" ... | 2019/06/07 | [
"https://vi.stackexchange.com/questions/20233",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22575/"
] | I'm on windows 10 with the Windows subsystem for linux. What I'd like to do with netrw is be able to jump from my home folder in Ubuntu to my home folder in windows. In Ranger I type `gh` and it takes me to my Ubuntu home folder immediately. I mapped `ga` to go to my Windows home folder so I can jump to that folder imm... | Netrw supports bookmarks, which could be used for this. See [`:h netwr-bookmark`](https://vimhelp.org/pi_netrw.txt.html#netrw-bookmark):
```none
BOOKMARKING A DIRECTORY netrw-mb netrw-bookmark netrw-bookmarks
One may easily "bookmark" the currently browsed directory by using
mb
[...]
... |
20,236 | <p>I have the following mappings:</p>
<pre><code>nnoremap # /___<CR>ciw
imap # <Esc>:w<CR><Esc>#
</code></pre>
<p>And the following file that I am editing:</p>
<pre><code>foo ___
goo ___
hoo ___
</code></pre>
<p>The idea is that I start at the beginning of the file, type <code>#</code> and I... | [
{
"answer_id": 20237,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>From <a href=\"http://vimhelp.appspot.com/undo.txt.html#%3Aundojoin\" rel=\"nofollow noreferrer\"><code>:h undojoin</code></... | 2019/06/07 | [
"https://vi.stackexchange.com/questions/20236",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18490/"
] | I have the following mappings:
```
nnoremap # /___<CR>ciw
imap # <Esc>:w<CR><Esc>#
```
And the following file that I am editing:
```
foo ___
goo ___
hoo ___
```
The idea is that I start at the beginning of the file, type `#` and I am editing the first `___`, then while still in insert mode, I type `#` again, and ... | You can use `<c-g>u` in insert mode to break undo sequence and start new change. Like this:
```
imap # <c-g>u<Esc>:w<CR>#
```
(removed the second `<esc>`, as it is not needed.)
See `:help i_CTRL-G_u` |
20,241 | <p>This post is connected with the following one.</p>
<p><a href="https://vi.stackexchange.com/questions/8205/jumping-from-function-definition-tag-to-prototype-tag/8206#8206?newreg=415baf15088d427ca9b0015280f1f80e">Jumping from function definition tag to prototype tag</a></p>
<p>Somehow, I did what it is mentioned th... | [
{
"answer_id": 20237,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>From <a href=\"http://vimhelp.appspot.com/undo.txt.html#%3Aundojoin\" rel=\"nofollow noreferrer\"><code>:h undojoin</code></... | 2019/06/07 | [
"https://vi.stackexchange.com/questions/20241",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22579/"
] | This post is connected with the following one.
[Jumping from function definition tag to prototype tag](https://vi.stackexchange.com/questions/8205/jumping-from-function-definition-tag-to-prototype-tag/8206#8206?newreg=415baf15088d427ca9b0015280f1f80e)
Somehow, I did what it is mentioned there. Now, when I generate my... | You can use `<c-g>u` in insert mode to break undo sequence and start new change. Like this:
```
imap # <c-g>u<Esc>:w<CR>#
```
(removed the second `<esc>`, as it is not needed.)
See `:help i_CTRL-G_u` |
20,244 | <p>I'm trying to make a function to insert license header from external file on first line in the buffer. The script is:</p>
<pre><code> fun InsertLicense()
if filereadable('LICENSE')
let license = 'LICENSE'
elseif filereadable('LICENSE.txt')
let license = 'LICENSE.txt'
... | [
{
"answer_id": 20245,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 4,
"selected": true,
"text": "<p><code>readfile()</code> returns a list, each line being in a separate list item.</p>\n\n<p>You can therefore make... | 2019/06/07 | [
"https://vi.stackexchange.com/questions/20244",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9140/"
] | I'm trying to make a function to insert license header from external file on first line in the buffer. The script is:
```
fun InsertLicense()
if filereadable('LICENSE')
let license = 'LICENSE'
elseif filereadable('LICENSE.txt')
let license = 'LICENSE.txt'
else
... | `readfile()` returns a list, each line being in a separate list item.
You can therefore make use of `map()` to change the list inplace:
```
let a=map(readfile('LICENSE'), { i,v -> '/* ' . v. ' */'})
```
This makes use of [lambda](http://vimhelp.appspot.com/eval.txt.html#expr-lambda) expression and wraps a the comme... |
20,247 | <p>I have my EXINIT set to</p>
<pre><code>export EXINIT="set ts=4 sw=4 ai nosm nows expandtab"
</code></pre>
<p>I also want <code>syn off</code> to turn off syntax highlighting by default.</p>
<p>How can I add this to EXINIT? Tried using <code>;</code> as a the separator but that doesn't work.</p>
<p>I know I can p... | [
{
"answer_id": 20245,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 4,
"selected": true,
"text": "<p><code>readfile()</code> returns a list, each line being in a separate list item.</p>\n\n<p>You can therefore make... | 2019/06/08 | [
"https://vi.stackexchange.com/questions/20247",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10998/"
] | I have my EXINIT set to
```
export EXINIT="set ts=4 sw=4 ai nosm nows expandtab"
```
I also want `syn off` to turn off syntax highlighting by default.
How can I add this to EXINIT? Tried using `;` as a the separator but that doesn't work.
I know I can put these commands in `.exrc` file but I want to know if I can ... | `readfile()` returns a list, each line being in a separate list item.
You can therefore make use of `map()` to change the list inplace:
```
let a=map(readfile('LICENSE'), { i,v -> '/* ' . v. ' */'})
```
This makes use of [lambda](http://vimhelp.appspot.com/eval.txt.html#expr-lambda) expression and wraps a the comme... |
20,268 | <p>I am trying to direct data from manpage to <em>gvim</em> file but it's not properly formatted. </p>
<p>Example: </p>
<ul>
<li>In manpage it is shown as <strong><code>NAME</code></strong> (bold)</li>
<li>But in <em>gvim</em> its printed as <code>N^HNA^HAM^HME^HE</code>.</li>
<li>Similarly for <strong><code>SYNTAX<... | [
{
"answer_id": 20272,
"author": "João A. Toledo",
"author_id": 11384,
"author_profile": "https://vi.stackexchange.com/users/11384",
"pm_score": 1,
"selected": false,
"text": "<p>I suppose you are trying to capture the output from a program and open it on <code>gVim</code>... If that's th... | 2019/06/10 | [
"https://vi.stackexchange.com/questions/20268",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22609/"
] | I am trying to direct data from manpage to *gvim* file but it's not properly formatted.
Example:
* In manpage it is shown as **`NAME`** (bold)
* But in *gvim* its printed as `N^HNA^HAM^HME^HE`.
* Similarly for **`SYNTAX`** it prints `S^HSY^HYN^HNT^HTA^HAX^HX`.
* You can notice additional letter after(or before) `^H... | I suppose you are trying to capture the output from a program and open it on `gVim`... If that's the case, I'm afraid you will need to open the file with the output and then *remove* those `^H` and the repeated character that follows it.
```
%s/\v(.)^H\1/\1/g
```
Where:
`%s/` substitute in all lines:
`\v` uses *ve... |
20,273 | <p>I am on neovim with Oni. vim-netranger plugin uses terminal colors in this format to highlight things. It does work in terminal with neovim , but not in a gui app. </p>
<p>I am looking for a way to replace this that will work. </p>
<pre><code>def c256(msg, c, background):
if background:
return '[38;5;{... | [
{
"answer_id": 20274,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>Assuming by text line OP means the command line window (e.g., via <code>echom</code>), use <code>:echohl</code>... | 2019/06/10 | [
"https://vi.stackexchange.com/questions/20273",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18375/"
] | I am on neovim with Oni. vim-netranger plugin uses terminal colors in this format to highlight things. It does work in terminal with neovim , but not in a gui app.
I am looking for a way to replace this that will work.
```
def c256(msg, c, background):
if background:
return '[38;5;{};7m{}[0m'.format(c, ... | Those are ANSI escape sequences which are commonly used to print colored text in terminal windows. If valid sequences are being inserted into Vim buffers then you'll be happy to know that there's a plugin that will translate to Vim highlighting/colors: [AnsiEsc](https://github.com/powerman/vim-plugin-AnsiEsc)
Here's ... |
20,275 | <p>I'm trying to debug an error in a vim plugin. The only clue I'm getting regarding the location of the error is this message:</p>
<pre><code>Error detected while processing function 190[2]..191[15]..218:
line 27:
<custom error message>
</code></pre>
<p>I've tried Googling an answer to this question, but it ... | [
{
"answer_id": 20276,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 0,
"selected": false,
"text": "<p>If you are profiling when the function is called, vim will print the lines of the function to a log file.</p>\n\n<pre><c... | 2019/06/10 | [
"https://vi.stackexchange.com/questions/20275",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4808/"
] | I'm trying to debug an error in a vim plugin. The only clue I'm getting regarding the location of the error is this message:
```
Error detected while processing function 190[2]..191[15]..218:
line 27:
<custom error message>
```
I've tried Googling an answer to this question, but it hasn't turned up anything. I kno... | I use `fnum` to represent function number in this answer.
**Get numbered function definition**
```
:function {fnum}
```
It's documented at [:h numbered-function](https://vimhelp.org/eval.txt.html#numbered-function)
**Add breakpoint to numbered-function**
```
:breakadd func lnum fnum
```
Note that everytime you ... |
20,286 | <p>Running <code>:checkhealth</code> in NeoVim-Qt (v0.3.5) I get the following report on terminal:</p>
<pre><code>ERROR: command failed: infocmp -L
infocmp: environment variable TERM not set
</code></pre>
<p>How can I set the environment variable TERM in NeoVim-Qt?</p>
| [
{
"answer_id": 20331,
"author": "bk2204",
"author_id": 22677,
"author_profile": "https://vi.stackexchange.com/users/22677",
"pm_score": 4,
"selected": true,
"text": "<p>The <code>TERM</code> environment variable is generally set by the terminal emulator you're running in, and it tells pr... | 2019/06/11 | [
"https://vi.stackexchange.com/questions/20286",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17024/"
] | Running `:checkhealth` in NeoVim-Qt (v0.3.5) I get the following report on terminal:
```
ERROR: command failed: infocmp -L
infocmp: environment variable TERM not set
```
How can I set the environment variable TERM in NeoVim-Qt? | The `TERM` environment variable is generally set by the terminal emulator you're running in, and it tells programs using curses (like Vim and Neovim) what sequences to send to the screen to do things like moving the cursor and setting colors. When you're using a graphical environment, Vim and Neovim don't need this env... |
20,296 | <p>Let's say I'm at line 20 and I want to copy (and paste below line 20) just the line 50. I can do that with <code>:50,50y</code> , then paste with <code>p</code> in normal mode. I found this <a href="https://vi.stackexchange.com/a/9817/22625">here</a>.</p>
<p>I want to know if there are ways to do it without that co... | [
{
"answer_id": 20297,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 4,
"selected": true,
"text": "<p><strong>Copy line 50 after line 20</strong></p>\n\n<pre><code>:50t20\n</code></pre>\n\n<p>Change <code>20</code> to <co... | 2019/06/11 | [
"https://vi.stackexchange.com/questions/20296",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22625/"
] | Let's say I'm at line 20 and I want to copy (and paste below line 20) just the line 50. I can do that with `:50,50y` , then paste with `p` in normal mode. I found this [here](https://vi.stackexchange.com/a/9817/22625).
I want to know if there are ways to do it without that command nor using `50ggyy20ggp` (in general t... | **Copy line 50 after line 20**
```
:50t20
```
Change `20` to `.` if you want to copy line 50 after current line.
**Move around and copy line after line 20**:
Go to line 20, and mark it:
```
mm
```
Move cursor to any line you want and execute an ex command :
```
:t'm
```
[`:h :t`](http://vimhelp.appspot.com/c... |
20,299 | <p>If I'm using replace mode, but I want to keep one or a few characters in a row of the text I am replacing, is there an easy way to skip forward rather than retyping the characters or exiting replace mode and moving and re-entering replace mode?</p>
<p>For example, let's say I'm editing the following text:</p>
<pre... | [
{
"answer_id": 20300,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>You want to skip <code>Jun</code> , so you must find a way to move cursor to <code>11</code>.</p>\n\n<p>You want to us... | 2019/06/12 | [
"https://vi.stackexchange.com/questions/20299",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4676/"
] | If I'm using replace mode, but I want to keep one or a few characters in a row of the text I am replacing, is there an easy way to skip forward rather than retyping the characters or exiting replace mode and moving and re-entering replace mode?
For example, let's say I'm editing the following text:
```
Tue Jun 11 20:... | You want to skip `Jun` , so you must find a way to move cursor to `11`.
You want to use dot repeat, so `<c-o>` is not an option, as it always splits undo.
That leave you only the arrow keys. To stop it from breaking undo, custom map is necessary:
```
inoremap <Left> <C-G>U<Left>
inoremap <Right> <C-G>U<Right>
inore... |
20,304 | <p>Help! I am looking for a vim script function: </p>
<p>The function takes "currentDirectoryPath" and "fileName"; starting from "currentDirectoryPath" it will search recursively for the existence of "fileName" in the parent directory . </p>
<p>Return true if "fileName" is found and stop searching. </p>
<p>Return fa... | [
{
"answer_id": 20309,
"author": "Andy Stewart",
"author_id": 1643,
"author_profile": "https://vi.stackexchange.com/users/1643",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <code>findfile()</code> for this.</p>\n\n<pre><code>:echo !empty(findfile(fileName, currentDirectoryPat... | 2019/06/13 | [
"https://vi.stackexchange.com/questions/20304",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15493/"
] | Help! I am looking for a vim script function:
The function takes "currentDirectoryPath" and "fileName"; starting from "currentDirectoryPath" it will search recursively for the existence of "fileName" in the parent directory .
Return true if "fileName" is found and stop searching.
Return false if fileName is not f... | You can use `findfile()` for this.
```
:echo !empty(findfile(fileName, currentDirectoryPath.';'))
``` |
20,310 | <p>I am currently using a vertical monitor for my vim setup. I absolutely love being able to view 100+ lines of code at once. My eyes can scan longer and more complicated blocks of code.</p>
<p>However, I have noticed that there are times when being able to see 100+ lines of code is actually quite distracting. There a... | [
{
"answer_id": 20309,
"author": "Andy Stewart",
"author_id": 1643,
"author_profile": "https://vi.stackexchange.com/users/1643",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <code>findfile()</code> for this.</p>\n\n<pre><code>:echo !empty(findfile(fileName, currentDirectoryPat... | 2019/06/13 | [
"https://vi.stackexchange.com/questions/20310",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22644/"
] | I am currently using a vertical monitor for my vim setup. I absolutely love being able to view 100+ lines of code at once. My eyes can scan longer and more complicated blocks of code.
However, I have noticed that there are times when being able to see 100+ lines of code is actually quite distracting. There are cases w... | You can use `findfile()` for this.
```
:echo !empty(findfile(fileName, currentDirectoryPath.';'))
``` |
20,319 | <p>I often want to edit text in say line 200 of a file, but while doing this I need to look at say line 100, so I scroll to line 100. Is there a way to quickly jump back to line 200 after scrolling? Is there a possibility to configure a jump mark that is update with every movement except scrolling?</p>
<p><code>''</co... | [
{
"answer_id": 20320,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>First, instead of scrolling, try <code>:100</code> or <code>100G</code>; then the <code>`</code> mark will work... | 2019/06/14 | [
"https://vi.stackexchange.com/questions/20319",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21684/"
] | I often want to edit text in say line 200 of a file, but while doing this I need to look at say line 100, so I scroll to line 100. Is there a way to quickly jump back to line 200 after scrolling? Is there a possibility to configure a jump mark that is update with every movement except scrolling?
`''` doesn't seem to w... | **Go back in the same file**
Mark your current position with `mm` , move around, go back with `'m` or ``m`.
**Go back to last insert position in the same file**
```
`^
```
**Go back to last insert position and continue in insert mode**
```
gi
```
**Go back accross files**
Mark your current position with mM , m... |
20,333 | <p>I use two spaces in my indentation of codes. What are the possible ways to indent or unindent a block of code?</p>
| [
{
"answer_id": 20334,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n <p>I use two spaces in my indentation of codes. </p>\n</blockquote>\n\n<p>First off, you should set th... | 2019/06/17 | [
"https://vi.stackexchange.com/questions/20333",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22680/"
] | I use two spaces in my indentation of codes. What are the possible ways to indent or unindent a block of code? | >
> I use two spaces in my indentation of codes.
>
>
>
First off, you should set the [`'shiftwidth'`](https://vimhelp.org/options.txt.html#%27shiftwidth%27) option to 2, to match the number of spaces you want to use as indentation. You will probably also want to set [`'expandtab'`](https://vimhelp.org/options.txt... |
20,340 | <p>I normally write my functions this way</p>
<pre><code>public void test() {}
</code></pre>
<p>to continue, I need to insert a new line from within the brackets, so the final output is this:</p>
<pre><code>public void test(){
// cursor is here now
}
</code></pre>
<p>To do so in vim, I follow these steps: (the ... | [
{
"answer_id": 20341,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "<p>Turn on <a href=\"https://vimhelp.org/options.txt.html#%27autoindent%27\" rel=\"nofollow noreferrer\">:h 'autoindent'<... | 2019/06/17 | [
"https://vi.stackexchange.com/questions/20340",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22692/"
] | I normally write my functions this way
```
public void test() {}
```
to continue, I need to insert a new line from within the brackets, so the final output is this:
```
public void test(){
// cursor is here now
}
```
To do so in vim, I follow these steps: (the pipe is where the cursor at)
```
public void tes... | Turn on [:h 'autoindent'](https://vimhelp.org/options.txt.html#%27autoindent%27) and [:h 'smartindent'](https://vimhelp.org/options.txt.html#%27smartindent%27) , assume current typing is:
```
public void test(){
```
input `enter``}`:
```
public void test(){
}
```
input `esc``O`:
```
public void test(){
|
}
... |
20,344 | <p>I stumbled recently upon a mapping in the <a href="https://vim.fandom.com/wiki/Folding" rel="noreferrer">Vim Tips Wiki</a> that uses an <a href="http://vimdoc.sourceforge.net/htmldoc/eval.html#expr-quote" rel="noreferrer">expr-quote</a>:</p>
<pre><code>nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\... | [
{
"answer_id": 20345,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 5,
"selected": true,
"text": "<p>Good question. The keycode format with wider general usability is <code>\"\\<xxx>\"</code>. In any expression t... | 2019/06/18 | [
"https://vi.stackexchange.com/questions/20344",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10164/"
] | I stumbled recently upon a mapping in the [Vim Tips Wiki](https://vim.fandom.com/wiki/Folding) that uses an [expr-quote](http://vimdoc.sourceforge.net/htmldoc/eval.html#expr-quote):
```
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
```
and realized it still worked after using a [literal-string](ht... | Good question. The keycode format with wider general usability is `"\<xxx>"`. In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code").
Per [`:h keycodes`](https://vimhelp.org/intro.txt.html#keycodes) the other form, `<xxx>`, is used in the docume... |
20,363 | <p>I'd like to be able to define my own functions that add certain kinds of line to the quickfix list, or set it to those in its entirety, without having to go via the filesystem with a made-up <code>errorfile</code> format that I tell vim how to parse (<code>errorfmt</code>).</p>
<p>I've seen <code>setqflist</code> a... | [
{
"answer_id": 20365,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 1,
"selected": false,
"text": "<p><code>getqflist()</code> and <code>setqflist()</code> are sort of opposites. Printing out the results of <code>getq... | 2019/06/19 | [
"https://vi.stackexchange.com/questions/20363",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5778/"
] | I'd like to be able to define my own functions that add certain kinds of line to the quickfix list, or set it to those in its entirety, without having to go via the filesystem with a made-up `errorfile` format that I tell vim how to parse (`errorfmt`).
I've seen `setqflist` and `getqflist`, but the only other question... | `getqflist()` and `setqflist()` are sort of opposites. Printing out the results of `getqflist()` will give you and idea of the structure `setqflist()` is looking for.
```
call setqflist(getqflist())
```
Recent versions of Vim (8+) also allow you to use `lines` & `efm` to parse a list of lines with a different format... |
20,371 | <h2>Background and problem</h2>
<p>I've just discovered <a href="https://stackoverflow.com/a/42118416/1944384">how to make the cursor a vertical line</a> in insert mode. This works well with <a href="https://stackoverflow.com/a/6489348/1944384">cursorline</a>; even with the thinner cursor, I can still easily find my p... | [
{
"answer_id": 26547,
"author": "xicod",
"author_id": 26305,
"author_profile": "https://vi.stackexchange.com/users/26305",
"pm_score": 1,
"selected": false,
"text": "<p>I actually went with coloring the background of the line number. This way you're not interfering with syntax colors or ... | 2019/06/20 | [
"https://vi.stackexchange.com/questions/20371",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1278/"
] | Background and problem
----------------------
I've just discovered [how to make the cursor a vertical line](https://stackoverflow.com/a/42118416/1944384) in insert mode. This works well with [cursorline](https://stackoverflow.com/a/6489348/1944384); even with the thinner cursor, I can still easily find my position.
`... | I actually went with coloring the background of the line number. This way you're not interfering with syntax colors or underscores.
So basically I have this (for light background terminal)
```
highlight CursorLineNr ctermfg=white guifg=white ctermbg=darkgrey guibg=darkgrey cterm=bold gui=bold
``` |
20,407 | <p>1) To underline misspelled words, I can execute the following in an open buffer:</p>
<pre><code>:hi clear SpellBad
:hi SpellBad cterm=underline
:set spell
</code></pre>
<p>2) However, if I write in my <code>.vimrc</code> the first two lines, namely:</p>
<pre><code>:hi clear SpellBad
:hi SpellBad cterm=underline
<... | [
{
"answer_id": 20408,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>They are likely overridden by your colorscheme of choice (even if it is default). </p>\n\n<p>My suggested fix is... | 2019/06/24 | [
"https://vi.stackexchange.com/questions/20407",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6023/"
] | 1) To underline misspelled words, I can execute the following in an open buffer:
```
:hi clear SpellBad
:hi SpellBad cterm=underline
:set spell
```
2) However, if I write in my `.vimrc` the first two lines, namely:
```
:hi clear SpellBad
:hi SpellBad cterm=underline
```
and when I open a file, I execute `:set spe... | They are likely overridden by your colorscheme of choice (even if it is default).
My suggested fix is
```
augroup colors
au!
au ColorScheme * hi whatever
augroup
``` |
20,409 | <p>When I pass the names of multiple files to vim on the command line (e.g. <code>vim foo.txt bar.txt</code>), I almost always want to add the <code>-o</code> option, because I would like them to be visible side-by-side in separate windows. However, I often forget to add <code>-o</code>. I cannot find an appropriate se... | [
{
"answer_id": 20412,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 4,
"selected": true,
"text": "<p>As a solution to the generalized question <em>How can I apply a command-line option every time I open vim?</em> (there... | 2019/06/24 | [
"https://vi.stackexchange.com/questions/20409",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | When I pass the names of multiple files to vim on the command line (e.g. `vim foo.txt bar.txt`), I almost always want to add the `-o` option, because I would like them to be visible side-by-side in separate windows. However, I often forget to add `-o`. I cannot find an appropriate setting, but is there a way to set thi... | As a solution to the generalized question *How can I apply a command-line option every time I open vim?* (there are options that don't have configuration equivalents) one approach is as follows.
1. Put your personal bin dir (`~/bin`) ahead of vim's path in your PATH environment variable. If the bin dir is not already ... |
20,418 | <p>I want to map <code>Ctrl</code> + mouse click to a command:</p>
<pre><code>nnoremap <C-???> :YcmCompleter GoTo<CR>
</code></pre>
<p>Is it possible to do that using <code>nnoremap</code>? What symbol should I use for that?</p>
| [
{
"answer_id": 20419,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>You are looking for this which I found at the bottom of <a href=\"http://vimhelp.appspot.com/intro.txt.html#keycodes\" re... | 2019/06/25 | [
"https://vi.stackexchange.com/questions/20418",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9140/"
] | I want to map `Ctrl` + mouse click to a command:
```
nnoremap <C-???> :YcmCompleter GoTo<CR>
```
Is it possible to do that using `nnoremap`? What symbol should I use for that? | You are looking for this which I found at the bottom of [`:h keycodes`](http://vimhelp.appspot.com/intro.txt.html#keycodes):
```
nnoremap <C-LeftMouse> :echom 'Foo'<CR>
```
And according to [`:h <LeftMouse>`](http://vimhelp.appspot.com/visual.txt.html#%3cLeftMouse%3e) you also need to check that `set mouse` contains... |
20,426 | <p>Given an input file of the form </p>
<pre><code>#1. This STUFF
Content related to 1
...and some tips
#4. Fouth heading
4para
4para
#3.
3para
3para
</code></pre>
<p>I'd like to be able to sort it to get: </p>
<pre><code>#1. This STUFF
Content related to 1
...and some tips
#3.
3para
3para
#4. Fouth headin... | [
{
"answer_id": 20430,
"author": "Jürgen Krämer",
"author_id": 2636,
"author_profile": "https://vi.stackexchange.com/users/2636",
"pm_score": 1,
"selected": false,
"text": "<p>I would use a special marker for end-of-line, join all lines in a section into one line, sort the lines, and repl... | 2019/06/26 | [
"https://vi.stackexchange.com/questions/20426",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8792/"
] | Given an input file of the form
```
#1. This STUFF
Content related to 1
...and some tips
#4. Fouth heading
4para
4para
#3.
3para
3para
```
I'd like to be able to sort it to get:
```
#1. This STUFF
Content related to 1
...and some tips
#3.
3para
3para
#4. Fouth heading
4para
4para
```
specifically I'd ... | ```
for id in reverse(range(1,100)) | sil exe printf('g/\v^#%d\./,/\v.*(\n#\d+\.|%%$)/ m0', id) | endfor
```
Loop from 100 to 1, execute [:h :global](https://vimhelp.org/repeat.txt.html#%3Aglobal) for each number, use [:h :m](https://vimhelp.org/change.txt.html#%3Am) to move each block to file start.
This method is s... |
20,431 | <p>I've found a lot of information online about this for Linux-Vim but not for the Windows-Vim (not gvim). Whenever I try to copy and paste something in Vim (using <code>y</code> and <code>p</code>), the copies I make do not expand to the system, only to the currently running instance of vim. Here are a few different s... | [
{
"answer_id": 20432,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 2,
"selected": false,
"text": "<p>I don't have a Windows machine to test, but I think you are looking for</p>\n\n<pre><code>:set clipboard=unnamedplus\n</... | 2019/06/26 | [
"https://vi.stackexchange.com/questions/20431",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1965/"
] | I've found a lot of information online about this for Linux-Vim but not for the Windows-Vim (not gvim). Whenever I try to copy and paste something in Vim (using `y` and `p`), the copies I make do not expand to the system, only to the currently running instance of vim. Here are a few different scenarios that all do diff... | I don't have a Windows machine to test, but I think you are looking for
```
:set clipboard=unnamedplus
```
Than Vim always uses the `+` register "for all yank, delete, change and put operations which would normally go to the unnamed register".
See `:help clipboard`. |
20,448 | <p>I pasted some code into a new, unwritten buffer in Vim. I'd like to do some quick edits on the code without saving it to a file, but it hurts my eyes to look at code without syntax highlighting. Can I use syntax highlighting without writing it to a file? I don't want to write it to a file so I don't have to delet... | [
{
"answer_id": 20449,
"author": "alanboy",
"author_id": 22830,
"author_profile": "https://vi.stackexchange.com/users/22830",
"pm_score": 2,
"selected": false,
"text": "<p>You can set the syntax highlighting by doing: </p>\n\n<pre><code>:set syntax=java\n</code></pre>\n\n<p>This will work... | 2019/06/28 | [
"https://vi.stackexchange.com/questions/20448",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21476/"
] | I pasted some code into a new, unwritten buffer in Vim. I'd like to do some quick edits on the code without saving it to a file, but it hurts my eyes to look at code without syntax highlighting. Can I use syntax highlighting without writing it to a file? I don't want to write it to a file so I don't have to delete the ... | In addition to setting the syntax, setting the filetype brings indent options (if you have those on), mappings, and other filetype specific vimscript to bear on your code. So I recommend
```
:set filetype=java
```
Which we typically abbreviate in interactive use as
```
:set ft=java
``` |
20,455 | <p>Say I have files File1.m, File2.m, and File3.m in the current directory. I want vimgrep to search all but File3.m. After reading the help on using backticks to specify files for vimgrep, I tried:</p>
<pre><code>:vimgrep SearchExpression `echo !(File3).m`
</code></pre>
<p>This yields the error</p>
<pre><code>Can... | [
{
"answer_id": 20449,
"author": "alanboy",
"author_id": 22830,
"author_profile": "https://vi.stackexchange.com/users/22830",
"pm_score": 2,
"selected": false,
"text": "<p>You can set the syntax highlighting by doing: </p>\n\n<pre><code>:set syntax=java\n</code></pre>\n\n<p>This will work... | 2019/06/29 | [
"https://vi.stackexchange.com/questions/20455",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7970/"
] | Say I have files File1.m, File2.m, and File3.m in the current directory. I want vimgrep to search all but File3.m. After reading the help on using backticks to specify files for vimgrep, I tried:
```
:vimgrep SearchExpression `echo !(File3).m`
```
This yields the error
```
Cannot open file "File1.m File2.m"
```
S... | In addition to setting the syntax, setting the filetype brings indent options (if you have those on), mappings, and other filetype specific vimscript to bear on your code. So I recommend
```
:set filetype=java
```
Which we typically abbreviate in interactive use as
```
:set ft=java
``` |
20,469 | <p>I started to learn ViM one month ago, so I'm not a ViM expert. </p>
<p>My question is: if I make some changes in insert mode (let's say I type some text, then I delete the last two words and finally type some other words) and then I press <code><ESC> u</code> the entire text I typed in Insert mode disappears.... | [
{
"answer_id": 20470,
"author": "Jürgen Krämer",
"author_id": 2636,
"author_profile": "https://vi.stackexchange.com/users/2636",
"pm_score": 3,
"selected": true,
"text": "<p>You can define insert mode mappings for those keys by prepending <code><c-g>u</code>:</p>\n<pre><code>:inore... | 2019/07/01 | [
"https://vi.stackexchange.com/questions/20469",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22833/"
] | I started to learn ViM one month ago, so I'm not a ViM expert.
My question is: if I make some changes in insert mode (let's say I type some text, then I delete the last two words and finally type some other words) and then I press `<ESC> u` the entire text I typed in Insert mode disappears. I know the existence of th... | You can define insert mode mappings for those keys by prepending `<c-g>u`:
```
:inoremap <space> <c-g>u<space>
:inoremap <bs> <c-g>u<bs>
:inoremap <c-w> <c-g>u<c-w>
" etc.
``` |
20,474 | <p><strong>TL;DR:</strong> How do I permanently and persistently <code>:set syntax=context</code> for <code>*.tex</code> files?</p>
<hr>
<p>I've been using <code>vim</code> for a LaTeX project, with <a href="https://github.com/patstockwell/vim-monokai-tasty" rel="nofollow noreferrer">monokai-tasty</a> as the colour s... | [
{
"answer_id": 20480,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>I think what you are looking for is the variable <code>g:tex_flavor</code>. Put this in your vimrc file:</p>\n\n<... | 2019/07/01 | [
"https://vi.stackexchange.com/questions/20474",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22858/"
] | **TL;DR:** How do I permanently and persistently `:set syntax=context` for `*.tex` files?
---
I've been using `vim` for a LaTeX project, with [monokai-tasty](https://github.com/patstockwell/vim-monokai-tasty) as the colour scheme.
The default syntax highlighting seems to be TeX Highlighting
```
:set syntax=tex
```... | I think what you are looking for is the variable `g:tex_flavor`. Put this in your vimrc file:
```
let g:tex_flavor = 'context'
```
For more information, see `:help g:tex_flavor`. |
20,484 | <p>in my plugin, i am joining XML tags together depending on a mapping a use. It also uses so i can make XML snippets repetitive.
After inserting the text into a buffer, i would like the cursor to return to the initial position from which I started the 'pasting', but somehow i cannot leave the insert mode.</p>
<p>The... | [
{
"answer_id": 20485,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": true,
"text": "<ol>\n<li>Instead of marking in normal mode, you can use <code>:mark q</code></li>\n<li>Instead of entering insert ... | 2019/07/02 | [
"https://vi.stackexchange.com/questions/20484",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22283/"
] | in my plugin, i am joining XML tags together depending on a mapping a use. It also uses so i can make XML snippets repetitive.
After inserting the text into a buffer, i would like the cursor to return to the initial position from which I started the 'pasting', but somehow i cannot leave the insert mode.
The function l... | 1. Instead of marking in normal mode, you can use `:mark q`
2. Instead of entering insert mode to paste your data, try using either `put =result` (results on a new line), save the result into a register (`let @a=result`) and paste inline (`normal! "ap`), or match a part of the line to insert (e.g., at the beginning: `s... |