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 |
|---|---|---|---|---|---|---|
9,776 | <p>Consider something like this
<code>
nnoremap <silent> <leader>( F(a<cr><esc>vi(:^Uexecute"'<,'>s/,/,\r/gg"<cr>=i(k$%i,<cr><esc>%:nohlsearch<cr>
</code>
It expands arguments of a function in lines. (You can run it on <code>(a, b, c, d)</code> for example.)
The pro... | [
{
"answer_id": 9777,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 0,
"selected": false,
"text": "<p>AFAIK, we can't run vim commands in background. At best we can run external processes.</p>\n\n<p>Or may be start anot... | 2016/10/01 | [
"https://vi.stackexchange.com/questions/9776",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7153/"
] | Consider something like this
`nnoremap <silent> <leader>( F(a<cr><esc>vi(:^Uexecute"'<,'>s/,/,\r/gg"<cr>=i(k$%i,<cr><esc>%:nohlsearch<cr>`
It expands arguments of a function in lines. (You can run it on `(a, b, c, d)` for example.)
The problem is things happen in front of my eyes while I expect it to happen in backgrou... | To avoid "seeing" the effect of each command run from a map or macro, use:
```
set lazyredraw
```
.. so that the screen is only redrawn once at the end - which makes the whole process (much) faster (see `:h lz`). |
9,786 | <p>If I have a magic Vim regex in a string literal, is there a way to convert the whole regex into an alternative representation that uses a different magic mode, so I could paste that equivalent regex into source code?</p>
<p>For instance, if I want to convert this magic-mode pattern:</p>
<pre><code>'\m-\=\<\d\+L... | [
{
"answer_id": 9818,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 2,
"selected": false,
"text": "<p>The command</p>\n\n<pre><code>:s\\v\\\\(\\W)/\\1/\n</code></pre>\n\n<p>should suffice to transform most any pattern into ... | 2016/10/01 | [
"https://vi.stackexchange.com/questions/9786",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/824/"
] | If I have a magic Vim regex in a string literal, is there a way to convert the whole regex into an alternative representation that uses a different magic mode, so I could paste that equivalent regex into source code?
For instance, if I want to convert this magic-mode pattern:
```
'\m-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+... | The command
```
:s\v\\(\W)/\1/
```
should suffice to transform most any pattern into `\v` mode. It won't swap out the lil' `\m` marker though - and to my knowledge that's impossible in a single replacement. It's short enough to type manually though, and then you can just do `:s/\\m/\\v` for the mode marker.
`\W` is... |
9,790 | <p>I use vim-pandoc for markdown editing but it adds red backgrounds to almost every words. Is it an spellchecking issue ? how can I disable this ?</p>
<p>[<img src="https://i.stack.imgur.com/X2kaP.png" alt="red background[1]"></p>
| [
{
"answer_id": 9818,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 2,
"selected": false,
"text": "<p>The command</p>\n\n<pre><code>:s\\v\\\\(\\W)/\\1/\n</code></pre>\n\n<p>should suffice to transform most any pattern into ... | 2016/10/03 | [
"https://vi.stackexchange.com/questions/9790",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4542/"
] | I use vim-pandoc for markdown editing but it adds red backgrounds to almost every words. Is it an spellchecking issue ? how can I disable this ?
[![red background[1]](https://i.stack.imgur.com/X2kaP.png) | The command
```
:s\v\\(\W)/\1/
```
should suffice to transform most any pattern into `\v` mode. It won't swap out the lil' `\m` marker though - and to my knowledge that's impossible in a single replacement. It's short enough to type manually though, and then you can just do `:s/\\m/\\v` for the mode marker.
`\W` is... |
9,793 | <p>For example:</p>
<pre><code>QString QSSMLTools::heather(QString s)
{
if (!m_Enable) {return s;}
s.insert(0,"<voice name='Heather'>");
s.append("</voice>");
return s;
}
QString QSSMLTools::isabella(QString s)
{
if (!m_Enable) {return s;}
s.insert(0,"<voice name='Isabella'>... | [
{
"answer_id": 9794,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 2,
"selected": false,
"text": "<p>You can do this with two mappings, a normal mode mapping, and a visual mode mapping. Try this:</p>\n\n<pre><code>nnor... | 2016/10/04 | [
"https://vi.stackexchange.com/questions/9793",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | For example:
```
QString QSSMLTools::heather(QString s)
{
if (!m_Enable) {return s;}
s.insert(0,"<voice name='Heather'>");
s.append("</voice>");
return s;
}
QString QSSMLTools::isabella(QString s)
{
if (!m_Enable) {return s;}
s.insert(0,"<voice name='Isabella'>");
s.append("</voice>");
... | You can do this with two mappings, a normal mode mapping, and a visual mode mapping. Try this:
```
nnoremap * viw
xnoremap * wiw
```
The first one is pretty straightforward. It starts visual mode (`v`), and selects (i)nside of the current (w)ord. Then, the second time you hit it, the other mapping applies since we w... |
9,795 | <p>Let's say I'd like to indent the current line 4 times. (Not 4 spaces, 4 indent commands). As far as I can tell, the shortest way to do this is</p>
<pre><code>>>...
</code></pre>
<p>(Indent once, repeat three times) This seems really inefficient to me. I'd rather do something like this:</p>
<pre><code>4>&... | [
{
"answer_id": 9796,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<p>You can do:</p>\n\n<pre><code>:>>>>\n</code></pre>\n\n<p>to shift the current line 4 times.</p>\n\n<p>So you cou... | 2016/10/04 | [
"https://vi.stackexchange.com/questions/9795",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2920/"
] | Let's say I'd like to indent the current line 4 times. (Not 4 spaces, 4 indent commands). As far as I can tell, the shortest way to do this is
```
>>...
```
(Indent once, repeat three times) This seems really inefficient to me. I'd rather do something like this:
```
4>>
```
But instead of repeatedly indenting the... | You can do:
```
:>>>>
```
to shift the current line 4 times.
So you could write a custom normal mode mapping that shifts the current line `{count}` times:
```
nnoremap <expr> <F5> ":\<C-u>" . repeat(">", v:count1) . "\<CR>"
nnoremap <expr> <F6> ":\<C-u>" . repeat("<", v:count1) . "\<CR>"
```
and its visual mode ... |
9,815 | <p>Suppose I am on line <code>10</code>, and I want to yank to line <code>20</code>. Usually I will do <code>10y</code>. Sometimes I do the subtraction wrong, and copy the wrong number of lines. Is there a way to copy directly from current line to line <code>20</code> without doing the subtraction?</p>
| [
{
"answer_id": 9796,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<p>You can do:</p>\n\n<pre><code>:>>>>\n</code></pre>\n\n<p>to shift the current line 4 times.</p>\n\n<p>So you cou... | 2016/10/05 | [
"https://vi.stackexchange.com/questions/9815",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9567/"
] | Suppose I am on line `10`, and I want to yank to line `20`. Usually I will do `10y`. Sometimes I do the subtraction wrong, and copy the wrong number of lines. Is there a way to copy directly from current line to line `20` without doing the subtraction? | You can do:
```
:>>>>
```
to shift the current line 4 times.
So you could write a custom normal mode mapping that shifts the current line `{count}` times:
```
nnoremap <expr> <F5> ":\<C-u>" . repeat(">", v:count1) . "\<CR>"
nnoremap <expr> <F6> ":\<C-u>" . repeat("<", v:count1) . "\<CR>"
```
and its visual mode ... |
9,831 | <p>If I press <kbd>Ctrl</kbd><kbd>z</kbd> in normal mode, it makes my gVim "minimized" or in vim (not gVim ) it goes back to the shell.</p>
<p>I want to disable this feature but</p>
<ul>
<li>I can't unmap <kbd>Ctrl</kbd><kbd>z</kbd>: <code>unmap <c-z></code> returns <code>no such mapping</code></li>
<li>There i... | [
{
"answer_id": 9833,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 5,
"selected": true,
"text": "<p>So there are several things that you need to understand:</p>\n\n<p>Firstly you can't use <code>:unset suspend</code> and t... | 2016/10/06 | [
"https://vi.stackexchange.com/questions/9831",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9582/"
] | If I press `Ctrl``z` in normal mode, it makes my gVim "minimized" or in vim (not gVim ) it goes back to the shell.
I want to disable this feature but
* I can't unmap `Ctrl``z`: `unmap <c-z>` returns `no such mapping`
* There is no option called `suspend`, allowing me to use `unset suspend`.
I did `:help suspend` but... | So there are several things that you need to understand:
Firstly you can't use `:unset suspend` and that is normal. Suspending Vim is not controlled by an option (that you could unset) but by a command: `:suspend`. See [`:h :suspend`](http://vimdoc.sourceforge.net/htmldoc/starting.html#:suspend)
Secondly you want to ... |
9,846 | <p>For example, if I execute the following command from the terminal: </p>
<pre><code>vim -c PluginList
</code></pre>
<p>this command opens vim and lists my currently installed plugins. How do I execute the above command but redirect the output to my terminal?</p>
| [
{
"answer_id": 9847,
"author": "Dalker",
"author_id": 2058,
"author_profile": "https://vi.stackexchange.com/users/2058",
"pm_score": 0,
"selected": false,
"text": "<p>EDIT: modified original answer to keep only the finished script version.</p>\n\n<p>For future reference to people browsin... | 2016/10/07 | [
"https://vi.stackexchange.com/questions/9846",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7226/"
] | For example, if I execute the following command from the terminal:
```
vim -c PluginList
```
this command opens vim and lists my currently installed plugins. How do I execute the above command but redirect the output to my terminal? | Since you appear to be using Vundle, you could simply grep your `vimrc`:
```
$ grep -c Plugin ~/.vimrc
``` |
9,862 | <p>I have <code>relativenumber</code> turned on and sometimes find it convenient to use ex copy/move/delete on certain lines. For instance, my cursor might be at the top of the screen and there are two lines I want to delete, but they're way down the page. So I run something like <code>:+43,+44d</code>.</p>
<p>Unfortu... | [
{
"answer_id": 9863,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<p>Ex commands have <em>always</em> worked like this:</p>\n\n<ol>\n<li>move the cursor to the given line,</li>\n<li>perform the... | 2016/10/08 | [
"https://vi.stackexchange.com/questions/9862",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2036/"
] | I have `relativenumber` turned on and sometimes find it convenient to use ex copy/move/delete on certain lines. For instance, my cursor might be at the top of the screen and there are two lines I want to delete, but they're way down the page. So I run something like `:+43,+44d`.
Unfortunately, this *moves the cursor* ... | I don't believe there is a way to run an ex command without moving the cursor, but there is a much more convenient way to get back to where you were. When you run an ex command, the current location will be added to your "jumplist". You can use `<C-o>` to move back in the jumplist. From [`:h ctrl-o`](http://vimdoc.sour... |
9,878 | <p>From time to time I have to work with code that isn't indented to the level of indentation I have Vim set up to (4 spaces per level), usually after copy/pasting something in the file. I usually make do with <code><<</code> and <code>>></code>. The problem is they don't jump to the next indentation level,... | [
{
"answer_id": 9882,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 2,
"selected": false,
"text": "<p>If you always want <code>>></code> to indent to the next tabstop and <code><<</code> to delete to the last ta... | 2016/10/10 | [
"https://vi.stackexchange.com/questions/9878",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1545/"
] | From time to time I have to work with code that isn't indented to the level of indentation I have Vim set up to (4 spaces per level), usually after copy/pasting something in the file. I usually make do with `<<` and `>>`. The problem is they don't jump to the next indentation level, they just add or subtract 4 spaces.
... | When you use one of the commands `{count}>>`, `{count}<<`, `>{motion}` or `<{motion}`, on some lines which have already been indented, and you want their new indentation level to be a multiple of your `'shiftwidth'` option value, you can enable the `'shiftround'` option, and add this line in your `vimrc`:
```
set shif... |
9,888 | <p>It is possible to pipe visually selected <em>lines</em> (i.e. selected with uppercase <kbd>V</kbd>) using <kbd>:</kbd>, after which I can enter a command in vim's command line, e.g.:</p>
<pre><code>:'<,'>!python -m base64 -d
</code></pre>
<p>I'd like to do the same for the selected <em>character range</em> ... | [
{
"answer_id": 9882,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 2,
"selected": false,
"text": "<p>If you always want <code>>></code> to indent to the next tabstop and <code><<</code> to delete to the last ta... | 2016/10/11 | [
"https://vi.stackexchange.com/questions/9888",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8856/"
] | It is possible to pipe visually selected *lines* (i.e. selected with uppercase `V`) using `:`, after which I can enter a command in vim's command line, e.g.:
```
:'<,'>!python -m base64 -d
```
I'd like to do the same for the selected *character range* (i.e. selected with lowercase `v`). Using `:` still creates a lin... | When you use one of the commands `{count}>>`, `{count}<<`, `>{motion}` or `<{motion}`, on some lines which have already been indented, and you want their new indentation level to be a multiple of your `'shiftwidth'` option value, you can enable the `'shiftround'` option, and add this line in your `vimrc`:
```
set shif... |
9,896 | <p>I have a large list of scores that looks likes this:</p>
<pre><code>Michelle
,46419
,32413
Frank
,46412
,33810
Steve
,28333
,17830
,37
Joe
,136
,93
Alicia
,121300
,84146
</code></pre>
<p>How can I move my list in Vim so it is re-arranged like this:</p>
<pre><code>Michelle,46419,32413
Frank,46412,33810
Steve,28333... | [
{
"answer_id": 9897,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 4,
"selected": true,
"text": "<p>You can do this with a simple substitute command. Try this:</p>\n\n<pre><code>:%s/\\n,/,\n</code></pre>\n\n<p>This rem... | 2016/10/13 | [
"https://vi.stackexchange.com/questions/9896",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9679/"
] | I have a large list of scores that looks likes this:
```
Michelle
,46419
,32413
Frank
,46412
,33810
Steve
,28333
,17830
,37
Joe
,136
,93
Alicia
,121300
,84146
```
How can I move my list in Vim so it is re-arranged like this:
```
Michelle,46419,32413
Frank,46412,33810
Steve,28333,17830,37
Joe,136,93
Alicia,121300,84... | You can do this with a simple substitute command. Try this:
```
:%s/\n,/,
```
This removes a newline from every line containing a newline followed by a comma. You could also do it like this:
```
:%s/\n\ze,
```
The way this works is by marking the end of the selection to be removed, and the only text that will be ... |
9,905 | <p>I (very) often write python, and I use Vim's python3 backend to test my code. To perform my tests I use:</p>
<pre><code>vnoremap <localleader>p y:<c-r>"<c-b>python3 <cr>
</code></pre>
<p>It simply takes my visual selection and runs within Vim's python backend. This is very practical becau... | [
{
"answer_id": 9918,
"author": "grochmal",
"author_id": 7700,
"author_profile": "https://vi.stackexchange.com/users/7700",
"pm_score": 0,
"selected": false,
"text": "<h3>Workaround</h3>\n\n<p>After a good deal of debugging I found that forcing Vim to have the shared library in memory all... | 2016/10/13 | [
"https://vi.stackexchange.com/questions/9905",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7700/"
] | I (very) often write python, and I use Vim's python3 backend to test my code. To perform my tests I use:
```
vnoremap <localleader>p y:<c-r>"<c-b>python3 <cr>
```
It simply takes my visual selection and runs within Vim's python backend. This is very practical because I can re-run only pieces of code (and I'm careful... | This is because your numpy isn't linked against the Python 3 library (no `-lpython3` used). This is fine for most applications that has the library loaded into global space, but Vim uses `RTLD_LOCAL` so numpy's libraries don't see Python 3's symbols unless it's linked against it.
`LD_PRELOAD` is fine as long as you do... |
9,941 | <p>I can check vim's version by using <code>v:version</code>,
and I can check if I am running in nvim by doing <code>has('nvim')</code>. Is there a variable like <code>v:version</code> in neovim to let me know the nvim version, like <code>0.1.4</code> or <code>0.1.6</code>?</p>
| [
{
"answer_id": 9942,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 3,
"selected": false,
"text": "<p>There is probably a direct way (?); if not, here's a function that parses <code>:version</code> to extract and return t... | 2016/10/17 | [
"https://vi.stackexchange.com/questions/9941",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9681/"
] | I can check vim's version by using `v:version`,
and I can check if I am running in nvim by doing `has('nvim')`. Is there a variable like `v:version` in neovim to let me know the nvim version, like `0.1.4` or `0.1.6`? | As mentioned in comments elsewhere, you can use `has`. For generic "is this neovim":
```
:echo has('nvim')
```
For at least minor version `0.1` (latest as of this writing):
```
:echo has('nvim-0.1')
```
For at least patch version `0.1.6`:
```
:echo has('nvim-0.1.6')
``` |
9,951 | <p>Basically, I'd like to have long entries for bulleted / numbered lists that automatically indent like so:</p>
<pre><code>1. Congress shall make no law respecting an establishment of
religion, or prohibiting the free exercise thereof; or
abridging the freedom of speech, or of the press; or the
right of t... | [
{
"answer_id": 22622,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>As of Vim 8.2.0139, there are no configuration options to specify this behaviour. Furthermore, any changes to the behaviour ... | 2016/10/18 | [
"https://vi.stackexchange.com/questions/9951",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2593/"
] | Basically, I'd like to have long entries for bulleted / numbered lists that automatically indent like so:
```
1. Congress shall make no law respecting an establishment of
religion, or prohibiting the free exercise thereof; or
abridging the freedom of speech, or of the press; or the
right of the people peac... | As of Vim 8.2.0139, there are no configuration options to specify this behaviour. Furthermore, any changes to the behaviour of Vim's soft wrapping via `'wrap'` will require implementing in the source code: there is no workaround possible by using Vimscript.\*
See the [feature request that Ryan Lue (who asked this ques... |
9,953 | <p>Is there a way I can perform a batch-regex-replace using a list of words?</p>
<p>Simplified example: </p>
<h1>List of words</h1>
<pre><code>Apple
Cabbage
Turtle
</code></pre>
<h1>Text to search</h1>
<pre><code>Bike 2
Turtle 5
Bike 3
Bike 5
Cabbage 2
Bike 0
Bike 0
Apple 1
</code></pre>
<h1>O... | [
{
"answer_id": 9954,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 1,
"selected": false,
"text": "<p>You can make a list in regular expressions using the or operator: <code>\\|</code> So yours would look something like:... | 2016/10/18 | [
"https://vi.stackexchange.com/questions/9953",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9755/"
] | Is there a way I can perform a batch-regex-replace using a list of words?
Simplified example:
List of words
=============
```
Apple
Cabbage
Turtle
```
Text to search
==============
```
Bike 2
Turtle 5
Bike 3
Bike 5
Cabbage 2
Bike 0
Bike 0
Apple 1
```
Output
======
```
Turtle = 5;
Cabbage... | You can make a list in regular expressions using the or operator: `\|` So yours would look something like:
```
:%s/\(Apple\|Cabbage\|Turtle\)\s\+\(\d\+\)/\1 = \2;/
```
Then if you wanted to delete the rest of the lines that didn't match you could use a global command:
```
:g!/Apple\|Cabbage\|Turtle/ d
```
See `:h... |
9,957 | <p>I know I can <code>:set ignorecase smartcase</code> to get autompletion to be case-insensitive <strong>but</strong> this has the side-effect of making <em>all</em> searches case-insensitive unless they contain an uppercase character.</p>
<p>I have tried the following to attempt a per-command setting of <code>ignore... | [
{
"answer_id": 9958,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 3,
"selected": true,
"text": "<p>It's not straight-forward, but it's possible to do this with <code>:h map-<expr></code> and some script:</p>\n\n<pr... | 2016/10/19 | [
"https://vi.stackexchange.com/questions/9957",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8520/"
] | I know I can `:set ignorecase smartcase` to get autompletion to be case-insensitive **but** this has the side-effect of making *all* searches case-insensitive unless they contain an uppercase character.
I have tried the following to attempt a per-command setting of `ignorecase`, but had no luck:
```
inoremap <C-N> <C... | It's not straight-forward, but it's possible to do this with `:h map-<expr>` and some script:
```
augroup toggle_compl_ignorecase
autocmd!
autocmd CompleteDone,InsertLeave *
\ if exists('s:ignorecase') |
\ let &ignorecase = s:ignorecase |
\ unlet! s:ignorecase |
\ endif
augroup ... |
9,959 | <p>To make the usage of vim in cygwin convenient, I've added the color scheme in <a href="https://github.com/Marslo/VimConfig/blob/master/Configurations/vimrc_cygwin" rel="nofollow noreferrer">my cygwin .vimrc</a>. But I found the color scheme doesn't work when vim is started. </p>
<p>So I did some investigations:</p>... | [
{
"answer_id": 9960,
"author": "Marslo",
"author_id": 7389,
"author_profile": "https://vi.stackexchange.com/users/7389",
"pm_score": 2,
"selected": false,
"text": "<p>Okay, Okay, I found the reason. There's code shows in <code>/usr/share/vim/vim74/syntax/synload.vim</code>:\n<a href=\"ht... | 2016/10/19 | [
"https://vi.stackexchange.com/questions/9959",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7389/"
] | To make the usage of vim in cygwin convenient, I've added the color scheme in [my cygwin .vimrc](https://github.com/Marslo/VimConfig/blob/master/Configurations/vimrc_cygwin). But I found the color scheme doesn't work when vim is started.
So I did some investigations:
1. My Cygwin indeed support `xterm-256color`. [Th... | There's a simpler workaround. Just add `let g:syntax_cmd = "skip"` to your .vimrc.
From [`:h syntax_cmd`](http://vimdoc.sourceforge.net/htmldoc/syntax.html#syntax_cmd):
```
The "syntax_cmd" variable is set to one of these values when the
syntax/syncolor.vim files are loaded:
"on" ":syntax on" command. Highlig... |
9,962 | <p>Is there a way to get filetype for given extension or filename</p>
<p>For example:</p>
<pre><code>let my_f='text.rb'
let my_ft=GetFileType(my_f)
echo my_ft
" should output ruby
</code></pre>
| [
{
"answer_id": 9963,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": true,
"text": "<p>As Christian said, parsing the expression won't be the easier way. I'd even say that's insufficient. Some filetypes sh... | 2016/10/19 | [
"https://vi.stackexchange.com/questions/9962",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7820/"
] | Is there a way to get filetype for given extension or filename
For example:
```
let my_f='text.rb'
let my_ft=GetFileType(my_f)
echo my_ft
" should output ruby
``` | As Christian said, parsing the expression won't be the easier way. I'd even say that's insufficient. Some filetypes share the same file extension. In that case, vim parses a few lines from the files to deduce exactly their filetype.
Otherwise, you could indeed parse `filetype.vim`, but instead, I'd parse the result of... |
9,965 | <p>Using atom I can <kbd>Ctrl</kbd><kbd>Shift</kbd><kbd>f</kbd> while a word is selected in order to start a multi file search for a matching string.</p>
<p>I would like to emulate this flow as much as possible with Vim.</p>
<p>I know I can yank the text, type: <code>:grep -F</code> and then paste it using <code><... | [
{
"answer_id": 9969,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": true,
"text": "<p>You can reference the word/WORD under the cursor with:</p>\n\n<pre><code><C-r><C-w>\n<C-r><C-a>\n</... | 2016/10/19 | [
"https://vi.stackexchange.com/questions/9965",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9761/"
] | Using atom I can `Ctrl``Shift``f` while a word is selected in order to start a multi file search for a matching string.
I would like to emulate this flow as much as possible with Vim.
I know I can yank the text, type: `:grep -F` and then paste it using `<ctrl+r>"`
Is there a way to do this in fewer keystrokes? | You can reference the word/WORD under the cursor with:
```
<C-r><C-w>
<C-r><C-a>
```
So instead of yanking, you can directly have:
```
:grep -F <C-r><C-w>
```
Or even shorter with a mapping:
```
nnoremap <C-f> :grep -F "<C-R><C-W>"
```
Now if you want to search for a visually selected part of your file you can... |
9,967 | <p>Sometimes in my workflow, I might want to open or search for a file on the go.</p>
<p>I'd like to map a single key (say <kbd>F6</kbd>) to open and close NERDTree (<em>i.e.</em>, I want to toggle the NERDTree view). Also, I'd like NERDTree to display hidden files and folders in its toggled view, and I'd also like it ... | [
{
"answer_id": 9968,
"author": "Atropo",
"author_id": 9763,
"author_profile": "https://vi.stackexchange.com/users/9763",
"pm_score": 7,
"selected": true,
"text": "<p>In your <code>vimrc</code> add</p>\n\n<pre><code>nmap <F6> :NERDTreeToggle<CR>\n</code></pre>\n\n<p>where <cod... | 2016/10/19 | [
"https://vi.stackexchange.com/questions/9967",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9760/"
] | Sometimes in my workflow, I might want to open or search for a file on the go.
I'd like to map a single key (say `F6`) to open and close NERDTree (*i.e.*, I want to toggle the NERDTree view). Also, I'd like NERDTree to display hidden files and folders in its toggled view, and I'd also like it to close automatically wh... | In your `vimrc` add
```
nmap <F6> :NERDTreeToggle<CR>
```
where `<F6>` is the key you want to map. |
9,977 | <p>I'd like to make a plugin to display currently pending keys while in operator-pending mode. As the first part of that, how would I register an autocmd to run when operator-pending mode is entered? I'm using neovim, so I'm totally cool if it only works there.</p>
| [
{
"answer_id": 9968,
"author": "Atropo",
"author_id": 9763,
"author_profile": "https://vi.stackexchange.com/users/9763",
"pm_score": 7,
"selected": true,
"text": "<p>In your <code>vimrc</code> add</p>\n\n<pre><code>nmap <F6> :NERDTreeToggle<CR>\n</code></pre>\n\n<p>where <cod... | 2016/10/19 | [
"https://vi.stackexchange.com/questions/9977",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9767/"
] | I'd like to make a plugin to display currently pending keys while in operator-pending mode. As the first part of that, how would I register an autocmd to run when operator-pending mode is entered? I'm using neovim, so I'm totally cool if it only works there. | In your `vimrc` add
```
nmap <F6> :NERDTreeToggle<CR>
```
where `<F6>` is the key you want to map. |
9,992 | <p>I know that I can paste the clipboard in by by typing <kbd>ctrl-shift-v</kbd>.</p>
<p>The problem is that this is a very counterintuitive shortcut. It requires me to move my hand in a very uncomfortable way.</p>
<p>I would like to paste the clipboard with something better, such as <code>gcp</code>.</p>
<p>I am tr... | [
{
"answer_id": 9993,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 2,
"selected": false,
"text": "<p>Assuming Vim has access to the clipboard, you can insert the clipboard contents (in Vim register <code>+</code>) via <... | 2016/10/21 | [
"https://vi.stackexchange.com/questions/9992",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/605/"
] | I know that I can paste the clipboard in by by typing `ctrl-shift-v`.
The problem is that this is a very counterintuitive shortcut. It requires me to move my hand in a very uncomfortable way.
I would like to paste the clipboard with something better, such as `gcp`.
I am trying to put a line in my vimrc file that wil... | *Update: In order to access the system clipboard(s) Vim needs to be compiled with support for this. You can use the commands `:echo has('clipboard')` and, on Unix, `:echo has('xterm_clipboard')` to check for this. As it turns out, question asker did* not *have these features compiled in. Their `ctrl-shift-v` shortcut w... |
9,999 | <p>Fo example, this piece of code in rails:</p>
<pre><code> t.string :receipt_number
t.timestamp :transaction_timestamp
t.string :transaction_type
t.decimal :cash_amount
t.decimal :card_amount
</code></pre>
<p>Now, I want new code should be:</p>
<pre><code> t.string :receipt_number
t.timestamp :tr... | [
{
"answer_id": 10000,
"author": "dNitro",
"author_id": 7976,
"author_profile": "https://vi.stackexchange.com/users/7976",
"pm_score": 1,
"selected": false,
"text": "<p>Aligning delimiter is controlled by <code>stick-to-left</code> option. Its a boolean controlling whether to position del... | 2016/10/21 | [
"https://vi.stackexchange.com/questions/9999",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7078/"
] | Fo example, this piece of code in rails:
```
t.string :receipt_number
t.timestamp :transaction_timestamp
t.string :transaction_type
t.decimal :cash_amount
t.decimal :card_amount
```
Now, I want new code should be:
```
t.string :receipt_number
t.timestamp :transaction_timestamp
t.string :... | Here's an admittedly hacky solution in pure vimscript:
```
:%norm dt::left 17<C-v><CR>0:exec "norm R".getreg('"')<C-v><CR>
```
Obviously, you can changed `17` to whatever value works best with your text.
Explanation:
The way this works is by deleting everything up to the first colon before aligning. Then after tha... |
10,007 | <p>I have a Bash script which sources variables from another file. It passes the <code>shellcheck -x</code>, however Syntastic always complains:</p>
<blockquote>
<p>Not following: sourced_file.sh was not specified as input (see shellcheck -x). [SC1091]</p>
</blockquote>
<p>The script is:</p>
<pre><code>#!/bin/bash... | [
{
"answer_id": 10013,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 5,
"selected": true,
"text": "<p>As noted, <a href=\"https://github.com/scrooloose/syntastic#faqargs\" rel=\"noreferrer\">the FAQ says</a>:</p>\n\n<blockquote... | 2016/10/22 | [
"https://vi.stackexchange.com/questions/10007",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5334/"
] | I have a Bash script which sources variables from another file. It passes the `shellcheck -x`, however Syntastic always complains:
>
> Not following: sourced\_file.sh was not specified as input (see shellcheck -x). [SC1091]
>
>
>
The script is:
```
#!/bin/bash
. sourced_file.sh
echo ${variable1}
```
The `sou... | As noted, [the FAQ says](https://github.com/scrooloose/syntastic#faqargs):
>
> **4.5. Q. How can I pass additional arguments to a checker?**
>
>
> A. In most cases a command line is constructed using an internal
> function named `makeprgBuild()`, which provides a number of options
> that allow you to customise ev... |
10,016 | <p>I use both <code>CtrlP</code> and <code>NERDTree</code> in my Vim. When I open a file using the <code>CtrlP</code> search feature, it sometimes opens in the NERDTree window (and always if the NERD window is the active one).</p>
<p><strong>How can I stop <code>CtrlP</code> from opening files in NERDTree, and force i... | [
{
"answer_id": 10866,
"author": "jonasl",
"author_id": 10725,
"author_profile": "https://vi.stackexchange.com/users/10725",
"pm_score": 2,
"selected": false,
"text": "<p>I've tripped on this one too many times too:</p>\n\n<p>I've solved it by remapping the <code><c-p></code> to clo... | 2016/10/23 | [
"https://vi.stackexchange.com/questions/10016",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/969/"
] | I use both `CtrlP` and `NERDTree` in my Vim. When I open a file using the `CtrlP` search feature, it sometimes opens in the NERDTree window (and always if the NERD window is the active one).
**How can I stop `CtrlP` from opening files in NERDTree, and force it to open them in the main window?** I've tried going throug... | Finally found a way to do this that doesn't involve closing NERDTree all the time.
I made a function that cycles through the open windows until it finds a writable buffer, then runs ctrl-p there:
```
function! CtrlPCommand()
let c = 0
let wincount = winnr('$')
" Don't open it here if current buffer is not... |
10,028 | <p>I'm switching from <code>vim</code> to <code>neovim</code>, but when starting <code>neovim</code>, I get the following error on startup:</p>
<blockquote>
<p>E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3</p>
</blockquote>
<p>What does this mean, and how do I stop <code>neovim</code... | [
{
"answer_id": 10029,
"author": "Tom Hale",
"author_id": 5324,
"author_profile": "https://vi.stackexchange.com/users/5324",
"pm_score": 3,
"selected": false,
"text": "<p>TL;DR: skip to the <code>Resolution</code> section.</p>\n\n<h3>Background</h3>\n\n<p>The issue is that <code>neovim</c... | 2016/10/25 | [
"https://vi.stackexchange.com/questions/10028",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5324/"
] | I'm switching from `vim` to `neovim`, but when starting `neovim`, I get the following error on startup:
>
> E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3
>
>
>
What does this mean, and how do I stop `neovim` complaining about it?
Note: I want to be able to use both `vim` and `neov... | TL;DR: skip to the `Resolution` section.
### Background
The issue is that `neovim` can't read/write `vim`'s `viminfo` file format.
Instead of using `vim`'s`viminfo` format for storing editing session information, `neovim` uses a [shada-file](https://neovim.io/doc/user/starting.html#shada-file) for "SHAred DAta".
Th... |
10,031 | <p>I often find scrolling a full page too disorienting, half a page too much, but a quarter page is just right. I currently do it just by holding down the arrow keys.</p>
<p>How do I scroll 25% of the page down and up easily?</p>
| [
{
"answer_id": 10032,
"author": "A. Dziedziczak",
"author_id": 9294,
"author_profile": "https://vi.stackexchange.com/users/9294",
"pm_score": 3,
"selected": false,
"text": "<p>You can use <kbd>ctrl</kbd><kbd>e</kbd> and <kbd>ctrl</kbd><kbd>y</kbd> to move the page by one line up and down... | 2016/10/25 | [
"https://vi.stackexchange.com/questions/10031",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9536/"
] | I often find scrolling a full page too disorienting, half a page too much, but a quarter page is just right. I currently do it just by holding down the arrow keys.
How do I scroll 25% of the page down and up easily? | Maybe `ctrl``d` and `ctrl``u` could be what you are looking for. By default they move half of the screen.
From [`:h CTRL-D`](http://vimhelp.appspot.com/scroll.txt.html#CTRL%2DD):
>
> Scroll window Downwards in the buffer. The number of
> lines comes from the 'scroll' option (default: half a
> screen).
>
>
> If [... |
10,049 | <h2>Foreword</h2>
<p>I'm using the "indent with tabs, align with spaces" ideology for indentation. This means that each line in a file can be prefixed with an arbitrary amount of tabs and spaces (as opposed to "only spaces" or "tabs when possible, then <code>0 ≤ x < tabstop</code> spaces"). For example:</p>
<pre><... | [
{
"answer_id": 14474,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 0,
"selected": false,
"text": "<p><code>:nnoremap >> I<tab><esc>^</code></p>\n\n<p><code>:nnoremap << :s/\\v^\\t//<cr></code... | 2016/10/26 | [
"https://vi.stackexchange.com/questions/10049",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7826/"
] | Foreword
--------
I'm using the "indent with tabs, align with spaces" ideology for indentation. This means that each line in a file can be prefixed with an arbitrary amount of tabs and spaces (as opposed to "only spaces" or "tabs when possible, then `0 ≤ x < tabstop` spaces"). For example:
```
<--># use OLS (ordinary... | With the help of [this](https://vi.stackexchange.com/a/14474/20429), [this](https://unix.stackexchange.com/a/544418/307359), and [this](https://superuser.com/a/207521/943615), I come up with this:
```
nnoremap >> 0i<tab><esc>^
nnoremap << :norm 0ldF<tab><enter>^
```
For multiline selection (works on `VISUAL`, `VISUA... |
10,062 | <p>When executing an ex command I can use the variable <code>v:count</code> to get the count which was given to this command. From <a href="http://vimhelp.appspot.com/eval.txt.html#v%3Acount" rel="nofollow noreferrer"><code>:h v:count</code></a>, if I create this mapping:</p>
<pre><code>:map _x :<C-U>echo "the c... | [
{
"answer_id": 10364,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>It seems that there is no built-in way to do what I want. So I came up with this small chunk of code following @DjMcMayh... | 2016/10/28 | [
"https://vi.stackexchange.com/questions/10062",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | When executing an ex command I can use the variable `v:count` to get the count which was given to this command. From [`:h v:count`](http://vimhelp.appspot.com/eval.txt.html#v%3Acount), if I create this mapping:
```
:map _x :<C-U>echo "the count is " . v:count<CR>
```
And use `12``\_``x` I'll get a message
```
the c... | It seems that there is no built-in way to do what I want. So I came up with this small chunk of code following @DjMcMayhem comment. It is not extensively tested but it seems to be working.
First let's remap `@` to call our custom function:
```
nnoremap <silent> @ :<C-U>call MacroWithCount()<CR>
```
And the function... |
10,067 | <p>I have these two functions</p>
<pre><code> void function_one(){
return;
}
void function_two()
{
return;
}
</code></pre>
<p>when I use <code>zM</code> to fold the functions I get</p>
<pre><code> +-- 3 lines: void function_one(){--
void function_two()
+-- 3 lines: {-
</code></pre>
<p>the ... | [
{
"answer_id": 10068,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>I did define <a href=\"https://github.com/LucHermitte/VimFold4C\" rel=\"nofollow\">VimFold4C</a> that tries its best... | 2016/10/28 | [
"https://vi.stackexchange.com/questions/10067",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9897/"
] | I have these two functions
```
void function_one(){
return;
}
void function_two()
{
return;
}
```
when I use `zM` to fold the functions I get
```
+-- 3 lines: void function_one(){--
void function_two()
+-- 3 lines: {-
```
the `function_two` doesn't get a nice folding, How I can get the... | I did define [VimFold4C](https://github.com/LucHermitte/VimFold4C) that tries its best to fold C & C++ codes. The caveat is when we are modifying the code: I'm using caches in order to speed up the fold processing, but alas it has quirks. |
10,070 | <p>I work with lots of different servers and would like to unify my vimrc across them all. I see that vim has the source command, which I'm assuming works similar to bash. In bash, to source a file from a webpage you go </p>
<pre><code>. <(curl -s domain.com)
</code></pre>
<p>How can I do this with vim? I'm aware ... | [
{
"answer_id": 10073,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": false,
"text": "<p>AFAIK, <code>source</code> doesn't let you source anything other than a file.</p>\n<p>This function is a little bit dirty... | 2016/10/28 | [
"https://vi.stackexchange.com/questions/10070",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8456/"
] | I work with lots of different servers and would like to unify my vimrc across them all. I see that vim has the source command, which I'm assuming works similar to bash. In bash, to source a file from a webpage you go
```
. <(curl -s domain.com)
```
How can I do this with vim? I'm aware that I can instead apply each... | From `:h -u`:
```
-u {vimrc} The file {vimrc} is read for initializations. Most other
initializations are skipped; see |initialization|. This can
be used to start Vim in a special mode, with special
mappings and settings. A shell alias can be used to make
this easy to use. For exam... |
10,072 | <p>Recently I decided to switch from Vundle to VimPlug, and I noticed that after installing it...</p>
<ul>
<li><p>putting the <code>plug.vim</code> in my autoload directory <code>~/.vim/autoload/</code></p></li>
<li><p>and making sure that my vim and neovim was symbol linked so I didn't have to create a whole new set ... | [
{
"answer_id": 10110,
"author": "PrimRock",
"author_id": 9885,
"author_profile": "https://vi.stackexchange.com/users/9885",
"pm_score": 3,
"selected": true,
"text": "<p>For whatever reason it doesn't seem to see VimPlug with the first symbolic link I had in my post. This is the only plug... | 2016/10/28 | [
"https://vi.stackexchange.com/questions/10072",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9885/"
] | Recently I decided to switch from Vundle to VimPlug, and I noticed that after installing it...
* putting the `plug.vim` in my autoload directory `~/.vim/autoload/`
* and making sure that my vim and neovim was symbol linked so I didn't have to create a whole new set of directories just for neovim with this...
```
ln ... | For whatever reason it doesn't seem to see VimPlug with the first symbolic link I had in my post. This is the only plugin I couldn't get to work in neovim with it.
So instead of making a symbolic link of `~/.vim` to `~/.config/nvim`. I decided to make a symbolic link of `~/.vim` to `~/.config/` (*note that I'm trunca... |
10,087 | <p>Given this file:</p>
<pre><code>printf 'hello\x19world\n' > hello.txt
</code></pre>
<p>I can replace a hex character:</p>
<pre><code>$ ex -sc '%s/\%x19/ /|x' hello.txt
$ od -c hello.txt
0000000 h e l l o w o r l d \n
</code></pre>
<p>However I cannot replace with a hex character:</p>
... | [
{
"answer_id": 10089,
"author": "Wildcard",
"author_id": 4676,
"author_profile": "https://vi.stackexchange.com/users/4676",
"pm_score": 4,
"selected": true,
"text": "<p>From <code>:help todo</code>:</p>\n\n<blockquote>\n <p>Substitute with hex/unicode number \"\\%xff\" and \"\\%uabcd\".... | 2016/10/30 | [
"https://vi.stackexchange.com/questions/10087",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | Given this file:
```
printf 'hello\x19world\n' > hello.txt
```
I can replace a hex character:
```
$ ex -sc '%s/\%x19/ /|x' hello.txt
$ od -c hello.txt
0000000 h e l l o w o r l d \n
```
However I cannot replace with a hex character:
```
$ ex -sc '%s/ /\%x19/|x' hello.txt
$ od -c hello.tx... | From `:help todo`:
>
> Substitute with hex/unicode number "\%xff" and "\%uabcd". Just like
> "\%uabcd" in search pattern.
>
>
>
In other words, this isn't implemented yet.
You can do it interactively, in Vim. See `:help 24.8`.
Type `:%s/ /`, then type `Ctrl-V`, then `x19`, then press Enter. |
10,093 | <p><a href="https://i.stack.imgur.com/8M1uc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8M1uc.png" alt="enter image description here"></a></p>
<ul>
<li><p>3rd block of code needs to go from <code>ipt1</code> to <code>ipt4</code></p></li>
<li><p>4th block of code needs to go from <code>ipt1</code... | [
{
"answer_id": 10094,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 2,
"selected": false,
"text": "<p>Using visual mode and substitution:</p>\n\n<pre><code>v/}<CR>s/ipt1/ipt4<CR>\n</code></pre>\n\n<p>Using substit... | 2016/10/31 | [
"https://vi.stackexchange.com/questions/10093",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | [](https://i.stack.imgur.com/8M1uc.png)
* 3rd block of code needs to go from `ipt1` to `ipt4`
* 4th block of code needs to go from `ipt1` to `ipt5`
Because it is only 3 selections, creating a macro is probably slower than manually, but doing it manua... | Using visual mode and substitution:
```
v/}<CR>s/ipt1/ipt4<CR>
```
Using substitution only:
```
:,/}/s/ipt1/ipt5<CR>
``` |
10,098 | <p>I saw an editor command which started like this:</p>
<pre><code>:%! sort
</code></pre>
<p>What does that mean? Specifically, the <code>:%!</code>.</p>
| [
{
"answer_id": 10100,
"author": "Jair López",
"author_id": 6698,
"author_profile": "https://vi.stackexchange.com/users/6698",
"pm_score": 3,
"selected": false,
"text": "<p>From <a href=\"http://vimhelp.appspot.com/cmdline.txt.html#%3a%25\" rel=\"noreferrer\"><code>:help :%</code></a>:</p... | 2016/10/31 | [
"https://vi.stackexchange.com/questions/10098",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9024/"
] | I saw an editor command which started like this:
```
:%! sort
```
What does that mean? Specifically, the `:%!`. | ```
:%! command
```
pipes the current file's contents to `command`'s stdin, and replaces the file's contents with `command`'s stdout.
So, `:%! sort` is pretty much the same as (from a shell) `cat file | sort > tmp && mv tmp file`. |
10,111 | <p>I am using Ubuntu 16.04. I installed Neovim using apt-get. I downloaded the plug.vim script & put it into the <code>autoload</code> folder in <code>~/.config/nvim</code>. I put the following in my <code>init.vim</code>:</p>
<pre><code>call plug#begin()
Plug 'https://github.com/luochen1990/rainbow.git'
Plug 'htt... | [
{
"answer_id": 10112,
"author": "SnoringFrog",
"author_id": 1166,
"author_profile": "https://vi.stackexchange.com/users/1166",
"pm_score": 0,
"selected": false,
"text": "<p>From the <a href=\"https://github.com/neovim/neovim/wiki/FAQ\" rel=\"nofollow noreferrer\">NeoVim FAQ</a>:</p>\n\n<... | 2016/11/01 | [
"https://vi.stackexchange.com/questions/10111",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9938/"
] | I am using Ubuntu 16.04. I installed Neovim using apt-get. I downloaded the plug.vim script & put it into the `autoload` folder in `~/.config/nvim`. I put the following in my `init.vim`:
```
call plug#begin()
Plug 'https://github.com/luochen1990/rainbow.git'
Plug 'https://github.com/davisdude/vim-love-docs.git'
Plug '... | My guess is that you haven't activated the plug-ins. In the `rainbow` case you should add
```
let g:rainbow_active = 1
```
to your init file (Neovim's one is located in `~/.config/nvim/init.vim`). In case of `gruvbox` you should add
```
colorscheme gruvbox
```
Usually it's done after the `plug#end()`.
As for `v... |
10,122 | <p>The question is more or less in the title, until recently I have the feeling that I got a fairly large number of visible tabs in any window of MacVim. I either updated MacVim or my system or something and now I can only get 5 visible tabs in a 90 character wide window. Is there any way to increase this number? </p>
... | [
{
"answer_id": 10131,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 0,
"selected": false,
"text": "<p>There's the <code>tabpagemax</code> option that limits the number of tab pages you can open with <code>$ vim -p *.txt</code... | 2016/11/02 | [
"https://vi.stackexchange.com/questions/10122",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9959/"
] | The question is more or less in the title, until recently I have the feeling that I got a fairly large number of visible tabs in any window of MacVim. I either updated MacVim or my system or something and now I can only get 5 visible tabs in a 90 character wide window. Is there any way to increase this number?
I'm us... | Apparently the minimum width of a tab is configurable, and set by default to 120 (pixels). It can be redefined by doing:
```
defaults write org.vim.MacVim MMTabMinWidth 55
```
where 55 is the minimum width of a tab in pixels. This allows me to get 11 tabs in a window of 90 characters, which solves my problem. |
10,148 | <p>With the release of vim 8, I was wondering if there is a way to execute <code>:s</code> or <code>:g</code> asynchronously.</p>
| [
{
"answer_id": 10131,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 0,
"selected": false,
"text": "<p>There's the <code>tabpagemax</code> option that limits the number of tab pages you can open with <code>$ vim -p *.txt</code... | 2016/11/03 | [
"https://vi.stackexchange.com/questions/10148",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7327/"
] | With the release of vim 8, I was wondering if there is a way to execute `:s` or `:g` asynchronously. | Apparently the minimum width of a tab is configurable, and set by default to 120 (pixels). It can be redefined by doing:
```
defaults write org.vim.MacVim MMTabMinWidth 55
```
where 55 is the minimum width of a tab in pixels. This allows me to get 11 tabs in a window of 90 characters, which solves my problem. |
10,161 | <p>An editing pattern I frequently run into is the following: I want to yank a piece of text inside quotes or brackets, and replace that piece of text inside another pair of quotes/brackets.</p>
<p>For example, if I want to copy the the class name <code>foo bar</code> and paste that somewhere else:</p>
<pre><code><... | [
{
"answer_id": 10163,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 6,
"selected": true,
"text": "<p>You can use <code>vi\"p</code> when inside <code>\"\"</code>. This can replace text in yank register, so it matters when... | 2016/11/04 | [
"https://vi.stackexchange.com/questions/10161",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8831/"
] | An editing pattern I frequently run into is the following: I want to yank a piece of text inside quotes or brackets, and replace that piece of text inside another pair of quotes/brackets.
For example, if I want to copy the the class name `foo bar` and paste that somewhere else:
```
<span class="foo bar">
<div class=... | You can use `vi"p` when inside `""`. This can replace text in yank register, so it matters when you want to use original yanked text more than once.
**EDIT**:
Additional info from Octaviour comment regarding making it reusable more than once:
>
> In order to do that I would yank to a named register, which makes the ... |
10,167 | <p>Is there way I can identify a window by a number in neovim and then jump to it with a macro ? Or better yet...Is there a way that I can identify which window is a terminal after calling the <code>:term</code> command and then jump to it ?</p>
<p>I know there's window number system in <code>tmux</code> that's simila... | [
{
"answer_id": 10170,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 2,
"selected": false,
"text": "<p>You will need to write a function for that (<a href=\"https://www.reddit.com/r/vim/comments/3aldvk/switch_to_a_split_dependin... | 2016/11/04 | [
"https://vi.stackexchange.com/questions/10167",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9885/"
] | Is there way I can identify a window by a number in neovim and then jump to it with a macro ? Or better yet...Is there a way that I can identify which window is a terminal after calling the `:term` command and then jump to it ?
I know there's window number system in `tmux` that's similar to that.
The problem is I wro... | statox's comment works, but for what you want, it's not the best solution. You can't simply check for `&buftype == 'terminal`. A terminal buffer could be created by a plugin such as [fzf](https://github.com/junegunn/fzf) and you could end up in a weird state if you blindly try to send text into it.
Plugin
------
Prob... |
10,174 | <p>I am using Vim version 7.4 from 2012-Dez-06 of Ubuntu 16.04, and I use PuTTY 0.67 on W10. I want to map the keys of the NUM pad in <code>.vimrc</code>. This doesn't work:</p>
<pre><code>map <k1> COMMAND
map k1 COMMAND
map <C-k1> COMMAND
map <S-k1> COMMAND
map *keypad-1* COMMAND
map keypad-1 COMMAND... | [
{
"answer_id": 10175,
"author": "Ashok Arora",
"author_id": 9004,
"author_profile": "https://vi.stackexchange.com/users/9004",
"pm_score": 2,
"selected": false,
"text": "<p>The keypad identifiers have a k* prefix.\nLike mapping control + numkey 1 to :NerdTree would be </p>\n\n<pre><code>... | 2016/11/04 | [
"https://vi.stackexchange.com/questions/10174",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9517/"
] | I am using Vim version 7.4 from 2012-Dez-06 of Ubuntu 16.04, and I use PuTTY 0.67 on W10. I want to map the keys of the NUM pad in `.vimrc`. This doesn't work:
```
map <k1> COMMAND
map k1 COMMAND
map <C-k1> COMMAND
map <S-k1> COMMAND
map *keypad-1* COMMAND
map keypad-1 COMMAND
```
If I do for example:
```
map 1 dd
... | The default settings of PuTTY are just fine. Do not change anything in `PuTTY-> Terminal -> Keyboard` (see above) or disable in `PuTTY-> Terminal -> Features` anything:
[](https://i.stack.imgur.com/is7Wh.jpg)
You can map in vi the NUM keys in the fol... |
10,176 | <p>Currently I'm using this to open a file in an existing vim instance.</p>
<pre><code>gvim --remote-silent some_file.txt
</code></pre>
<p>While it opens the file as expected, it <em>sometimes</em> splits the window.</p>
<p>I'm not sure what logic it uses, but I'd like to be able to tell it <em>never</em> to create ... | [
{
"answer_id": 15032,
"author": "calocedrus",
"author_id": 12085,
"author_profile": "https://vi.stackexchange.com/users/12085",
"pm_score": 0,
"selected": false,
"text": "<p>I may be off from your actual purpose and you may already know what I suggest here, but how about opening the file... | 2016/11/04 | [
"https://vi.stackexchange.com/questions/10176",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | Currently I'm using this to open a file in an existing vim instance.
```
gvim --remote-silent some_file.txt
```
While it opens the file as expected, it *sometimes* splits the window.
I'm not sure what logic it uses, but I'd like to be able to tell it *never* to create a new split-window for the new buffer since it ... | When you use Vim's `--remote` options, it constructs a `:drop` command.
If the specified file is not already open in an existing window, it will be opened in the current window, unless the file currently in that window cannot be `abandon`ed. (i.e. if the current file is modified and you have both `hidden` and `autowri... |
10,183 | <p>I want to use the Solarized Light theme in both my Terminal and VIM.</p>
<p>I seem to have got it working in Terminal, I downloaded the entire package from their website, <code>tree</code> output, and then in my terminal preferences I imported the <code>Solarized Light xterm-256color</code> profile from the downloa... | [
{
"answer_id": 10186,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 1,
"selected": false,
"text": "<p>According to <a href=\"https://github.com/altercation/vim-colors-solarized#important-note-for-terminal-users\" rel=\"no... | 2016/11/05 | [
"https://vi.stackexchange.com/questions/10183",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9024/"
] | I want to use the Solarized Light theme in both my Terminal and VIM.
I seem to have got it working in Terminal, I downloaded the entire package from their website, `tree` output, and then in my terminal preferences I imported the `Solarized Light xterm-256color` profile from the download.
[![enter image description h... | I fixed the issue by setting `g:solarized_termcolors` to `16` instead of `256`.
```
let g:solarized_termcolors=16
``` |
10,193 | <p>I've written regexes for markdown for emphasis and bold as follows:</p>
<pre><code>syntax match PandocEmphasisMarker "\v(^|\s+)\zs_[^\n\t_ ]+([^_\n]|(\S_\S)|(\s_\S)|(\s+_\s+))+[^\n\t_ ]+_\ze($|\s+)" contains=PandocEmphasis
syntax match PandocEmphasis "\v\zs[^\n\t_ ]+([^_\n]|(\S_\S)|(\s_\S)|(\s+_\s+))+[^\n\t_ ]+\ze"... | [
{
"answer_id": 10220,
"author": "TonioElGringo",
"author_id": 5590,
"author_profile": "https://vi.stackexchange.com/users/5590",
"pm_score": 1,
"selected": false,
"text": "<p>You can simply add the <code>contains=<...></code> option to both the <code>PandocEmphasis</code> and <code... | 2016/11/06 | [
"https://vi.stackexchange.com/questions/10193",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9855/"
] | I've written regexes for markdown for emphasis and bold as follows:
```
syntax match PandocEmphasisMarker "\v(^|\s+)\zs_[^\n\t_ ]+([^_\n]|(\S_\S)|(\s_\S)|(\s+_\s+))+[^\n\t_ ]+_\ze($|\s+)" contains=PandocEmphasis
syntax match PandocEmphasis "\v\zs[^\n\t_ ]+([^_\n]|(\S_\S)|(\s_\S)|(\s+_\s+))+[^\n\t_ ]+\ze" contained
sy... | If you have known start and end delimiters, you should use regions (`:h :syn-region`):
```
syntax region Emphasis start="\\\@<!\z(_\)" skip="\%(\s\|\\\)\@<=\z1\|\z1\k" end="\\\@<!\z1" keepend contains=Strong,Strike
syntax region Strong start="\\\@<!\z(\*\)" skip="\%(\s\|\\\)\@<=\z1\|\z1\k" end="\\\@<!\z1" keepend cont... |
10,194 | <p>I have these lines in my .vimrc to help with indentation:</p>
<pre><code>autocmd BufReadPost * set noexpandtab | retab! 4
autocmd BufWritePre * set expandtab | retab! 4
autocmd BufWritePost * set noexpandtab | retab! 4
</code></pre>
<p>However, they create a lot of noise in the undo history. Since they essentially... | [
{
"answer_id": 10326,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "<p>Using <code>undojoin</code> actually works pretty well:</p>\n\n<pre><code>autocmd BufReadPost * undojoin | set noexpandta... | 2016/11/06 | [
"https://vi.stackexchange.com/questions/10194",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I have these lines in my .vimrc to help with indentation:
```
autocmd BufReadPost * set noexpandtab | retab! 4
autocmd BufWritePre * set expandtab | retab! 4
autocmd BufWritePost * set noexpandtab | retab! 4
```
However, they create a lot of noise in the undo history. Since they essentially do nothing from the user'... | Using `undojoin` actually works pretty well:
```
autocmd BufReadPost * undojoin | set noexpandtab | retab! 4
autocmd BufWritePre * undojoin | set expandtab | retab! 4
autocmd BufWritePost * undojoin | set noexpandtab | retab! 4
```
However, if you execute `:w` right after undoing an action, you'll get an error:
... |
10,195 | <p>Sometimes I see examples of vimscript code, which uses <code>/</code> instead of <code>"</code> to delimit strings.</p>
<p>Are there any side effects to this, or is it always possible to do that? And what is the advantage of using slashes rather than double quotes?</p>
<p>One example is here: <a href="http://vimhe... | [
{
"answer_id": 10196,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 2,
"selected": false,
"text": "<p>I don't think there are side effects. Sometimes it can be useful because you don't need to escape same sign that would... | 2016/11/06 | [
"https://vi.stackexchange.com/questions/10195",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9855/"
] | Sometimes I see examples of vimscript code, which uses `/` instead of `"` to delimit strings.
Are there any side effects to this, or is it always possible to do that? And what is the advantage of using slashes rather than double quotes?
One example is here: <http://vimhelp.appspot.com/syntax.txt.html#E849> (scroll up... | The examples you are referring to are not examples of strings, but of patterns. A pattern may be delimited by any character (except alphanumeric characters), although the most usual one is `/`. This does not seem to be very well documented, but I found it described under `:h E146`, which reads as follows:
>
> Instead... |
10,206 | <p>What is the best way to bind key, to go "past the last delimiter. I want to bind, for example <code><leader>,</code> to behave like this:</p>
<ul>
<li><code>"foo bar| baz"</code> -> key press -> <code>"foo bar baz",|</code></li>
<li><code>(arg1, arg2, |arg3)</code> -> key press -> <code>(arg1, arg2, arg3),|</... | [
{
"answer_id": 10207,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p><strong>I)</strong> Don't create an insert mode mapping:</p>\n\n<p>Insert mode is made to insert characters, when you ne... | 2016/11/07 | [
"https://vi.stackexchange.com/questions/10206",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10018/"
] | What is the best way to bind key, to go "past the last delimiter. I want to bind, for example `<leader>,` to behave like this:
* `"foo bar| baz"` -> key press -> `"foo bar baz",|`
* `(arg1, arg2, |arg3)` -> key press -> `(arg1, arg2, arg3),|`
And same for other delimiter i choose. Is there any plugin for this?
For ... | This was a tough one as:
* I couldn't get `getpos('``<')` to work
* `searchpair*()` don't work when the opening and the closing signs are not identical. Here, two cases:
+ with strings, `va'` and `va"` can be used
+ with other possible pairs like `_` and `*` in markdown, `*` and `|` in vim help files, we have to use... |
10,209 | <p>I use vim for bash scripting, and sometimes I write a one-time script. Usually, I don't want to create a new file, make it executable, execute it and then remove it.</p>
<p>For instance I open vim and type this:</p>
<pre><code>#!/bin/bash
ll | while read line
do
echo $line
done
</code></pre>
<p>I did not sav... | [
{
"answer_id": 10211,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 7,
"selected": true,
"text": "<p>I wrote a pretty extensive answer about this <a href=\"https://stackoverflow.com/a/40290101/3524982\">over on stack-o... | 2016/11/07 | [
"https://vi.stackexchange.com/questions/10209",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | I use vim for bash scripting, and sometimes I write a one-time script. Usually, I don't want to create a new file, make it executable, execute it and then remove it.
For instance I open vim and type this:
```
#!/bin/bash
ll | while read line
do
echo $line
done
```
I did not save this file, I just use vim to si... | I wrote a pretty extensive answer about this [over on stack-overflow](https://stackoverflow.com/a/40290101/3524982). The basic idea is that since the write command is about *writing* not *saving*, you can write the text in your buffer into an external program, such as python or bash. In your case, you would want to do ... |
10,228 | <p>Working on a more lightweight vim-endwise replacement (endwise breaks <code>imap <expr> <CR></code> mappings).</p>
<p>In the following text:</p>
<pre><code>def name<-cursor here
</code></pre>
<p>it adds a newline and another line with an <code>end</code>:</p>
<pre><code>def name
<-cursor here... | [
{
"answer_id": 10229,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": true,
"text": "<p>IIRC, it's related to the <em>bar</em> character in command lines. You need to escape the bar twice, e.g.:</p>\n\n<pr... | 2016/11/09 | [
"https://vi.stackexchange.com/questions/10228",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8699/"
] | Working on a more lightweight vim-endwise replacement (endwise breaks `imap <expr> <CR>` mappings).
In the following text:
```
def name<-cursor here
```
it adds a newline and another line with an `end`:
```
def name
<-cursor here
end
```
This mapping does the job:
```
autocmd FileType ruby inoremap <buffer> <... | IIRC, it's related to the *bar* character in command lines. You need to escape the bar twice, e.g.:
```
" ftplugin/ruby/myshortcuts.vim
inoremap <buffer> <expr> <CR> match(getline('.'), 'if\\|def\\|case\\|do') >= 0 ? '<CR><CR>end<Esc>-cc' : '<CR>
```
BTW, you should make sure this is exactly `def` (and not `define`... |
10,239 | <p>When I set makeprg using:</p>
<pre><code>set makeprg=gcc\ -Wall\ -g\ %\ -o\ %
</code></pre>
<p>and then invoke :make Vim does not pass proper filenames, because this command is translated as:</p>
<pre><code>gcc -Wall -g file.c -o file.c
</code></pre>
<p>and executed. The compiler is then complaining that input a... | [
{
"answer_id": 10240,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": false,
"text": "<p>You can modify what is being expanded using so called filename modifiers. See the help at <code>:h filename-modi... | 2016/11/11 | [
"https://vi.stackexchange.com/questions/10239",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7370/"
] | When I set makeprg using:
```
set makeprg=gcc\ -Wall\ -g\ %\ -o\ %
```
and then invoke :make Vim does not pass proper filenames, because this command is translated as:
```
gcc -Wall -g file.c -o file.c
```
and executed. The compiler is then complaining that input and output files are the same, which is in fact da... | Unless you're using a non-properly configured version of gnumake (Solaris OS, or mingw distribution of gcc under windows), you don't need to modify `&makeprg`. Its default value is already perfect for GNU compilation tools.
All you need to do is to set `$CFLAGS` with `:let $CFLAGS="-g -Wall"`, and compile with `:make ... |
10,242 | <p>I'm trying to upgrade my Vim installation to version 8.0, but it doesn't support both Python and Python 3 as the below image.</p>
<p>(PS: Because of this problem, I cannot use the YCM (YouCompleteMe) plugin now.)</p>
<ol>
<li><p>I installed Vim 8.0 as in the following commands.</p></li>
<li><p>I'm using Ubuntu&nb... | [
{
"answer_id": 10243,
"author": "skywind3000",
"author_id": 9681,
"author_profile": "https://vi.stackexchange.com/users/9681",
"pm_score": 3,
"selected": false,
"text": "<p>you should use</p>\n\n<p><code>sudo apt-get install vim-nox\n</code></p>\n\n<p>instead, to get a \"huge-version\".<... | 2016/11/11 | [
"https://vi.stackexchange.com/questions/10242",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10053/"
] | I'm trying to upgrade my Vim installation to version 8.0, but it doesn't support both Python and Python 3 as the below image.
(PS: Because of this problem, I cannot use the YCM (YouCompleteMe) plugin now.)
1. I installed Vim 8.0 as in the following commands.
2. I'm using Ubuntu 16.04 (Xenial Xerus).
How can I handle... | The [pi-rho/dev PPA](https://launchpad.net/~pi-rho/+archive/ubuntu/dev) now supports Vim 8, and like it always has, includes support for Python/Python3:
```
$ vim --version | grep python
+cryptv +linebreak +python/dyn +vreplace
+cscope +lispindent +python3/dyn +wildignore
$ apt-ca... |
10,256 | <p>I mostly use Vim (or MacVim) to edit text, but occasionally (such as in writing this question), I use the Mac OS text editing keybindings built in to all text entry fields accessed through a Mac.</p>
<p>I find these binding extremely intuitive for <em>writing</em> text (whereas Vim bindings are better focused on <e... | [
{
"answer_id": 10258,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 2,
"selected": false,
"text": "<h2>MacVim GUI</h2>\n\n<p>Opt-Left and Opt-Right already do what you want by default, as well as Alt-Backspace.</p>\n\n<p>Cmd-... | 2016/11/12 | [
"https://vi.stackexchange.com/questions/10256",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4676/"
] | I mostly use Vim (or MacVim) to edit text, but occasionally (such as in writing this question), I use the Mac OS text editing keybindings built in to all text entry fields accessed through a Mac.
I find these binding extremely intuitive for *writing* text (whereas Vim bindings are better focused on *editing* text.)
-... | MacVim GUI
----------
Opt-Left and Opt-Right already do what you want by default, as well as Alt-Backspace.
Cmd-Left and Cmd-Right are mapped to `<Home>` and `<End>` by default. You can remap them to do whatever you want:
```
inoremap <D-Left> <C-o>g0
inoremap <D-Right> <C-o>g$
nnoremap <D-Left> g0
nnoremap <D-Right... |
10,262 | <p>I'm trying to bind <code><C-S-S></code> (Control + Shift + S) to send the selected test to a system command, and to then replace the selected text with the output of the system call.</p>
<p>This is what I have tried:</p>
<pre><code>vnoremap <C-S-S> :'<,'>!echo 'Output of system call'<CR>
</... | [
{
"answer_id": 10264,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 0,
"selected": false,
"text": "<ol>\n<li><p>You can't use multiple modifiers in CLI Vim mappings. Find another mapping.</p></li>\n<li><p>See <code>:help hit-... | 2016/11/12 | [
"https://vi.stackexchange.com/questions/10262",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6499/"
] | I'm trying to bind `<C-S-S>` (Control + Shift + S) to send the selected test to a system command, and to then replace the selected text with the output of the system call.
This is what I have tried:
```
vnoremap <C-S-S> :'<,'>!echo 'Output of system call'<CR>
```
However, it only seems to work in gvim (and with an ... | There are a couple things I notice.
1. You can't map to `<C-S-S>`. I wrote a more extensive answer on that [here](https://vi.stackexchange.com/questions/8856/mapping-ctrl-with-equal-sign), but the basic problem is that `<C-S-S>` does not produce an ASCII value different then `<C-s>` so vim is unable to distinguish the... |
10,267 | <p>Is it possible to delete the current visual block selection and all other occurences from the current buffer?</p>
| [
{
"answer_id": 10268,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 0,
"selected": false,
"text": "<p>You could do something like</p>\n\n<p><code>visual</code> around the block you want to delete, hit <code>y</code> to yan... | 2016/11/12 | [
"https://vi.stackexchange.com/questions/10267",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6878/"
] | Is it possible to delete the current visual block selection and all other occurences from the current buffer? | It's probably not completely reliable, but you could try this:
```
xno <silent> mbc :<C-U>call <SID>move_blocks(1)<CR>
xno <silent> mbd :<C-U>call <SID>move_blocks(0)<CR>
fu! s:move_blocks(clean_them_only) abort
let view = winsaveview()
let block = s:get_its_text()
call cursor(1,1)
while s:you_find_... |
10,287 | <p>I'd like to test the range pattern, same as Vim highlights the text while searching (e.g. <code>:/</code>), but for the range command instead.</p>
<p>So in other words, instead of executing:</p>
<pre><code>:/<head/,/\/head>/d
</code></pre>
<p>I'd like to test only <code>/<head/,/\/head>/</code> range ... | [
{
"answer_id": 10288,
"author": "kenorb",
"author_id": 467,
"author_profile": "https://vi.stackexchange.com/users/467",
"pm_score": 1,
"selected": false,
"text": "<p>Currently I only know the following way by using multi-line match (<code>\\_.\\{-}</code>), e.g.:</p>\n\n<pre><code>/<h... | 2016/11/14 | [
"https://vi.stackexchange.com/questions/10287",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I'd like to test the range pattern, same as Vim highlights the text while searching (e.g. `:/`), but for the range command instead.
So in other words, instead of executing:
```
:/<head/,/\/head>/d
```
I'd like to test only `/<head/,/\/head>/` range pattern in form of highlight to check whether the pattern is correc... | ### A
If you just want to quickly confirm the validity of the range (and it isn't too long), you can use the built-in `:print` or `:number`:
```
:/<head/,/\/head>/print
```
### B
Another idea would be (mis-)using the visual selection. The following custom command creates a linewise selection of the passed range:
... |
10,292 | <p>I'm trying to modify test runner plugin to do the following:</p>
<ol>
<li>When running test show a window with them (that part is already covered by the plugin)</li>
<li>After all tests are done if there is no errors hide window.</li>
<li>If there were errors leave the window open.</li>
</ol>
<p>I've written a she... | [
{
"answer_id": 10311,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": false,
"text": "<p>From <code>vim/src/eval.c</code>:</p>\n<pre><code>static void eval_job_process_exit_cb(Process *proc, int status, v... | 2016/11/15 | [
"https://vi.stackexchange.com/questions/10292",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6634/"
] | I'm trying to modify test runner plugin to do the following:
1. When running test show a window with them (that part is already covered by the plugin)
2. After all tests are done if there is no errors hide window.
3. If there were errors leave the window open.
I've written a shell script that exits if the exit code o... | From `vim/src/eval.c`:
```
static void eval_job_process_exit_cb(Process *proc, int status, void *d) {
[..]
if (data->term && !data->exited) {
data->exited = true;
char msg[sizeof("\r\n[Process exited ]") + NUMBUFLEN];
snprintf(msg, sizeof msg, "\r\n[Process exited %d]", proc->status);
t... |
10,296 | <p>I finally decided to ditch the arrow keys for navigation in favor of <code>hjkl</code>.
I used the <code>Vim hardmode</code> plugin to disable the arrow keys.</p>
<p>I got used to navigation pretty fast, but it turns out that navigation in insert mode suddenly is impossible.</p>
<p>Is there any solution for this? (e... | [
{
"answer_id": 10297,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 7,
"selected": true,
"text": "<p>There are many options you have. One option, and IMO the sanest and easiest is to just stop disabling the arrow keys.... | 2016/11/15 | [
"https://vi.stackexchange.com/questions/10296",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/496/"
] | I finally decided to ditch the arrow keys for navigation in favor of `hjkl`.
I used the `Vim hardmode` plugin to disable the arrow keys.
I got used to navigation pretty fast, but it turns out that navigation in insert mode suddenly is impossible.
Is there any solution for this? (exiting insert mode is not a solution)... | There are many options you have. One option, and IMO the sanest and easiest is to just stop disabling the arrow keys. I understand why many hardcore vimmers say things like
>
> You should never ever use the arrow keys again! Every time you use the arrow keys, you waste 3 minutes of time, a puppy dies and somebody swi... |
10,323 | <p>Sometimes I browse around the directory of the current buffer by using <code>:Ex</code>. On one of my development machines, this results in a <code>.swp</code> file being created in every directory I visit.</p>
<p>I've checked the directory variable other machines where this doesn't seem to be the issue, and they m... | [
{
"answer_id": 10328,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": true,
"text": "<p>This is probably a netrw bug. You might be able to work around by creating a file <code>~/.vim/after/ftplugin/net... | 2016/11/17 | [
"https://vi.stackexchange.com/questions/10323",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8327/"
] | Sometimes I browse around the directory of the current buffer by using `:Ex`. On one of my development machines, this results in a `.swp` file being created in every directory I visit.
I've checked the directory variable other machines where this doesn't seem to be the issue, and they match (`directory=.,~/tmp,/var/tm... | This is probably a netrw bug. You might be able to work around by creating a file `~/.vim/after/ftplugin/netrw.vim` (create non-existent directories) and put in there `:set noswapfile` |
10,329 | <p>I'm testing NeoVim and would like to put in my vimrc universal mapping for either vim and nvim.</p>
<p>I've sketch sth like below so far, but it doesn't work and it's <em>very</em> rough.</p>
<pre><code>function! Meta(key) " define if using alt(it works in neovim) or leader key. Used below for mapping only.
" ... | [
{
"answer_id": 10330,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p>The <code>:map</code> command takes <code>:help key-notation</code>, but not variables. Vimscript is evaluated exactly... | 2016/11/18 | [
"https://vi.stackexchange.com/questions/10329",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8444/"
] | I'm testing NeoVim and would like to put in my vimrc universal mapping for either vim and nvim.
I've sketch sth like below so far, but it doesn't work and it's *very* rough.
```
function! Meta(key) " define if using alt(it works in neovim) or leader key. Used below for mapping only.
" for neovim testing and chang... | The `:map` command takes `:help key-notation`, but not variables. Vimscript is evaluated exactly like the Ex commands typed in the `:` command-line. There were no variables in `ex`, so there's no way to specify them. When typing a command interactively, you'd probably use `<C-R>=` to insert variable contents:
```
:sle... |
10,338 | <p>In Vim, how to change the vimrc so that I could keep files' \t characters while I don't want \t characters appear in the newline generated by auto-indentation and tab-button I pressed.</p>
<p>Is this achievable?</p>
<p>Here is what I have appended to the tail of _vimrc:</p>
<pre><code>set nu
set noexpandtab " ... | [
{
"answer_id": 10341,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 2,
"selected": false,
"text": "<p>Vim doesn't translate tabs (<code>\\t</code> characters) to spaces unless you edit the line containing tabs in certain... | 2016/11/19 | [
"https://vi.stackexchange.com/questions/10338",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10189/"
] | In Vim, how to change the vimrc so that I could keep files' \t characters while I don't want \t characters appear in the newline generated by auto-indentation and tab-button I pressed.
Is this achievable?
Here is what I have appended to the tail of \_vimrc:
```
set nu
set noexpandtab " I want to read \t, not to tra... | Replace
```
set noexpandtab
```
to
```
set expandtab
```
.
This will make both auto-indentation and Tabs you manually typed to only spaces.
Now you can type a line containing mixture of both spaces and Tabs with length greater than which tabstop is set,
without worrying some spaces become \t. And actually,
> ... |
10,357 | <p>In vim I can use for instance <kbd>1</kbd><kbd>0</kbd><kbd>j</kbd> to go 10 lines down. And I can use <code>.</code> to repeat the last deletion.</p>
<p>Now, in bash script I have many commented lines like this:</p>
<pre><code># ...
# ...
# ...
# ...
# ...
# ...
# ...
# ...
# ...
etc...
</code></pre>
<p>Say, ther... | [
{
"answer_id": 10358,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": false,
"text": "<p>I do approve @mMontu comment suggesting to use a comment plugin (<a href=\"https://github.com/tpope/vim-commentary/\" re... | 2016/11/21 | [
"https://vi.stackexchange.com/questions/10357",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | In vim I can use for instance `1``0``j` to go 10 lines down. And I can use `.` to repeat the last deletion.
Now, in bash script I have many commented lines like this:
```
# ...
# ...
# ...
# ...
# ...
# ...
# ...
# ...
# ...
etc...
```
Say, there are 52 such lines. Is there a way to combine moving `52j` and repeati... | I do approve @mMontu comment suggesting to use a comment plugin ([vim-commentary](https://github.com/tpope/vim-commentary/) is an option but [NERDCommenter](https://github.com/scrooloose/nerdcommenter) has my preference over vim-commentary).
But you could do it in other ways:
* First if all your `#` are aligned on th... |
10,371 | <p>I have a problem with Vim Autocompletion behavior for buffer names. </p>
<p><strong>Target Soft/OS</strong></p>
<p>I'm using gVim without plugins on Windows 10</p>
<p><strong>What I would like to do</strong></p>
<p>Assuming we have a file tree like :</p>
<pre><code>+---- a
+---- b
| +---- c
| +---- d
|... | [
{
"answer_id": 10373,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 2,
"selected": false,
"text": "<p>I believe that <code>:b</code> is only going to select from the buffers you have open. It sounds to me like you want ... | 2016/11/22 | [
"https://vi.stackexchange.com/questions/10371",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10222/"
] | I have a problem with Vim Autocompletion behavior for buffer names.
**Target Soft/OS**
I'm using gVim without plugins on Windows 10
**What I would like to do**
Assuming we have a file tree like :
```
+---- a
+---- b
| +---- c
| +---- d
| +---- e0
| +---- e
| +----f
| +----g
`... | This is a bug from vim when using backslash on windows, it can be fixed by using `set shellslash`
I've reported the bug, but setting shellslash is easy and sufficient enough for everyday use. |
10,374 | <p>I would like to compare</p>
<ul>
<li><code>File1-v1.txt</code> with <code>File1-v2.txt</code></li>
</ul>
<p>and</p>
<ul>
<li><code>File2-v1.txt</code> with <code>File2-v2.txt</code></li>
</ul>
<p>at the same time. I tried to create the following layout:</p>
<pre><code>+------------------+------------------+
| ... | [
{
"answer_id": 10373,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 2,
"selected": false,
"text": "<p>I believe that <code>:b</code> is only going to select from the buffers you have open. It sounds to me like you want ... | 2016/11/22 | [
"https://vi.stackexchange.com/questions/10374",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3230/"
] | I would like to compare
* `File1-v1.txt` with `File1-v2.txt`
and
* `File2-v1.txt` with `File2-v2.txt`
at the same time. I tried to create the following layout:
```
+------------------+------------------+
| | |
| File1-v1.txt <=> File1-v2.txt | // scroll synchronized diff
| ... | This is a bug from vim when using backslash on windows, it can be fixed by using `set shellslash`
I've reported the bug, but setting shellslash is easy and sufficient enough for everyday use. |
10,394 | <p>I have a following line in one script:</p>
<pre><code>cp "$uploaddir"/"$file" "$cvsdir"/"$device"
</code></pre>
<p>I would like to search if this exact line is present elsewhere in the script. Usually I would do <kbd>y</kbd><kbd>y</kbd> and then <kbd>/</kbd><kbd>Ctrl</kbd><kbd>r</kbd><kbd>0</kbd>. However, this ti... | [
{
"answer_id": 10395,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 4,
"selected": true,
"text": "<p>Use backward search <code>:h ?</code>. This way you type <code>?</code> instead of <code>/</code> to start search, but t... | 2016/11/25 | [
"https://vi.stackexchange.com/questions/10394",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8626/"
] | I have a following line in one script:
```
cp "$uploaddir"/"$file" "$cvsdir"/"$device"
```
I would like to search if this exact line is present elsewhere in the script. Usually I would do `y``y` and then `/``Ctrl``r``0`. However, this time the line contains forward slashes. I also tried to specify "very nomagic"(`\V... | Use backward search `:h ?`. This way you type `?` instead of `/` to start search, but this also allows to use `/` in search pattern. |
10,396 | <p>Within a function, is there a way to determine if vim is in insert mode (or was in insert mode prior to calling the function)?</p>
| [
{
"answer_id": 10397,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p><em>Something</em> must have invoked your function. Setting the (new in Vim 8.0) asyncronous timers aside, this will b... | 2016/11/25 | [
"https://vi.stackexchange.com/questions/10396",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | Within a function, is there a way to determine if vim is in insert mode (or was in insert mode prior to calling the function)? | *Something* must have invoked your function. Setting the (new in Vim 8.0) asyncronous timers aside, this will be either
* a custom command, which cannot be invoked from insert mode, only command-line mode
* a mapping
* an `:autocmd` event
For the latter, you can split into two separate `:autocmd`s, and pass an `isIns... |
10,402 | <p>I want to be editing a file like this:</p>
<pre><code>---------------
| |
| |
| DOC |
| |
| |
| |
---------------
</code></pre>
<p>And then press <kbd>F5</kbd> and open NERDTree and Tagbar like this:</p>
<pre><code>---------------
| | |... | [
{
"answer_id": 10397,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p><em>Something</em> must have invoked your function. Setting the (new in Vim 8.0) asyncronous timers aside, this will b... | 2016/11/26 | [
"https://vi.stackexchange.com/questions/10402",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10260/"
] | I want to be editing a file like this:
```
---------------
| |
| |
| DOC |
| |
| |
| |
---------------
```
And then press `F5` and open NERDTree and Tagbar like this:
```
---------------
| | |
|NERD| DOC |
|TREE| |
|----| ... | *Something* must have invoked your function. Setting the (new in Vim 8.0) asyncronous timers aside, this will be either
* a custom command, which cannot be invoked from insert mode, only command-line mode
* a mapping
* an `:autocmd` event
For the latter, you can split into two separate `:autocmd`s, and pass an `isIns... |
10,407 | <p>I would like Vim to stop highlighting matches when entering Insert mode. And not to highlight them again until a new search is performed.</p>
<p>A first thought would be to add the following line to my <code>.vimrc</code>.</p>
<pre><code>autocmd InsertEnter * nohlsearch
</code></pre>
<p>But from <code>:help :nohl... | [
{
"answer_id": 10410,
"author": "ryuichiro",
"author_id": 2961,
"author_profile": "https://vi.stackexchange.com/users/2961",
"pm_score": 1,
"selected": false,
"text": "<p>You can try:</p>\n\n<pre><code>autocmd InsertEnter * setlocal nohlsearch\nautocmd InsertLeave * setlocal hlsearch lz\... | 2016/11/26 | [
"https://vi.stackexchange.com/questions/10407",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | I would like Vim to stop highlighting matches when entering Insert mode. And not to highlight them again until a new search is performed.
A first thought would be to add the following line to my `.vimrc`.
```
autocmd InsertEnter * nohlsearch
```
But from `:help :nohlsearch` we know that `nohlsearch` does not work i... | You can use `feedkeys()` to execute `:nohlsearch`. A small challenge is to avoid the recursion, as the `:call` temporarily leaves (and then re-enters) insert mode. I've used a simple boolean flag for that here:
```
let didit = 0
autocmd! InsertEnter * if ! didit | call feedkeys("\<C-\>\<C-o>:nohlsearch|let didit = 1\<... |
10,409 | <p>Executing<code>:3,7y</code> does not change the line which contains the cursor (<code>line('.')</code>). This is what I expected.</p>
<p>However, when I execute <code>:3,7call XYZ()</code>, the current line goes to the third line. I didn't expect this behavior.</p>
<p>Why is that? Can I change the behavior so that... | [
{
"answer_id": 10417,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 1,
"selected": false,
"text": "<p>One way to do this would be to pass current line as function argument. But <code>line('.')</code> is evaluated for firs... | 2016/11/26 | [
"https://vi.stackexchange.com/questions/10409",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | Executing`:3,7y` does not change the line which contains the cursor (`line('.')`). This is what I expected.
However, when I execute `:3,7call XYZ()`, the current line goes to the third line. I didn't expect this behavior.
Why is that? Can I change the behavior so that the current line does not change? | One way to do this would be to pass current line as function argument. But `line('.')` is evaluated for first line of range, thus this needs to be done earlier. My solution to this would be to use user command. Below complete sample code:
```
function XYZ(curline) range
[normal body]
exe "normal " . a:curline . "g... |
10,428 | <p>Under <code>:help [range]</code> it states:</p>
<blockquote>
<p>Some Ex commands accept a line range in front of them. This is noted as
[range]. It consists of one or more line specifiers, separated with ',' or
';'.</p>
</blockquote>
<p>I am wondering if there is actually a command that takes more than two... | [
{
"answer_id": 27483,
"author": "Thorsten Roggendorf",
"author_id": 31592,
"author_profile": "https://vi.stackexchange.com/users/31592",
"pm_score": 3,
"selected": false,
"text": "<p>I would have used a comment instead of an answer, but alas, my reputation is insufficient. So this is <em... | 2016/11/28 | [
"https://vi.stackexchange.com/questions/10428",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | Under `:help [range]` it states:
>
> Some Ex commands accept a line range in front of them. This is noted as
> [range]. It consists of one or more line specifiers, separated with ',' or
> ';'.
>
>
>
I am wondering if there is actually a command that takes more than two line specifiers. I can think of at most tw... | I would have used a comment instead of an answer, but alas, my reputation is insufficient. So this is *not* an answer, sorry.
I would really love to have a solution to this, too. Though in my mind restricting that to vim is hardly a solution. Indeed, a multi-editor solution is absolutely required. The tech I'm looking... |
10,432 | <p>I have found this very useful function to turn on and off relative number lines:</p>
<pre><code>function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
</code></pre>
<p>but it doesn't work, when I launch it</p>
<pre><code>:call NumberToggle()
</code></p... | [
{
"answer_id": 10433,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 3,
"selected": false,
"text": "<p>Why won't you use Vim's builtin feature to toggle that? Just use: <code>set relativenumber!</code> - this will cycle be... | 2016/11/28 | [
"https://vi.stackexchange.com/questions/10432",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6854/"
] | I have found this very useful function to turn on and off relative number lines:
```
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
```
but it doesn't work, when I launch it
```
:call NumberToggle()
```
I see no changes, even when I close and reope... | The intention of the function as described in the blog post is *not* to toggle `relativenumber` but to switch between the `number` and `relativenumber` settings.
In Vim 7.3, the `number` and `relativenumber` settings could not be used at the same time, and I believe setting one automatically unset the other.
However,... |
10,435 | <p>Let's say that I have a code like this (<em><code>|</code> represents the cursor position</em>):</p>
<pre><code>func1(x|, func2(), y);
</code></pre>
<p>I would like to get:</p>
<pre><code>func1(x|);
</code></pre>
<p>Is there a way to <em>delete the code from the position of the cursor to the position preceding ... | [
{
"answer_id": 10436,
"author": "Nathan Wilson",
"author_id": 2674,
"author_profile": "https://vi.stackexchange.com/users/2674",
"pm_score": 2,
"selected": false,
"text": "<p>For this specific case I would <code>dfy</code> </p>\n\n<p>For the general case:</p>\n\n<ul>\n<li><code>dT(</cod... | 2016/11/28 | [
"https://vi.stackexchange.com/questions/10435",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6043/"
] | Let's say that I have a code like this (*`|` represents the cursor position*):
```
func1(x|, func2(), y);
```
I would like to get:
```
func1(x|);
```
Is there a way to *delete the code from the position of the cursor to the position preceding the right end of the current inner block*?
I know that I can go with ... | I would use
```
d])
```
which means delete (`d`) to the next unmatched ')' (`])`).
See [`:help ])`](http://vimhelp.appspot.com/motion.txt.html#%5D%29). |
10,443 | <p>Is it possible to change the back-gound color of the gutter for the function that I am working on? I keep loosing my place, but it would be awesome to highlight a section like below.</p>
<p><a href="https://i.stack.imgur.com/OzMEN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OzMEN.png" alt="e... | [
{
"answer_id": 10444,
"author": "rampion",
"author_id": 361,
"author_profile": "https://vi.stackexchange.com/users/361",
"pm_score": 2,
"selected": false,
"text": "<p>I don't know of a way to highlight the gutter (and the fact that the only highlight groups for that region are <code>Line... | 2016/11/29 | [
"https://vi.stackexchange.com/questions/10443",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3050/"
] | Is it possible to change the back-gound color of the gutter for the function that I am working on? I keep loosing my place, but it would be awesome to highlight a section like below.
[](https://i.stack.imgur.com/OzMEN.png) | One could (ab)use `:help sign`:
```
" define an highlight group
highlight CurrentBlock ctermbg=red ctermfg=red cterm=NONE
" define a sign
sign define currentblock text=>> texthl=CurrentBlock
" place the signs
for range(30, 40)
execute "sign place " . i . " line=" . i . " name=currentblock file=" . expand("%:p")
... |
10,454 | <p>Does anyone know a way to highlight only comments in vim?</p>
<p>Requirements:</p>
<ul>
<li>For any colour scheme.</li>
<li>Without having to clear and re-add only the comment syntax group in each language's ftplugin.</li>
</ul>
<p>I suppose I want something that loops over the syntax groups and removes them if i... | [
{
"answer_id": 10455,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 1,
"selected": false,
"text": "<p>Not sure exactly what you mean by highlight, but a simple approach would be:</p>\n\n<pre><code>hi clear Comment\nhi l... | 2016/11/30 | [
"https://vi.stackexchange.com/questions/10454",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10321/"
] | Does anyone know a way to highlight only comments in vim?
Requirements:
* For any colour scheme.
* Without having to clear and re-add only the comment syntax group in each language's ftplugin.
I suppose I want something that loops over the syntax groups and removes them if it doesn't equal "Comment". Is this possibl... | Something like this perhaps:
```
func! ClearSyntax()
let syn=split(execute('syn list'), "\n")[1:]
call filter(syn, {idx, val -> match(val, '^\w') > -1})
call map(syn, {idx, val -> split(val)[0]})
for item in syn
if match(item, '\c\mcomment') == -1
try
exe 'syn clear'... |
10,460 | <p>Consider:</p>
<pre><code>apple
pear
</code></pre>
<p>Put your cursor on the first line and type <code>Yp</code>, producing:</p>
<pre><code>apple
apple
pear
</code></pre>
<p>Put your cursor on the <code>pear</code> line and type <code>.</code> to repeat the last command. This repeats only the <code>p</code> (rat... | [
{
"answer_id": 10461,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 2,
"selected": false,
"text": "<p>In <code>Yp</code>, the only \"change\" to repeat is <code>p</code>. The only way I know to alter the behavior of <code>.</... | 2016/12/01 | [
"https://vi.stackexchange.com/questions/10460",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5373/"
] | Consider:
```
apple
pear
```
Put your cursor on the first line and type `Yp`, producing:
```
apple
apple
pear
```
Put your cursor on the `pear` line and type `.` to repeat the last command. This repeats only the `p` (rather than the combination `Yp`), producing:
```
apple
apple
pear
apple
```
I would like a wa... | In `Yp`, the only "change" to repeat is `p`. The only way I know to alter the behavior of `.` in normal mode is to add `y` to the `cpoptions` option:
```
set cpoptions+=y
```
which lets you repeat the last yank as well as the last change.
But that doesn't change anything to your problem because `Yp` is still two co... |
10,471 | <p>I use <a href="https://github.com/francoiscabrol/ranger.vim" rel="nofollow noreferrer">the ranger plugin</a> wich I can trigger with a shortcut. But when I open a directory I would like to use the plugin instead of netrw.
So I have found that the filetype of directories is <code>netrw</code>, using <code>set filetyp... | [
{
"answer_id": 10473,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 1,
"selected": false,
"text": "<ul>\n<li>Vim's default file explorer, the one you get when you do <code>$ vim .</code>, is Netrw. See <code>:help netrw</code... | 2016/12/01 | [
"https://vi.stackexchange.com/questions/10471",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6078/"
] | I use [the ranger plugin](https://github.com/francoiscabrol/ranger.vim) wich I can trigger with a shortcut. But when I open a directory I would like to use the plugin instead of netrw.
So I have found that the filetype of directories is `netrw`, using `set filetype`on a directory, and decided to put an autocommand in m... | I had a look at [how](https://github.com/justinmk/vim-dirvish/blob/4ae4303748221543aaa37030f209da11de817270/plugin/dirvish.vim#L8-L20) `Dirvish` did it, and tested this:
```
augroup ranger
au!
au VimEnter * sil! au! FileExplorer *
au BufEnter * if s:isdir(expand('%')) | bd | exe 'Ranger' | endif
augroup EN... |
10,477 | <p>How can I iterate over the current open buffers and say, load the buffer numbers into an array in vimscript?</p>
<p>I know there exists arrays or similar data structures in vimscript.<br>
I know that every buffer gets assigned a unique number.<br>
My goal is to put each of those numbers into an array of the same le... | [
{
"answer_id": 10478,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 5,
"selected": true,
"text": "<p>You can iterate over buffers if you use <code>:bnext</code> and all. I highly advice against this method. It'll trigg... | 2016/12/02 | [
"https://vi.stackexchange.com/questions/10477",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10357/"
] | How can I iterate over the current open buffers and say, load the buffer numbers into an array in vimscript?
I know there exists arrays or similar data structures in vimscript.
I know that every buffer gets assigned a unique number.
My goal is to put each of those numbers into an array of the same length as the ... | You can iterate over buffers if you use `:bnext` and all. I highly advice against this method. It'll trigger autocommands, and you'll have to remember where you were. In other words, it can be damn slow, and with plenty side effects. Stay away if you can.
Until now my preferred approach was to use `filter()` on `range... |
10,490 | <p>Sometimes I need to press <kbd>TAB</kbd>, but instead of getting actual the tab key, a suggestion pops up and <kbd>TAB</kbd> cycles through the suggestions.</p>
<p>How can I insert <kbd>TAB</kbd> without invoking the auto-completion ?</p>
<p>The problem occurrs both in YouCompleteMe and SuperTab plugins.</p>
| [
{
"answer_id": 10491,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 2,
"selected": false,
"text": "<p>You can always bypass the effects of a keypress by preceding it with a <kbd>ctrl-v</kbd>. For example, if you'd like... | 2016/12/03 | [
"https://vi.stackexchange.com/questions/10490",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/496/"
] | Sometimes I need to press `TAB`, but instead of getting actual the tab key, a suggestion pops up and `TAB` cycles through the suggestions.
How can I insert `TAB` without invoking the auto-completion ?
The problem occurrs both in YouCompleteMe and SuperTab plugins. | I would just use a different key mapping for completion instead of hijacking the Tab key. Having one key to preform two actions and "guess" which one it should do is just a misguided approach IMHO.
For SuperTab see `:help supertab-forwardbackward`:
```
g:SuperTabMappingForward (default value: '<tab>')
g:SuperTabMapp... |
10,518 | <p>I just discovered you can't search and replace within a block selection without adding the ugly and unintuitive <code>\%V</code> to the search term. The default behaviour seems to be to ignore the fact that you've done a columnular highlight and operate on whatever lines the highlight touches.</p>
<p>Would it not h... | [
{
"answer_id": 10491,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 2,
"selected": false,
"text": "<p>You can always bypass the effects of a keypress by preceding it with a <kbd>ctrl-v</kbd>. For example, if you'd like... | 2016/12/06 | [
"https://vi.stackexchange.com/questions/10518",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I just discovered you can't search and replace within a block selection without adding the ugly and unintuitive `\%V` to the search term. The default behaviour seems to be to ignore the fact that you've done a columnular highlight and operate on whatever lines the highlight touches.
Would it not have made more sense t... | I would just use a different key mapping for completion instead of hijacking the Tab key. Having one key to preform two actions and "guess" which one it should do is just a misguided approach IMHO.
For SuperTab see `:help supertab-forwardbackward`:
```
g:SuperTabMappingForward (default value: '<tab>')
g:SuperTabMapp... |
10,523 | <p>I want to do some edits on each match during a global substitution operation.</p>
<p>I found this answer </p>
<pre><code>:% s/re\(ge\)xp/\= myfunction(submatch(1))/gc.
</code></pre>
<p>But I don't have a function, just some keystrokes. </p>
<p>So how can I wrap a macro into myfunction to call during substitute?... | [
{
"answer_id": 10524,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": false,
"text": "<p>I would suggest the following:</p>\n\n<p>Record your keystrokes as a macro (here in the register <code>q</code>) and call... | 2016/12/06 | [
"https://vi.stackexchange.com/questions/10523",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7817/"
] | I want to do some edits on each match during a global substitution operation.
I found this answer
```
:% s/re\(ge\)xp/\= myfunction(submatch(1))/gc.
```
But I don't have a function, just some keystrokes.
So how can I wrap a macro into myfunction to call during substitute?
Sample use: rot13(vselection) is g?, b... | I would suggest the following:
Record your keystrokes as a macro (here in the register `q`) and call:
```
:g/regex/normal @q
```
This will apply the macro on each found regex in your document.
Example of use:
Content of your file
```
function A(){}
function B(){}
function C(){}
```
Type:
```
/function<CR> ... |
10,534 | <p>I'm using Vim as a 3-way merge too with Git and sometimes need to take changes from both local and remote branches. <code>kdiff3</code> can do this with a couple of key presses, is there a way to do this in Vim?</p>
| [
{
"answer_id": 10535,
"author": "mMontu",
"author_id": 1405,
"author_profile": "https://vi.stackexchange.com/users/1405",
"pm_score": 4,
"selected": true,
"text": "<p>Not exactly what you asked, but may find this useful: <a href=\"http://vimawesome.com/plugin/splice\" rel=\"noreferrer\">... | 2016/12/07 | [
"https://vi.stackexchange.com/questions/10534",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5528/"
] | I'm using Vim as a 3-way merge too with Git and sometimes need to take changes from both local and remote branches. `kdiff3` can do this with a couple of key presses, is there a way to do this in Vim? | Not exactly what you asked, but may find this useful: [Splice plugin: a Vim plugin for resolving conflicts during three-way merge](http://vimawesome.com/plugin/splice).
It has a nice [demo screencast on Vimeo](https://vimeo.com/25764692).
If you are going to stick with the default vimdiff you could create a function ... |
10,549 | <p>How can I match the outest bracket and replace it with <code>$$</code> in vim?</p>
<p>For example:</p>
<pre><code>{a+b>c} --> $a+b>c$
{a+{\int_a^bf(x)dx=\set{a+c}}} --> $a+{\int_a^bf(x)dx=\set{a+c}}$
{a+{b+c}+d} and {e+{f}+g} --> $a+{b+c}+d$ and $a+{f}+g$
</code></pre>
<h3>UPDATE</h3>
<p>By @Ing... | [
{
"answer_id": 10550,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 2,
"selected": false,
"text": "<p>As long as there's only one such construct on each line, a simple greedy match (<code>.*</code>) will do. Capture the... | 2016/12/08 | [
"https://vi.stackexchange.com/questions/10549",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10430/"
] | How can I match the outest bracket and replace it with `$$` in vim?
For example:
```
{a+b>c} --> $a+b>c$
{a+{\int_a^bf(x)dx=\set{a+c}}} --> $a+{\int_a^bf(x)dx=\set{a+c}}$
{a+{b+c}+d} and {e+{f}+g} --> $a+{b+c}+d$ and $a+{f}+g$
```
### UPDATE
By @Ingo Karkat's fascinating answer, I can search and replace correctl... | Here's a macro approach that uses the `%` command to jump to matching curly braces. In contrast to my regular expression solution, this one handles multiple constructs in a line:
Preparation: Don't let search wrap around, the recursive macro would not end and eat into inner braces, too:
```
:set nowrapscan
```
Sear... |
10,597 | <p>I have two windows open in <code>tmux</code>(version 2.3). In first <code>tmux</code> window I have a SSH session to <code>server1</code> and in second <code>tmux</code> window I have a SSH session to <code>server2</code>. In <code>server1</code> I opened a shell script with <code>vim script.sh</code> and selected a... | [
{
"answer_id": 10599,
"author": "Martin",
"author_id": 8626,
"author_profile": "https://vi.stackexchange.com/users/8626",
"pm_score": 3,
"selected": true,
"text": "<p>This behavior was caused by <code>colorcolumn</code> option. I started to use <a href=\"http://vimcasts.org/episodes/acce... | 2016/12/12 | [
"https://vi.stackexchange.com/questions/10597",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8626/"
] | I have two windows open in `tmux`(version 2.3). In first `tmux` window I have a SSH session to `server1` and in second `tmux` window I have a SSH session to `server2`. In `server1` I opened a shell script with `vim script.sh` and selected a part of the script with mouse and paste it to `vim` open in `server2` with midd... | This behavior was caused by `colorcolumn` option. I started to use [quoteplus register](http://vimcasts.org/episodes/accessing-the-system-clipboard-from-vim/). |
10,607 | <p>It took me very long time to realize that putting (pasting) something with <code>p</code> or <code>P</code> which visual-block selects with <code>ctrl+v</code> and yanked (copied) with <code>y</code>, preserves the manner before, so that, when the copied text was being in the middle of lines, it will then be copied ... | [
{
"answer_id": 10608,
"author": "user9433424",
"author_id": 6960,
"author_profile": "https://vi.stackexchange.com/users/6960",
"pm_score": 5,
"selected": true,
"text": "<p>When you copy some text, it goes into a register. The text inside a register has a type: <code>characterwise</code>,... | 2016/12/13 | [
"https://vi.stackexchange.com/questions/10607",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10241/"
] | It took me very long time to realize that putting (pasting) something with `p` or `P` which visual-block selects with `ctrl+v` and yanked (copied) with `y`, preserves the manner before, so that, when the copied text was being in the middle of lines, it will then be copied among middle of other text whenever possible.
... | When you copy some text, it goes into a register. The text inside a register has a type: `characterwise`, `linewise` or `blockwise`.
This type determines in which way the text will be put.
In your example, you copied some text from visual block mode. So, the text had the type `blockwise` and was stored in the unnamed... |
10,633 | <p>I think noticing a slow redrawing and slow cursor movement on a fastest PC, is one of the popular frustrations with Vim. Here I am as a yet another instance.</p>
<p>I have a fresh installation of VIM, with the <code>$MYVIMRC</code> at the bottom.</p>
<p>My problem is basically a painful slowdown of cursor movement... | [
{
"answer_id": 10637,
"author": "user9433424",
"author_id": 6960,
"author_profile": "https://vi.stackexchange.com/users/6960",
"pm_score": 3,
"selected": true,
"text": "<p>I have no idea if any of the following will help, but here are a few things you could try.</p>\n\n<p>You have the fo... | 2016/12/16 | [
"https://vi.stackexchange.com/questions/10633",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4583/"
] | I think noticing a slow redrawing and slow cursor movement on a fastest PC, is one of the popular frustrations with Vim. Here I am as a yet another instance.
I have a fresh installation of VIM, with the `$MYVIMRC` at the bottom.
My problem is basically a painful slowdown of cursor movements and screen redraws, which ... | I have no idea if any of the following will help, but here are a few things you could try.
You have the following autocmd:
```
:au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>85v.\+', -1)
```
I can't read your whole `vimrc` file, so maybe you already did it in the missing part, but in case you didn't, you shoul... |
10,635 | <p>I have <kbd>@@</kbd> mapped to <kbd>Space</kbd>. This can be really convenient.</p>
<p>Sometimes I want to combine a macro with another. So maybe I need to record <code>q</code> as <code>@:/jump</code> to run my last regex substitution and move to the next place I probably want to run it. Then <kbd>@q</kbd> and pre... | [
{
"answer_id": 10645,
"author": "Aaron Thoma",
"author_id": 2314,
"author_profile": "https://vi.stackexchange.com/users/2314",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n <p>Is there a way to run @: without setting it to @@ while recording the macro for q?</p>\n</blockquote... | 2016/12/16 | [
"https://vi.stackexchange.com/questions/10635",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8483/"
] | I have `@@` mapped to `Space`. This can be really convenient.
Sometimes I want to combine a macro with another. So maybe I need to record `q` as `@:/jump` to run my last regex substitution and move to the next place I probably want to run it. Then `@q` and press `Space` until I'm happy.
Unfortunately if you run `@q`,... | >
> Is there a way to run @: without setting it to @@ while recording the macro for q?
>
>
>
Yes:
For normal 'character' registers:
```
:call feedkeys(@a)
```
`":` needs special handling:
```
:call feedkeys(':' . @: . "\<CR>")
```
If you use this often, you may want to map it:
```
" for @:
:noremap @- :<C-... |
10,642 | <p>Say I have a comment like this:</p>
<pre><code>//This is a comment
</code></pre>
<p>And I want to make it like this:</p>
<pre><code>//*****************
//This is a comment
//*****************
</code></pre>
<p>Is there an easy way to insert a character repeatedly until even with the next/previous line?</p>
| [
{
"answer_id": 10643,
"author": "Aaron Thoma",
"author_id": 2314,
"author_profile": "https://vi.stackexchange.com/users/2314",
"pm_score": 5,
"selected": true,
"text": "<h1>Short answer</h1>\n\n<p><kbd>\nv\n</kbd> <kbd>\n$\n</kbd> <kbd>\nr\n</kbd><kbd>\n<code>*</code>\n</kbd></p>\n\n<p><... | 2016/12/17 | [
"https://vi.stackexchange.com/questions/10642",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10038/"
] | Say I have a comment like this:
```
//This is a comment
```
And I want to make it like this:
```
//*****************
//This is a comment
//*****************
```
Is there an easy way to insert a character repeatedly until even with the next/previous line? | Short answer
============
`v` `$` `r```*``
[`:help v_r`](http://vimhelp.appspot.com/change.txt.html#v_r)
Longer answer
=============
`y``y`
`p`/`P` Duplicate line to below/above
`2``l` Move to position from where to overwrite (in this case 3rd column ← 2 to the right)
`v` `$` ... |
10,649 | <p>I've got the following mappings and abbreviations in my .vimrc</p>
<pre><code>let mapleader = ","
inoremap <leader>( ()<ESC>i
iabbrev pirnt print
</code></pre>
<p>Now abbreviations won't expand if the following character is an open parenthesis.</p>
<p>If I type:</p>
<pre><code>pirnt,(
</code></pre>
... | [
{
"answer_id": 10643,
"author": "Aaron Thoma",
"author_id": 2314,
"author_profile": "https://vi.stackexchange.com/users/2314",
"pm_score": 5,
"selected": true,
"text": "<h1>Short answer</h1>\n\n<p><kbd>\nv\n</kbd> <kbd>\n$\n</kbd> <kbd>\nr\n</kbd><kbd>\n<code>*</code>\n</kbd></p>\n\n<p><... | 2016/12/18 | [
"https://vi.stackexchange.com/questions/10649",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10545/"
] | I've got the following mappings and abbreviations in my .vimrc
```
let mapleader = ","
inoremap <leader>( ()<ESC>i
iabbrev pirnt print
```
Now abbreviations won't expand if the following character is an open parenthesis.
If I type:
```
pirnt,(
```
it won't correct my spelling mistake, and it leaves me with `pirn... | Short answer
============
`v` `$` `r```*``
[`:help v_r`](http://vimhelp.appspot.com/change.txt.html#v_r)
Longer answer
=============
`y``y`
`p`/`P` Duplicate line to below/above
`2``l` Move to position from where to overwrite (in this case 3rd column ← 2 to the right)
`v` `$` ... |
10,652 | <p><code>Ctrl-]</code> is how one is supposed to move around interactively in Vim on "linkable" text, for instance in the help files. On US layouts, this is simply a two finger combo. Unfortunately the "]" character is a bit awkward to type on Norwegian keyboard layouts (AltGr+9), so I was simply wondering what other f... | [
{
"answer_id": 10655,
"author": "Toothrot",
"author_id": 4505,
"author_profile": "https://vi.stackexchange.com/users/4505",
"pm_score": 2,
"selected": false,
"text": "<p>I use a customized us layout and access ligatures by vim mappings and\nOS option key mappings instead of spending a wh... | 2016/12/18 | [
"https://vi.stackexchange.com/questions/10652",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1087/"
] | `Ctrl-]` is how one is supposed to move around interactively in Vim on "linkable" text, for instance in the help files. On US layouts, this is simply a two finger combo. Unfortunately the "]" character is a bit awkward to type on Norwegian keyboard layouts (AltGr+9), so I was simply wondering what other fellow Vim-user... | I use a customized us layout and access ligatures by vim mappings and
OS option key mappings instead of spending a whole key on them.
For instance, I use `aeo`, which are adjacent on qgmlwb (`jkl`), to get æ.
```
noremap! aeo æ
```
By default you can also use `<c-k>ae`. |
10,664 | <p>I'm trying to setup mappings for <code><C-]></code> that, depending on the buffer's file type, trigger different functions. For example, if I'm in a Javascript buffer, I want <code><C-]></code> to trigger <code>:TernDef</code>. If I'm in a C buffer, I want it to trigger <code>:YcmCompleter GoTo</code>. I... | [
{
"answer_id": 10665,
"author": "Octaviour",
"author_id": 8061,
"author_profile": "https://vi.stackexchange.com/users/8061",
"pm_score": 0,
"selected": false,
"text": "<p>For me that line does work (using commands that my Vim recognizes and including a colon at the start of the command).... | 2016/12/20 | [
"https://vi.stackexchange.com/questions/10664",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4901/"
] | I'm trying to setup mappings for `<C-]>` that, depending on the buffer's file type, trigger different functions. For example, if I'm in a Javascript buffer, I want `<C-]>` to trigger `:TernDef`. If I'm in a C buffer, I want it to trigger `:YcmCompleter GoTo`. I tried `autocmd FileType c nnoremap <C-]> :YcmCompleter GoT... | That autocmd looks fine; however, you should define *buffer-local* mappings (with `<buffer>`); else, editing one type of file will override the other type's (global) mapping:
```
autocmd FileType c nnoremap <buffer> <C-]> :YcmCompleter GoTo<CR>
autocmd FileType javascript nnoremap <buffer> <C-]> :TernDef<CR>
... |
10,675 | <p>My cursor is on the <code>f</code> of the first line. I'd like to move the word so that it aligns with the word below it. I know I could <code>b i spaces</code> until they align. I'd like to avoid getting in insert mode.</p>
<p><a href="https://i.stack.imgur.com/zfT65.png" rel="nofollow noreferrer"><img src="https:... | [
{
"answer_id": 10676,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": true,
"text": "<p>Without entering insert mode (not sure if it's better though):</p>\n\n<p>Example text (cursor on <code>C</code> of the fir... | 2016/12/20 | [
"https://vi.stackexchange.com/questions/10675",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1132/"
] | My cursor is on the `f` of the first line. I'd like to move the word so that it aligns with the word below it. I know I could `b i spaces` until they align. I'd like to avoid getting in insert mode.
[](https://i.stack.imgur.com/zfT65.png) | Without entering insert mode (not sure if it's better though):
Example text (cursor on `C` of the first line):
```
A BBCBB
A BBCBB
```
Type:
```
bjywkP
```
Decomposing:
```
bj go back to the start of the word, one line down (below the first B)
yw yank the next word (being the whitespaces)
k mov... |
10,677 | <p>I've the following content:</p>
<pre><code>group1
item1
item2
item3
group2
item4
item5
group3
item6
</code></pre>
<p>where I'd like to select all items which belong to <code>group2</code> using a search range.</p>
<p>Here is my approach:</p>
<pre><code>:/group2\n\zs/;,/^\ze\S/p
</code></pre>
<p>howe... | [
{
"answer_id": 10679,
"author": "user9433424",
"author_id": 6960,
"author_profile": "https://vi.stackexchange.com/users/6960",
"pm_score": 3,
"selected": true,
"text": "<p>I could be wrong but I think the atom <code>\\ze</code> does take effect, it just doesn't prevent Vim to find a matc... | 2016/12/20 | [
"https://vi.stackexchange.com/questions/10677",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I've the following content:
```
group1
item1
item2
item3
group2
item4
item5
group3
item6
```
where I'd like to select all items which belong to `group2` using a search range.
Here is my approach:
```
:/group2\n\zs/;,/^\ze\S/p
```
however it seems the `\ze` doesn't take any effect, because this is wha... | I could be wrong but I think the atom `\ze` does take effect, it just doesn't prevent Vim to find a match on the `group3` line.
It's an empty match since you write `\ze` just after the anchor `^` which excludes everything afterwards. But even if it's empty, it's still something, the beginning of the line.
Maybe you... |
10,680 | <p>I'd like to replace the entire buffer (file) with the current search range selection:</p>
<pre><code>:/pattern1/;,/pattern2/p
</code></pre>
<p>How this can be achieved?</p>
| [
{
"answer_id": 10691,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>I couldn't find a straightforward solution, but a possible workaround is the following. Consider that you have the follo... | 2016/12/20 | [
"https://vi.stackexchange.com/questions/10680",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I'd like to replace the entire buffer (file) with the current search range selection:
```
:/pattern1/;,/pattern2/p
```
How this can be achieved? | One way to do this is to delete the range you are interested in, delete the remainder of the buffer into the black hole register, then put the text you want to keep into the empty buffer:
```
:/pat1/;/pat2/d | %d_ | put | 1d
```
The final `1d` is to tidy up the empty line at the top, and handily leaves
the cursor at... |
10,685 | <p>I was trying to remap some keys to switch to the next buffer, but something doesn't work, I have these lines on my .vimrc file:</p>
<pre><code>" Cambia tecla lider a <Space>
let mapleader="<Space>"
" Switch to next buffer
nnoremap <Leader>l :bn<CR>
" Switch to previous buffer
nnoremap <... | [
{
"answer_id": 10686,
"author": "Luis Veliz",
"author_id": 10524,
"author_profile": "https://vi.stackexchange.com/users/10524",
"pm_score": 1,
"selected": false,
"text": "<p>The problem was a missing <code>\\</code></p>\n\n<p><code>let mapleader = \"\\<Space>\"</code></p>\n"
},
... | 2016/12/20 | [
"https://vi.stackexchange.com/questions/10685",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10524/"
] | I was trying to remap some keys to switch to the next buffer, but something doesn't work, I have these lines on my .vimrc file:
```
" Cambia tecla lider a <Space>
let mapleader="<Space>"
" Switch to next buffer
nnoremap <Leader>l :bn<CR>
" Switch to previous buffer
nnoremap <Leader>h :bp<CR>
" Split the window
nnor... | Inside `:map` commands, the special `:help key-notation` needs to be used, especially for space, because whitespace separates the arguments of `:map`. The `mapleader` is a built-in variable, and as such requires no escaping. You can simply use
```
:let mapleader = ' '
```
Alternatively, if you'd like to stick to the... |
10,694 | <p>Is it possible to view the help in Vim at a text width greater than 77 characters? Can Vim reflow the help text?</p>
| [
{
"answer_id": 10686,
"author": "Luis Veliz",
"author_id": 10524,
"author_profile": "https://vi.stackexchange.com/users/10524",
"pm_score": 1,
"selected": false,
"text": "<p>The problem was a missing <code>\\</code></p>\n\n<p><code>let mapleader = \"\\<Space>\"</code></p>\n"
},
... | 2016/12/21 | [
"https://vi.stackexchange.com/questions/10694",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2932/"
] | Is it possible to view the help in Vim at a text width greater than 77 characters? Can Vim reflow the help text? | Inside `:map` commands, the special `:help key-notation` needs to be used, especially for space, because whitespace separates the arguments of `:map`. The `mapleader` is a built-in variable, and as such requires no escaping. You can simply use
```
:let mapleader = ' '
```
Alternatively, if you'd like to stick to the... |
10,698 | <p>I'm having problems with latex-suite (some research indicates that many people are). The issue at hand is that they have a nifty python script that gives you a nice outline of your document and reference labels present therein. </p>
<p>I am running VimTouch for Android, which runs vim 7.3. It is compiled without py... | [
{
"answer_id": 10699,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>I am not quite sure, however there is something strange with your <code>system()</code> call. You do:\n<code>\nl... | 2016/12/21 | [
"https://vi.stackexchange.com/questions/10698",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10421/"
] | I'm having problems with latex-suite (some research indicates that many people are). The issue at hand is that they have a nifty python script that gives you a nice outline of your document and reference labels present therein.
I am running VimTouch for Android, which runs vim 7.3. It is compiled without python suppo... | I figured out the problem. Turns out, it WAS because of spaces in filenames. My python setup is that I have a shell script in /system/bin which calls python from where it is in my system. This resulted in escape characters being stripped twice. I changed the python code to run python from its actual location on my box.... |
10,708 | <p>I installed <code>tmux</code> in iTerm 2.(Build 3.0.13) When I execute <code>vim</code> in <code>tmux</code>, syntax highlighting looks like this.</p>
<p><a href="https://i.stack.imgur.com/zlKpP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zlKpP.png" alt="no syntax highlighting"></a></p>
<p>But outsid... | [
{
"answer_id": 11062,
"author": "sohnryang",
"author_id": 10072,
"author_profile": "https://vi.stackexchange.com/users/10072",
"pm_score": 5,
"selected": true,
"text": "<p>Well, I solved the problem by myself.</p>\n\n<p>as @Carpetsmoker♦ commented, I started to suspect that my <code>.vim... | 2016/12/22 | [
"https://vi.stackexchange.com/questions/10708",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10072/"
] | I installed `tmux` in iTerm 2.(Build 3.0.13) When I execute `vim` in `tmux`, syntax highlighting looks like this.
[](https://i.stack.imgur.com/zlKpP.png)
But outside tmux, syntax highlighting looks fine.
[ and started vim with this command inside tmux.
```
vim -u NONE -U NONE -N ~/.vimrc
```
After startin... |
10,711 | <p>After watching Damian Conway's <a href="http://radar.oreilly.com/2013/10/more-instantly-better-vim.html" rel="nofollow noreferrer">talk</a>, I added the following two lines to my <code>.vimrc</code>.</p>
<pre><code>highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
</code></pre>
<p>My... | [
{
"answer_id": 11062,
"author": "sohnryang",
"author_id": 10072,
"author_profile": "https://vi.stackexchange.com/users/10072",
"pm_score": 5,
"selected": true,
"text": "<p>Well, I solved the problem by myself.</p>\n\n<p>as @Carpetsmoker♦ commented, I started to suspect that my <code>.vim... | 2016/12/22 | [
"https://vi.stackexchange.com/questions/10711",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1750/"
] | After watching Damian Conway's [talk](http://radar.oreilly.com/2013/10/more-instantly-better-vim.html), I added the following two lines to my `.vimrc`.
```
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
```
My objective is to get the 81st column to be highlighted whenever a line goe... | Well, I solved the problem by myself.
as @Carpetsmoker♦ commented, I started to suspect that my `.vimrc` is a problem. I read [this question](https://vi.stackexchange.com/questions/2003/how-do-i-debug-my-vimrc-file) and started vim with this command inside tmux.
```
vim -u NONE -U NONE -N ~/.vimrc
```
After startin... |
10,725 | <p>We can execute bash command from vim like this:</p>
<pre><code>:! shuf -i1-123124 -n1
</code></pre>
<p>which generates random number in the given range. Is there a way to append the output to vim buffer?</p>
| [
{
"answer_id": 10726,
"author": "janos",
"author_id": 135,
"author_profile": "https://vi.stackexchange.com/users/135",
"pm_score": 3,
"selected": false,
"text": "<p>You can use filtering through an external program.\nThat's not the same as appending though.\nIn the simplest case, you cou... | 2016/12/23 | [
"https://vi.stackexchange.com/questions/10725",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | We can execute bash command from vim like this:
```
:! shuf -i1-123124 -n1
```
which generates random number in the given range. Is there a way to append the output to vim buffer? | `:read ! shuf -i1-123124 -n1`
Appending read before the command outputs it to the current buffer |
10,728 | <p>We can make from two lines a single with <code>J</code>. It looks as the following:</p>
<pre><code>line 1
line 2
</code></pre>
<p>after <code>J</code> pressed on line 1 we've got this:</p>
<pre><code>line 1 line 2
</code></pre>
<p>But is there a combination which what do the opposite (not <code>u</code>)? I mean... | [
{
"answer_id": 10729,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 4,
"selected": true,
"text": "<p>As far as I know, vim doesn't have a command for this. But vim is also all about customization. Easy enough to make yo... | 2016/12/23 | [
"https://vi.stackexchange.com/questions/10728",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9417/"
] | We can make from two lines a single with `J`. It looks as the following:
```
line 1
line 2
```
after `J` pressed on line 1 we've got this:
```
line 1 line 2
```
But is there a combination which what do the opposite (not `u`)? I mean to split
```
line 1 line 2
^
cursor
```
in
```
line 1
line 2
```
... | As far as I know, vim doesn't have a command for this. But vim is also all about customization. Easy enough to make your own mapping!
```
nnoremap s i<CR><Esc>
``` |