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 |
|---|---|---|---|---|---|---|
8,075 | <p>So I want to disable the arrow keys in insert mode. So I added the following lines at the end of <code>~/.vimrc</code>: </p>
<pre><code>inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
</code></pre>
<p>Now, every time I open a fi... | [
{
"answer_id": 8077,
"author": "Jakube",
"author_id": 7877,
"author_profile": "https://vi.stackexchange.com/users/7877",
"pm_score": 2,
"selected": true,
"text": "<p>Thanks everybody.</p>\n\n<p>With the command <code>:verbose :imap <up></code> and <code>:verbose :imap <down><... | 2016/06/03 | [
"https://vi.stackexchange.com/questions/8075",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7877/"
] | So I want to disable the arrow keys in insert mode. So I added the following lines at the end of `~/.vimrc`:
```
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
```
Now, every time I open a file the following effect happens: The left and right arrow are disabled in insert mode... | Thanks everybody.
With the command `:verbose :imap <up>` and `:verbose :imap <down>` if found out, that both arrows are used by YouCompleteMe.
The default keys for selecting a suggestion are tab and up, and for selecting a previous suggestion are s-tab and down. Since I only use tab and s-tab anyways, I was able to ... |
8,078 | <p>Consider the following <code>'errorformat'</code> configuration:</p>
<pre><code>set errorformat=%f:%l:\ %m
</code></pre>
<p>And the following message:</p>
<pre><code>%Warning-ASSIGNDLY: test.v:1: Unsupported: Ignoring delay.
</code></pre>
<p>While I expected that this message would not match, for some reason, af... | [
{
"answer_id": 8079,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 2,
"selected": false,
"text": "<p><em>Disclaimer: I have never used errorformat before.</em></p>\n\n<p>Edit: Deleted pointless stuff that was a mis-unde... | 2016/06/03 | [
"https://vi.stackexchange.com/questions/8078",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/599/"
] | Consider the following `'errorformat'` configuration:
```
set errorformat=%f:%l:\ %m
```
And the following message:
```
%Warning-ASSIGNDLY: test.v:1: Unsupported: Ignoring delay.
```
While I expected that this message would not match, for some reason, after running `:make` Vim is identifying this as a valid error... | As Tumbler41 [notes](https://vi.stackexchange.com/a/8079/7600), `isfname` has to be turned on:
>
> If "%f" is followed by a '%' or a backslash, it will look for a sequence of 'isfname' characters.
>
>
>
I had no luck inserting a % (`%:` is an invalid format), but I succeeded with a backslash. This requires a seco... |
8,082 | <p>I'm writing HTML lists, and I want to be able to automagically paste 10 list items where the item text is the only thing that changes.</p>
<p>I could accomplish this using PHP and then just copying the rendered HTML code but if there's a way to skip that step and do it directly from Vim that would save me so much t... | [
{
"answer_id": 8084,
"author": "Tim Ferguson",
"author_id": 7836,
"author_profile": "https://vi.stackexchange.com/users/7836",
"pm_score": 2,
"selected": false,
"text": "<p>I would probably do this with a mapping:</p>\n\n<pre><code> :nmap ^B o<li></li>^[4hi\n</code></pre>\n\n... | 2016/06/03 | [
"https://vi.stackexchange.com/questions/8082",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7795/"
] | I'm writing HTML lists, and I want to be able to automagically paste 10 list items where the item text is the only thing that changes.
I could accomplish this using PHP and then just copying the rendered HTML code but if there's a way to skip that step and do it directly from Vim that would save me so much time. | For what you want to do, [emmet-vim](https://github.com/mattn/emmet-vim), as nobe4 suggested, is your best bet.
In insert mode, `li{item $}*10<c-y>,` will expand 10 `<li>`s with `item N` prefilled as the text. You'll start editing the contents of the first one. While still in insert mode, pressing `<c-y>n` will move t... |
8,114 | <p>I have a line like this one:</p>
<pre><code>function my_function(argument, another argument, but there are spaces)
</code></pre>
<p>I want to substitute the space characters (inside the argument's names) with underscore. I thus would like to use :</p>
<pre><code>:s/\ /_/g
</code></pre>
<p>but how can I choose no... | [
{
"answer_id": 8115,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 5,
"selected": true,
"text": "<p>You could use the following solution:</p>\n\n<p>First use <kbd>v$</kbd> to select the text from the cursor to the end of t... | 2016/06/07 | [
"https://vi.stackexchange.com/questions/8114",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7128/"
] | I have a line like this one:
```
function my_function(argument, another argument, but there are spaces)
```
I want to substitute the space characters (inside the argument's names) with underscore. I thus would like to use :
```
:s/\ /_/g
```
but how can I choose not to apply it to the whole line, but starting fro... | You could use the following solution:
First use `v$` to select the text from the cursor to the end of the line. Then use the following command:
```
:s/\%V\ /_/g
```
The `\%V` indicate to change the text in the previously visually selected area, see [`:h /\%V`](http://vimdoc.sourceforge.net/htmldoc/pattern.html#/%5C... |
8,122 | <p>I have some files in my vim buffer.</p>
<p><code>:ls</code> shows the list of active buffer,
I want to open a file from buffer into a vertically/horizontally split window.</p>
<p>I know <code>:vsp</code> or <code>:sp</code> open split window in vim but how to open a split window from files in buffer?</p>
| [
{
"answer_id": 8123,
"author": "SibiCoder",
"author_id": 7161,
"author_profile": "https://vi.stackexchange.com/users/7161",
"pm_score": 4,
"selected": true,
"text": "<p>You can give </p>\n\n<pre><code>:vsplit | buffer buffernumber/buffername\n</code></pre>\n\n<p>to open a buffer in verti... | 2016/06/07 | [
"https://vi.stackexchange.com/questions/8122",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5890/"
] | I have some files in my vim buffer.
`:ls` shows the list of active buffer,
I want to open a file from buffer into a vertically/horizontally split window.
I know `:vsp` or `:sp` open split window in vim but how to open a split window from files in buffer? | You can give
```
:vsplit | buffer buffernumber/buffername
```
to open a buffer in vertical split mode.
**Example:**
```
:split | buffer 3
```
Same applies to horizontal split mode too. You can use `:sp` as a shortcut for `:split` and `:vs` for `:vsplit` |
8,127 | <p>I want to be able to search only within the <code>DiffText</code> regions of a file that I'm editing.</p>
<p>Related question: <a href="https://stackoverflow.com/questions/2683521/vim-search-in-c-c-code-lines">https://stackoverflow.com/questions/2683521/vim-search-in-c-c-code-lines</a></p>
<p>The accepted answer h... | [
{
"answer_id": 8132,
"author": "Antony",
"author_id": 7878,
"author_profile": "https://vi.stackexchange.com/users/7878",
"pm_score": 2,
"selected": false,
"text": "<p>Well, the simple way to search the differences (all\ndifferent lines, not just DiffText, sorry) would be to run\n<code>di... | 2016/06/07 | [
"https://vi.stackexchange.com/questions/8127",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6489/"
] | I want to be able to search only within the `DiffText` regions of a file that I'm editing.
Related question: <https://stackoverflow.com/questions/2683521/vim-search-in-c-c-code-lines>
The accepted answer here seems to work great for say, `Comment` or `Type` syntax groups, but any of the Diff groups don't work. I surm... | Not natively (also I have written a patch, that would allow to add a skip expression to the search() function, but this hasn't been included yet).
But you can workaround it by writing your own function that checks, whether the match is in a diff region contained. Something like this (very basic approach):
```
functio... |
8,128 | <p>I'm coming from Atom, and with that I can highlight multiple lines and hit <kbd>ctrl</kbd><kbd>/</kbd> and it'll toggle comments for those lines. I how easy this is.</p>
<p>Can I do something similar using <kbd>ctrl</kbd><kbd>/</kbd> with vim? I don't want to be doing <kbd>ctrl</kbd><kbd>v</kbd>, highlight rows, <c... | [
{
"answer_id": 8129,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 5,
"selected": true,
"text": "<p>It all depends on how extensive you want it to be. What type of files are you editing? I have the following in my <cod... | 2016/06/07 | [
"https://vi.stackexchange.com/questions/8128",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7911/"
] | I'm coming from Atom, and with that I can highlight multiple lines and hit `ctrl``/` and it'll toggle comments for those lines. I how easy this is.
Can I do something similar using `ctrl``/` with vim? I don't want to be doing `ctrl``v`, highlight rows, `//`, escape. That's too much effort. | It all depends on how extensive you want it to be. What type of files are you editing? I have the following in my `.vimrc` that works with python files:
```
let Comment='#'
xnoremap # :norm 0i<C-r>=Comment<CR><CR>
xnoremap & :norm ^<C-r>=len(Comment)<CR>x<CR>
```
This works well, but you have to manually setup each... |
8,134 | <p>I am trying to configure the statusline using plugins "vim-airline" and "vim-airline-themes". And i get this character "☰"</p>
<p>Please help me understand why is this being displayed and how to fix this. </p>
<p>Following is my .vimrc settings: </p>
<pre><code>" Backup Settings
set backup
set noswapfile
set back... | [
{
"answer_id": 8135,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 4,
"selected": true,
"text": "<p>That symbols stands for the last line number. So if it displays:\n<code>1/10 ☰</code> you know that you are on lin... | 2016/06/08 | [
"https://vi.stackexchange.com/questions/8134",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7919/"
] | I am trying to configure the statusline using plugins "vim-airline" and "vim-airline-themes". And i get this character "☰"
Please help me understand why is this being displayed and how to fix this.
Following is my .vimrc settings:
```
" Backup Settings
set backup
set noswapfile
set backupdir=~/.vim/tmp/backup//
se... | That symbols stands for the last line number. So if it displays:
`1/10 ☰` you know that you are on line 1 of 10 lines.
BTW: this symbol is in the documentation, search for maxlinenr. |
8,138 | <p>I want to define a Vim command that will install all LaTeX packages used in a <code>.tex</code> file.</p>
<p>To install packages I can do <code>sudo tlmgr install package1 package2 package3</code> etc. in the command line.</p>
<p>So now I need a way to get the names of all packages used in the file and use them wi... | [
{
"answer_id": 8140,
"author": "user9433424",
"author_id": 6960,
"author_profile": "https://vi.stackexchange.com/users/6960",
"pm_score": 2,
"selected": false,
"text": "<p>I'm not sure because I don't have the <code>tlmgr</code> shell command to test it, but you could try this:</p>\n\n<p... | 2016/06/08 | [
"https://vi.stackexchange.com/questions/8138",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7642/"
] | I want to define a Vim command that will install all LaTeX packages used in a `.tex` file.
To install packages I can do `sudo tlmgr install package1 package2 package3` etc. in the command line.
So now I need a way to get the names of all packages used in the file and use them with `tlmgr`.
It would be even better if... | To avoid leaving the buffer for entering the password, you can use `sudo`'s [`-S` flag](http://manpages.ubuntu.com/manpages/trusty/en/man8/sudo.8.html):
```none
-S, --stdin
Write the prompt to the standard error and read the password
from the standard input instead of using the terminal devi... |
8,147 | <p>I've found this little trick in vim wiki.</p>
<pre><code>nnoremap <Leader>s :%s/\<<C-r><C-w>\>//g<Left><Left>
</code></pre>
<p>Immediately I thought that in some cases it would be beneficial to use word in substitution, so I've added capturing parentheses for back reference.</p>... | [
{
"answer_id": 8148,
"author": "user9433424",
"author_id": 6960,
"author_profile": "https://vi.stackexchange.com/users/6960",
"pm_score": 3,
"selected": true,
"text": "<p>I'm not sure but maybe the following code could work:</p>\n\n<pre><code>nnoremap <expr> <Leader>s <SID... | 2016/06/08 | [
"https://vi.stackexchange.com/questions/8147",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6634/"
] | I've found this little trick in vim wiki.
```
nnoremap <Leader>s :%s/\<<C-r><C-w>\>//g<Left><Left>
```
Immediately I thought that in some cases it would be beneficial to use word in substitution, so I've added capturing parentheses for back reference.
```
nnoremap <leader>* *:%s/\v(<<C-r><C-w>>)//g<Left><Left>
```... | I'm not sure but maybe the following code could work:
```
nnoremap <expr> <Leader>s <SID>change_word_under_cursor()
fu! s:change_word_under_cursor() abort
let word = expand('<cword>')
let subwords = split(word, word =~# '_' ? '_' : '\ze\u')
return ':%s/\v' . join(map(subwords, '"(" . v:val . ")"'), word =~... |
8,167 | <p>I have been changing "$OLD" to "~/new" in a lot of files lately, so I am now used to starting vim like this</p>
<pre><code>$ vim file.txt
</code></pre>
<p><kbd>Enter</kbd></p>
<pre><code>Lorem ipsum $OLD
Lorem .OLD ipsum
</code></pre>
<p><kbd>:</kbd><kbd>%</kbd><kbd>up</kbd> (brings back <code>%s:\$OLD:\~/new:gc... | [
{
"answer_id": 8159,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 1,
"selected": false,
"text": "<p>Visual mode is not available in original vi. However, you should still be able to use a numbered yank or marks.</p>\n\... | 2016/06/10 | [
"https://vi.stackexchange.com/questions/8167",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/182/"
] | I have been changing "$OLD" to "~/new" in a lot of files lately, so I am now used to starting vim like this
```
$ vim file.txt
```
`Enter`
```
Lorem ipsum $OLD
Lorem .OLD ipsum
```
`:``%``up` (brings back `%s:\$OLD:\~/new:gc`)`Enter`
`:``w``q``Enter`
```
$
```
So I added a new autocommand in ~/.vimrc, like th... | I downloaded Busybox out of curiosity, and can reproduce
the problems you're having with that version of vi.
I have version `1.25.0-FRP-441-g53c3b08 2016-05-24 12:20:38 BST`.
A large number of vi commands seem to be unimplemented,
such as `:copy`, `v`, and `S`. `{` and `}` don't seem to work
properly.
In terms of yan... |
8,169 | <p>Often times I edit a file - think my work is done - then close the file and move on to the next thing. But then I realise I need to go back to that code and tweak it a bit more.<br>
If I open the file again, I can use the <code>.</code> mark and jump to the position of the last edit with <code>'.</code>.<br>
Now I'... | [
{
"answer_id": 8170,
"author": "the_velour_fog",
"author_id": 4603,
"author_profile": "https://vi.stackexchange.com/users/4603",
"pm_score": 2,
"selected": false,
"text": "<p>I wrote this vimscript statement which seems to work</p>\n\n<pre><code>autocmd BufLeave * :normal ml\n</code></pr... | 2016/06/10 | [
"https://vi.stackexchange.com/questions/8169",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4603/"
] | Often times I edit a file - think my work is done - then close the file and move on to the next thing. But then I realise I need to go back to that code and tweak it a bit more.
If I open the file again, I can use the `.` mark and jump to the position of the last edit with `'.`.
Now I'm trying to find a way to us... | Here is a classic solution: use
```
`H
```
to jump to the last HTML file and so on…
```
augroup VIMRC
autocmd!
autocmd BufLeave *.css normal! mC
autocmd BufLeave *.html normal! mH
autocmd BufLeave *.js normal! mJ
autocmd BufLeave *.php normal! mP
augroup END
``` |
8,179 | <p>I'd like to replace 'x' in this file with current line number. That is, change</p>
<pre><code>x
x
x
</code></pre>
<p>to</p>
<pre><code>1
2
3
</code></pre>
<p>For now, I use a Perl one-liner:</p>
<pre><code>perl -pi -e '$x=$.; s/x/$x/' myfile.txt
</code></pre>
<p>I think UltraEdit can do it with a vertical sele... | [
{
"answer_id": 8180,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 6,
"selected": true,
"text": "<p>Yes, vim can do this! Do a global search for <code>x</code>, and replace it with <code>\\=printf(\"%d\", line('.')</co... | 2016/06/10 | [
"https://vi.stackexchange.com/questions/8179",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7953/"
] | I'd like to replace 'x' in this file with current line number. That is, change
```
x
x
x
```
to
```
1
2
3
```
For now, I use a Perl one-liner:
```
perl -pi -e '$x=$.; s/x/$x/' myfile.txt
```
I think UltraEdit can do it with a vertical select and replace. Can this be done in vim? (My example here assumes 'x' is... | Yes, vim can do this! Do a global search for `x`, and replace it with `\=printf("%d", line('.')`. For example:
```
:%s/x/\=printf("%d", line('.'))
```
You can also change `x` to another search, if you need to.
Explanation:
This replaces every occurence of `x` (or whatever you search for) with the evaluation regist... |
8,189 | <p>I want to add a motion:</p>
<pre><code>:onoremap <silent> f( :<C-U>normal! f)vF(b<CR>
</code></pre>
<p>If I have this line, where the asterisk is my current position:</p>
<pre><code>int a = fo*o(4, 5, 99);
</code></pre>
<p>I want to type <kbd>v</kbd><kbd>f</kbd><kbd>(</kbd> and select <code>foo... | [
{
"answer_id": 8190,
"author": "SibiCoder",
"author_id": 7161,
"author_profile": "https://vi.stackexchange.com/users/7161",
"pm_score": 3,
"selected": true,
"text": "<p><code>Operator pending mode</code> has to be used only when waiting for a motion. You have used <code>f</code>, which w... | 2016/06/11 | [
"https://vi.stackexchange.com/questions/8189",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6300/"
] | I want to add a motion:
```
:onoremap <silent> f( :<C-U>normal! f)vF(b<CR>
```
If I have this line, where the asterisk is my current position:
```
int a = fo*o(4, 5, 99);
```
I want to type `v``f``(` and select `foo(4, 5, 99)`. Later on I want to add the equivalents for `[`, `{`, and `<`.
However the above sadl... | `Operator pending mode` has to be used only when waiting for a motion. You have used `f`, which waits for a character and moves there. Since you have given both `f` and `(` together, `f` has got a character to find and move to. Hence, there isn't any operator 'pending'!
So, you can map in normal mode itself, like
``... |
8,207 | <p>I am trying to highlight a word in the current buffer dynamically like so:</p>
<pre><code>function! Highlight()
let @/ = 'word'
set hlsearch
endfunction
</code></pre>
<p>When I run this function, the register <code>/</code> contains <code>word</code> as desired but the word <code>word</code> is not highlight... | [
{
"answer_id": 8225,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": true,
"text": "<p>A workaround:</p>\n\n<pre><code>function! Highlight()\n\n call matchadd('error', 'word')\n\nendfunction\n</code></pre>\n\n... | 2016/06/12 | [
"https://vi.stackexchange.com/questions/8207",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I am trying to highlight a word in the current buffer dynamically like so:
```
function! Highlight()
let @/ = 'word'
set hlsearch
endfunction
```
When I run this function, the register `/` contains `word` as desired but the word `word` is not highlighted.
This surprises me because if I remove the `set hlsearc... | A workaround:
```
function! Highlight()
call matchadd('error', 'word')
endfunction
```
The `matchadd` function takes an highlight group (here `'error'`) and a regex to match (here `'word'`), it will create a new highlight a return it's ID.
---
**Bonus:**
If you want to change the highlight over time, you can ... |
8,208 | <p>Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register?</p>
<p>I looked through <code>:h functions</code> but didn't find anything.</p>
| [
{
"answer_id": 8210,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": false,
"text": "<p>There is no other way but to yank it into a register. At best, you can restore the register once you're done.</p>\n\n... | 2016/06/12 | [
"https://vi.stackexchange.com/questions/8208",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6300/"
] | Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register?
I looked through `:h functions` but didn't find anything. | If you really want to avoid the registers, you can use the visual marks to figure out byte positions of the selected text:
```
function! s:pos2byte(pos) abort
return line2byte(a:pos[1]) + a:pos[2]
endfunction
function! s:get_visual_text() abort
let b1 = s:pos2byte(getpos("'<"))
let b2 = s:pos2byte(getpos(... |
8,209 | <p>Given the file <em>alfa.c</em>:</p>
<pre><code>// Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque usu
#include <stdio.h>
int main() {
puts("hello world");
}
</code></pre>
<p>I would li... | [
{
"answer_id": 8211,
"author": "SibiCoder",
"author_id": 7161,
"author_profile": "https://vi.stackexchange.com/users/7161",
"pm_score": 0,
"selected": false,
"text": "<p>You can set a limit for a line, like 80 columns for a line.</p>\n\n<p>Then you can set a autocommand to split such lin... | 2016/06/12 | [
"https://vi.stackexchange.com/questions/8209",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | Given the file *alfa.c*:
```
// Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque usu
#include <stdio.h>
int main() {
puts("hello world");
}
```
I would like to format all long comments to get r... | Depending on your configuration you can achieve the desired result with:
```
gq
```
If you want to use this as a ex command you can use:
```
normal! gqq
```
to format the current line.
Aslo, it's worth adding the flags `a` and `c` to your `'formatoption'` configuration:
```
set fo+=ac
```
This will try to pre... |
8,226 | <p>The following mapping doesn't work as expected:</p>
<pre><code>cnoremap $ <esc>
</code></pre>
<p>I would expect that when I press <kbd>$</kbd> in command line mode, it cancels the current command line and returns to normal mode.</p>
<p>But instead of that, it <em>runs</em> the current command line, and retu... | [
{
"answer_id": 8227,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 4,
"selected": true,
"text": "<p>I don't know why <code><esc></code> doesn't work, but you <em>can</em> use <code><C-c></code>. I.e.:</p>\n\... | 2016/06/14 | [
"https://vi.stackexchange.com/questions/8226",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5516/"
] | The following mapping doesn't work as expected:
```
cnoremap $ <esc>
```
I would expect that when I press `$` in command line mode, it cancels the current command line and returns to normal mode.
But instead of that, it *runs* the current command line, and returns to normal mode (as if I had pressed the `Return` ke... | I don't know why `<esc>` doesn't work, but you *can* use `<C-c>`. I.e.:
```
cnoremap $ <C-c>
```
**Edit:**
Found the reason for this behavior in `:h c_<Esc>`:
>
> In macros or when 'x' present in 'cpoptions', start entered command.
>
>
> |
8,231 | <p>I want to be able to delete indenting spaces one at a time. </p>
<p>If I set <code>shiftwidth</code> to 4, it deletes 4 spaces at a time if vim counts them as indentation. Setting <code>shiftwidth</code> to 1 fixes the problem, but makes vim autoindents using 1 space instead of a tab and inserts 1 space when I try ... | [
{
"answer_id": 8234,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 2,
"selected": false,
"text": "<p>I think some of your confusion comes down to terminology. There are two separate characters, space <code>\" \"</code>... | 2016/06/14 | [
"https://vi.stackexchange.com/questions/8231",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8006/"
] | I want to be able to delete indenting spaces one at a time.
If I set `shiftwidth` to 4, it deletes 4 spaces at a time if vim counts them as indentation. Setting `shiftwidth` to 1 fixes the problem, but makes vim autoindents using 1 space instead of a tab and inserts 1 space when I try to insert a tab.
Is it possible... | I think some of your confusion comes down to terminology. There are two separate characters, space `" "` and tab `"\t"`. Tabs are a single character, but get displayed as several blank columns. This can be configured with "shiftwidth". If you do `:set shiftwidth=4` this means
>
> When I press tab, insert a tab charac... |
8,232 | <p>I know the separate answers. For example,</p>
<ul>
<li>To open several files: <code>:n \**/*.f90</code></li>
<li>To save <code>*.f90</code> file to HTML: <code>:TOhtml</code> and <code>:wq</code>.</li>
</ul>
<p>However, I don't know how to combine both of them.</p>
| [
{
"answer_id": 8233,
"author": "Antony",
"author_id": 7878,
"author_profile": "https://vi.stackexchange.com/users/7878",
"pm_score": 4,
"selected": true,
"text": "<p>After you've added your files to the arguments list with <code>:n ./**/*.f90</code> (<code>:args</code> + filenames would ... | 2016/06/14 | [
"https://vi.stackexchange.com/questions/8232",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8010/"
] | I know the separate answers. For example,
* To open several files: `:n \**/*.f90`
* To save `*.f90` file to HTML: `:TOhtml` and `:wq`.
However, I don't know how to combine both of them. | After you've added your files to the arguments list with `:n ./**/*.f90` (`:args` + filenames would do the same thing and is perhaps more obvious) you can use:
```
:argdo exe 'TOhtml' | wq
```
`:argdo` will execute its following commands for each buffer that's in the argument list. Note that you need to use `TOhtml`... |
8,237 | <p>Is it possible to copy the absolute filepath of the file under the cursor in Netrw?</p>
| [
{
"answer_id": 8238,
"author": "SibiCoder",
"author_id": 7161,
"author_profile": "https://vi.stackexchange.com/users/7161",
"pm_score": 2,
"selected": false,
"text": "<p>You can select the file under cursor through visual block mode, like <code>Ctrl+V</code>, then press <code>$</code> an... | 2016/06/15 | [
"https://vi.stackexchange.com/questions/8237",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8013/"
] | Is it possible to copy the absolute filepath of the file under the cursor in Netrw? | You can select the file under cursor through visual block mode, like `Ctrl+V`, then press `$` and then a `j` and then a `y`.
Now, in command line mode,
Type
```
:echo @%.@"
```
This will show the full path of the file under cursor.
You can also map it to a key,
Like
```
:map \f ^<C-V>$jy:echo @%.@"<CR>
```
Now... |
8,249 | <p>I have a file like the following : two different files were yanked one after another, and the numbers subsequently don't match anymore.</p>
<pre><code> ... 46
atom 142 option 47
atom 143 option 48
atom 12 option 7 # There's a discontinuity in the numbers at this line
ato... | [
{
"answer_id": 8251,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": false,
"text": "<p><strong>edit :</strong> answer posted before knowing OP had no support for the visual increment.</p>\n\n<hr>\n\n<p>Here is... | 2016/06/15 | [
"https://vi.stackexchange.com/questions/8249",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7128/"
] | I have a file like the following : two different files were yanked one after another, and the numbers subsequently don't match anymore.
```
... 46
atom 142 option 47
atom 143 option 48
atom 12 option 7 # There's a discontinuity in the numbers at this line
atom 13 opti... | Visually select all the lines you want to increment, and do the following:
```
:s/\d\+/\=submatch(0) + 132
```
Does exactly what you describe. Visually selects a bunch of numbers, and adds a mathematical constant to each of them. If you leave of the `/g` flag, it will only increment the first number on each line. Th... |
8,256 | <p>When saving a session with <code>:mksession</code> and <code>source</code>ing it back, I noticed that alternate files (accessed via <code>C-^</code>) are not persisted.</p>
<p>The docs don't mention anything about persisting alternate files. Is there a way/workaround/hack to do so?</p>
| [
{
"answer_id": 8267,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": false,
"text": "<p>Since there is no option to do this directly, you can hack around like this:</p>\n\n<pre><code>function! MkSession(filenam... | 2016/06/15 | [
"https://vi.stackexchange.com/questions/8256",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7318/"
] | When saving a session with `:mksession` and `source`ing it back, I noticed that alternate files (accessed via `C-^`) are not persisted.
The docs don't mention anything about persisting alternate files. Is there a way/workaround/hack to do so? | Since there is no option to do this directly, you can hack around like this:
```
function! MkSession(filename)
execute 'mksession! '.a:filename
let l:alternate = fnameescape(expand('#'))
if l:alternate != ''
call system('echo "let @#=\"'.l:alternate.'\"" >> '.a:filename)
endif
endfunction
command! -nar... |
8,257 | <p>I'd like to be able to view the last n commands, similar to the <code>history</code> command in bash, and then be able to execute the nth command similar to the way it is done in bash by using <code>!<command number></code> is there an equivalent to this in vim?</p>
| [
{
"answer_id": 8267,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": false,
"text": "<p>Since there is no option to do this directly, you can hack around like this:</p>\n\n<pre><code>function! MkSession(filenam... | 2016/06/15 | [
"https://vi.stackexchange.com/questions/8257",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1065/"
] | I'd like to be able to view the last n commands, similar to the `history` command in bash, and then be able to execute the nth command similar to the way it is done in bash by using `!<command number>` is there an equivalent to this in vim? | Since there is no option to do this directly, you can hack around like this:
```
function! MkSession(filename)
execute 'mksession! '.a:filename
let l:alternate = fnameescape(expand('#'))
if l:alternate != ''
call system('echo "let @#=\"'.l:alternate.'\"" >> '.a:filename)
endif
endfunction
command! -nar... |
8,258 | <p><strong>Background</strong>: I am doing more and more stuff directly from inside Neovim, and less and less from the terminal or even the terminal emulator. So instead of going to the desired directory to work in, and then starting Neovim, I prefer to just start Neovim, and then change to the desired directory. This ... | [
{
"answer_id": 8299,
"author": "still_dreaming_1",
"author_id": 1410,
"author_profile": "https://vi.stackexchange.com/users/1410",
"pm_score": 2,
"selected": false,
"text": "<p>Here is a hack/workaround I am using in my config file. It is not an ideal solution, but it is the best I can c... | 2016/06/15 | [
"https://vi.stackexchange.com/questions/8258",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1410/"
] | **Background**: I am doing more and more stuff directly from inside Neovim, and less and less from the terminal or even the terminal emulator. So instead of going to the desired directory to work in, and then starting Neovim, I prefer to just start Neovim, and then change to the desired directory. This next part is a b... | One solution is to use the autocmd DirChanged to open a new buffer every time the directory changes. This way vim-fugitive will associate the new buffer with the new directory. As fugitive associates each buffer with a particular git directory, this is better than somehow forcing fugitive to consider the old buffer to ... |
8,283 | <p>When saving a session with <code>:mksession</code> and <code>:source</code>ing it back, the content of <code>[No Name]</code> unnamed buffers is lost.</p>
<p>I like to sometimes write temporary throwaway code or notes on a unnamed or scratch buffer, for the length of my session.</p>
<p>Just like Sublime Text saves... | [
{
"answer_id": 8284,
"author": "Jerome Dalbert",
"author_id": 7318,
"author_profile": "https://vi.stackexchange.com/users/7318",
"pm_score": 2,
"selected": false,
"text": "<p><strong>Vim workarounds:</strong></p>\n\n<ul>\n<li>write temporary notes/code in predefined system-wide or projec... | 2016/06/16 | [
"https://vi.stackexchange.com/questions/8283",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7318/"
] | When saving a session with `:mksession` and `:source`ing it back, the content of `[No Name]` unnamed buffers is lost.
I like to sometimes write temporary throwaway code or notes on a unnamed or scratch buffer, for the length of my session.
Just like Sublime Text saves the content of "untitled new tabs" when quitting ... | You could use the following function. It is extremely hacky and I haven't tested
it plenty but it seems to work.
The idea is to create a command `:Mksession` which will work like the original
`:mksession` but will also save the unnamed buffers.
(Note that I had some inspiration from [this
answer](https://vi.stackexch... |
8,285 | <p>I know there is one way to search and replace variable occurrences across a source file.</p>
<p>But is there any better way by which if I rename a variable at one place it gets renamed at other places as well without search and replace or substitute?</p>
| [
{
"answer_id": 8286,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "<p>You can use a substitute:</p>\n\n<pre><code>:%s/original/replaced/g\n</code></pre>\n\n<p>Will <code>s</code>ubstitute acro... | 2016/06/17 | [
"https://vi.stackexchange.com/questions/8285",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5890/"
] | I know there is one way to search and replace variable occurrences across a source file.
But is there any better way by which if I rename a variable at one place it gets renamed at other places as well without search and replace or substitute? | You can just use the usual workflow `search` and `replace`:
```
/original
cwreplaced
n.n.
```
---
You can take also advantage of the `gn` motion:
```
/original<CR>
cgnreplaced<ESC>
.....
```
`cgn` will `c`hange the `n`ext matched pattern, so instead of using `n.n.` to `go to next` and `repeat` you can just `..` ... |
8,287 | <p>If I try to copy a word via this <code>yw</code> – yank the current word and paste it to somewhere, it works but If I try to paste it somewhere else one more time old world gets lost with previous replaced word.</p>
<p>I want to paste multiple times with the original yanked word.</p>
| [
{
"answer_id": 8289,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": true,
"text": "<p>You should use the register <code>0</code>. It contains the last yanked text.</p>\n\n<p>By default, <code>c</code>, <code>d... | 2016/06/17 | [
"https://vi.stackexchange.com/questions/8287",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5890/"
] | If I try to copy a word via this `yw` – yank the current word and paste it to somewhere, it works but If I try to paste it somewhere else one more time old world gets lost with previous replaced word.
I want to paste multiple times with the original yanked word. | You should use the register `0`. It contains the last yanked text.
By default, `c`, `d`, `y` use the unnamed register `""` to store all modified text.
But the numbered registers `"0` contains the previously yanked text and only that. You can use :
```
"0p
```
With confidence it will past the last yanked text. |
8,291 | <p>Just like the topic says; is it possible to add a certain text string in the beginning of a file if I create a certain file type?</p>
<p>For example, if I create a random Python file with <code>vim random.py</code>. Can I configure my vim to automatically add <code>#!/usr/bin/python</code> at line 1?</p>
<p>I have... | [
{
"answer_id": 8292,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>Yup the question you linked should have helped you:</p>\n\n<pre><code>autocmd BufNewFile *.py normal! ggI#!/bin/python\n<... | 2016/06/17 | [
"https://vi.stackexchange.com/questions/8291",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8062/"
] | Just like the topic says; is it possible to add a certain text string in the beginning of a file if I create a certain file type?
For example, if I create a random Python file with `vim random.py`. Can I configure my vim to automatically add `#!/usr/bin/python` at line 1?
I have a standard vim installation without an... | You can accomplish it by placing
```
autocmd BufNewFile *.py norm i#!/usr/bin/python
```
in your `.vimrc` file. This should insert the text at the beginning of the first file, whenever you open a non-existing file with the file extension `py`.
The part `norm i#!/usr/bin/python` is simply commands which are executed... |
8,311 | <p>According to <code>:h compatible</code>:</p>
<blockquote>
<p>(...) when a |vimrc| or |gvimrc| file exists,
Vim will use the Vim defaults, otherwise it will use the Vi defaults.</p>
</blockquote>
<p>But when I try:</p>
<pre><code>$ mv ~/.vimrc vimrc
$ vim -c 'set cp?'
</code></pre>
<p>Vim tells me:</p>
<pre>... | [
{
"answer_id": 8312,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 3,
"selected": false,
"text": "<p>I just tried it, and I think I know what causes this. When I delete my vimrc, start vim, and run <code>:scriptnames</... | 2016/06/18 | [
"https://vi.stackexchange.com/questions/8311",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7700/"
] | According to `:h compatible`:
>
> (...) when a |vimrc| or |gvimrc| file exists,
> Vim will use the Vim defaults, otherwise it will use the Vi defaults.
>
>
>
But when I try:
```
$ mv ~/.vimrc vimrc
$ vim -c 'set cp?'
```
Vim tells me:
```
nocompatible
```
If I force it by:
```
$ vim -u NONE -c 'set cp?'
... | Thanks to DJ McMayhem pointing me in the right direction I found that Linux distros meddle with the `nocompatible` behaviour of `vim`. Since I cannot expect that everyone here know `unix` jargon, where I use `$` I'm working as a normal user and where I use `#` i do commands as the superuser (`root`).
1. Vim ignores `/... |
8,333 | <p>I am using <a href="https://github.com/scrooloose/nerdcommenter/" rel="nofollow noreferrer">https://github.com/scrooloose/nerdcommenter/</a> plugin to comment the code. It's working fine, but I would like to do a modification.</p>
<p>Currently these are the default mappings:</p>
<ul>
<li><code><leader>cc</co... | [
{
"answer_id": 23057,
"author": "Chris Stryczynski",
"author_id": 13656,
"author_profile": "https://vi.stackexchange.com/users/13656",
"pm_score": 0,
"selected": false,
"text": "<p>Seems that plugins have \"actions\" that you can call with <code>:call</code>.</p>\n\n<p>For example to map... | 2016/06/20 | [
"https://vi.stackexchange.com/questions/8333",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8092/"
] | I am using <https://github.com/scrooloose/nerdcommenter/> plugin to comment the code. It's working fine, but I would like to do a modification.
Currently these are the default mappings:
* `<leader>cc` comments the line
* `<leader>ci` inverts the comment
* `<leader>cu` undo last comment/uncomment action
I am looking ... | Like many other plug-ins, NERDCommenter creates internal mappings using the `<plug>` virtual key as a prefix, that you can use to map your own key-bindings to.
See [`:help NERDCommenterMappings`](https://github.com/preservim/nerdcommenter/blob/c62e618a1ab5a50a4028e3296500ba29d9b033d8/doc/NERD_commenter.txt#L872):
>
... |
8,357 | <p>I'm trying to figure out how the vim concept of buffers, windows, and tabs maps onto emacs.</p>
<p>It seems to me that <code><c-w>s</code> and <code><c-w>v</code> are roughly equivalent to Emacs <code>C-x 2</code> and <code>C-x 3</code>. They're not exactly equivalent since vim splits are equally spaced... | [
{
"answer_id": 8358,
"author": "lwassink",
"author_id": 8105,
"author_profile": "https://vi.stackexchange.com/users/8105",
"pm_score": 2,
"selected": false,
"text": "<p>Close window: <code>Ctrl-w c</code></p>\n\n<p>Close all other windows: <code>Ctrl-w o</code>, (<code>o</code> for \"onl... | 2016/06/21 | [
"https://vi.stackexchange.com/questions/8357",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6420/"
] | I'm trying to figure out how the vim concept of buffers, windows, and tabs maps onto emacs.
It seems to me that `<c-w>s` and `<c-w>v` are roughly equivalent to Emacs `C-x 2` and `C-x 3`. They're not exactly equivalent since vim splits are equally spaced by default and emacs will bisect the current window.
What is th... | By default, Vim will refuse to replace the current buffer with another one if it contains unsaved changes. You'll need to add the option below to your `vimrc` if you don't want that behavior (and you don't want that):
```
set hidden
```
Buffers are Vim's equivalent of documents in other programs. When you switch to ... |
8,361 | <p>I was working on building a regex in the command prompt. After a few iterations, my prompt looks like this:</p>
<pre><code>:echom 'test_foo_bar.py' =~ '^test_.*\.py$' ? 'yes' : 'no'
</code></pre>
<p>Now that I have my regex ready, I want to put it in the script I'm editing. Is there an easy way to take the text fr... | [
{
"answer_id": 8363,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 4,
"selected": false,
"text": "<p>Press <kbd>Ctrl</kbd><kbd>F</kbd> (or in normal mode, press <a href=\"http://vimhelp.appspot.com/cmdline.txt.html#q%3A\" rel=... | 2016/06/21 | [
"https://vi.stackexchange.com/questions/8361",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6475/"
] | I was working on building a regex in the command prompt. After a few iterations, my prompt looks like this:
```
:echom 'test_foo_bar.py' =~ '^test_.*\.py$' ? 'yes' : 'no'
```
Now that I have my regex ready, I want to put it in the script I'm editing. Is there an easy way to take the text from my command prompt and s... | In addition to the `Ctrl``F`, which provides complete navigation on the command history, you could use [`Ctrl``R`+`:` in insert mode](http://vimhelp.appspot.com/insert.txt.html#i_CTRL-R) (faster but works only for the latest command):
```
CTRL-R {0-9a-z"%#*+:.-=} *i_CTRL-R*
Insert the conten... |
8,365 | <p>Entering in vim</p>
<pre><code>:au FileType netrw echom "ft is now netrw"
</code></pre>
<p>Afterwards, I open a netrw window with <code>:E .</code>
Now, I expect to have a message entry in <code>:messages</code>. However, no message is there. Why is there no message?</p>
<p>According to "<a href="https://vi.stack... | [
{
"answer_id": 8367,
"author": "mMontu",
"author_id": 1405,
"author_profile": "https://vi.stackexchange.com/users/1405",
"pm_score": 4,
"selected": true,
"text": "<p>Your autocmd is clearly correct, as you can see that the message is printed if you explicitly set the <code>'ft'</code> wi... | 2016/06/21 | [
"https://vi.stackexchange.com/questions/8365",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1292/"
] | Entering in vim
```
:au FileType netrw echom "ft is now netrw"
```
Afterwards, I open a netrw window with `:E .`
Now, I expect to have a message entry in `:messages`. However, no message is there. Why is there no message?
According to "[How to display line number in netrw?](https://vi.stackexchange.com/questions/78... | Your autocmd is clearly correct, as you can see that the message is printed if you explicitly set the `'ft'` with `setl ft=netrw`.
The problem you are facing is that something is blocking the messages (such as `:silent`).
But your autocmd is being called when the filetype is first set; you can ensure that by using th... |
8,370 | <p>Generally you can select a visual block for the first n characters of a range of lines, and just press <kbd>c</kbd>, insert characters, and press <kbd>Esc</kbd> to have it apply to all.</p>
<p>However, this method is rarely possible for all the latter characters, because lines of code are likely to vary in length.<... | [
{
"answer_id": 8372,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p><strong>EDIT</strong> Here is a better solution than the one I gave previously:</p>\n\n<pre><code>'<,'>g/.*/norm! $... | 2016/06/22 | [
"https://vi.stackexchange.com/questions/8370",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | Generally you can select a visual block for the first n characters of a range of lines, and just press `c`, insert characters, and press `Esc` to have it apply to all.
However, this method is rarely possible for all the latter characters, because lines of code are likely to vary in length.
How can I easily change the... | It would not work all the time, but maybe you could temporarily right-align the right border of the code.
Suppose you have the following code containing 3 lines, each with the same level of indentation (`8`):
```
here is foo
here will be foo
here was foo
```
And you want to change `foo` with... |
8,378 | <p>How do I dump an internal vim command (not shell command) into a new buffer?</p>
<p>For example, I want to dump a listing of all plugins into <code>:enew</code> from <code>:scriptnames</code> so that I can search it.</p>
| [
{
"answer_id": 8379,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 7,
"selected": true,
"text": "<p>You can use <code>:redir</code> to redirect the output to a variable, register, or file. Example of redirecting to th... | 2016/06/22 | [
"https://vi.stackexchange.com/questions/8378",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2786/"
] | How do I dump an internal vim command (not shell command) into a new buffer?
For example, I want to dump a listing of all plugins into `:enew` from `:scriptnames` so that I can search it. | You can use `:redir` to redirect the output to a variable, register, or file. Example of redirecting to the unnamed register:
```
:redir @">|silent scriptnames|redir END|enew|put
```
Alternatively Tim Pope's [scriptease.vim](https://github.com/tpope/vim-scriptease) provides the `:Scriptnames` command which will load... |
8,381 | <p>I started using <strong>syntastic</strong> plugin with <strong>vim</strong> to report lint errors in my <code>javascript</code> code.</p>
<p>I also integrated <strong>eslint</strong> with <strong>syntastic</strong>, and it shows me nice errors, warnings in case they are present as per rules written in my <strong>.e... | [
{
"answer_id": 11281,
"author": "JepZ",
"author_id": 11201,
"author_profile": "https://vi.stackexchange.com/users/11201",
"pm_score": 4,
"selected": false,
"text": "<p>As mentioned in the comments be aware of the consequences this modification has to you work environment (know exactly wh... | 2016/06/22 | [
"https://vi.stackexchange.com/questions/8381",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5890/"
] | I started using **syntastic** plugin with **vim** to report lint errors in my `javascript` code.
I also integrated **eslint** with **syntastic**, and it shows me nice errors, warnings in case they are present as per rules written in my **.eslintrc** file.
Is there any way in which I can fix some common errors e.g mis... | As mentioned in the comments be aware of the consequences this modification has to you work environment (know exactly which eslint rules you use to "fix" things).
To answer your question: adding the option to the eslint execution with syntactic is [straight forward](https://github.com/vim-syntastic/syntastic#faqargs).... |
8,382 | <p>I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying incorrect spacing for the line of code that I added. Gedit shows the code with the correct spacing. I know Gedit has... | [
{
"answer_id": 8383,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>It gets reset by the Python filetype plugin; from <code>/usr/share/vim/vim74/ftplugin/python.vim</code>:</p>\n<pre><c... | 2016/06/22 | [
"https://vi.stackexchange.com/questions/8382",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8137/"
] | I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying incorrect spacing for the line of code that I added. Gedit shows the code with the correct spacing. I know Gedit has the c... | It gets reset by the Python filetype plugin; from `/usr/share/vim/vim74/ftplugin/python.vim`:
```
" As suggested by PEP8.
setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
```
This file is loaded every time a Python file is loaded.
To override it add this in your vimrc:
```
augroup python
autocmd!
" ... |
8,386 | <p>I find myself performing a small shell loop (involving <code>vim</code>) to transform files into the correct line endings for my system. It looks as follows:</p>
<pre><code>for i in *; do vim -c 'set ff=dos' -c 'wq' $i; done
</code></pre>
<p>It works. The problem is that the terminal flashes during the loop as v... | [
{
"answer_id": 8394,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": true,
"text": "<p>You can use the following, it is nearly what you have done (using another example to see difference), you need to add the <... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8386",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7700/"
] | I find myself performing a small shell loop (involving `vim`) to transform files into the correct line endings for my system. It looks as follows:
```
for i in *; do vim -c 'set ff=dos' -c 'wq' $i; done
```
It works. The problem is that the terminal flashes during the loop as vim **opens and closes repeatedly**. The... | You can use the following, it is nearly what you have done (using another example to see difference), you need to add the `hidden` option:
```
$ touch a b c
$ cat *
$ vi * +"set hidden" +"argdo r\!ls" +"xall"
$ cat *
a
b
c
a
b
c
a
b
c
```
`set hidden` tells vim you can switch buffer without saving them.
If you s... |
8,389 | <p>I was reading that the way to indent in vim is a <code>gg=G</code> sequence. This however loses my cursor position. </p>
<p>How can I indent my file without losing my cursor position?</p>
| [
{
"answer_id": 8390,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>You should use a mark, e.g.:</p>\n\n<pre><code>magg=G`a\n</code></pre>\n\n<p>Here <code>ma</code> will set the <co... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8389",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | I was reading that the way to indent in vim is a `gg=G` sequence. This however loses my cursor position.
How can I indent my file without losing my cursor position? | Expanding on Karl Yngve Lervåg's answer:
```
maHmbgg=G`bzt`a
```
Explanation:
```
ma - Set mark 'a'
H - Jump to the top of the window
mb - Set mark 'b'
gg=G - Indent from the first line to the last
`b - Jump to mark 'b'
zt - Scroll the cursor line to the top of the window
`a - Jump to mark 'a'
```
Th... |
8,395 | <p>Right now I am working on a latex project. When I open a netrw/vinegar window, I get following coloring:</p>
<p><a href="https://i.stack.imgur.com/6oiWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6oiWR.png" alt="enter image description here"></a></p>
<p>Apparently, certain filetypes are gra... | [
{
"answer_id": 8401,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 1,
"selected": false,
"text": "<p>I think the <code>g:netrw_special_syntax</code> specify wether you want the special highlight or not, you should not be ab... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8395",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1292/"
] | Right now I am working on a latex project. When I open a netrw/vinegar window, I get following coloring:
[](https://i.stack.imgur.com/6oiWR.png)
Apparently, certain filetypes are grayed out and other are not. I like the idea to emphasize files which ... | With the help of [nobe4](https://vi.stackexchange.com/users/1821/nobe4) I figured it out.
The plugin vinegar by tpope adds `netrwSuffixes` to `SpecialKey`.
```
exe 'syn match netrwSuffixes =\%(\S\+ \)*\S\+\%('.join(map(split(&suffixes, ','), s:escape), '\|') . '\)[*@]\=\S\@!='
hi def link netrwSuffixes SpecialKey
... |
8,399 | <p>My file consists of the following text</p>
<pre><code>one
bone
stone
cuttlebone
minestrone
cornerstone
</code></pre>
<p>and I want to select all instances of <code>bone</code> and <code>stone</code>, so I get the following highlighted text:</p>
<pre><code>one
BONE
STONE
cuttleBONE
minestrone
cornerSTONE
</code></... | [
{
"answer_id": 8400,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": true,
"text": "<p>You need to escape the <code>|</code>:</p>\n\n<pre><code>/bone\\|stone\n</code></pre>\n\n<p>If you want to reuse the <code>... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8399",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3209/"
] | My file consists of the following text
```
one
bone
stone
cuttlebone
minestrone
cornerstone
```
and I want to select all instances of `bone` and `stone`, so I get the following highlighted text:
```
one
BONE
STONE
cuttleBONE
minestrone
cornerSTONE
```
NB: *capitals indicate highlighted text since I can't format i... | You need to escape the `|`:
```
/bone\|stone
```
If you want to reuse the `one` part, you can do:
```
/\(b\|st\)one
```
This create a sub expression `b\|st` and add `one` to it.
As DJ McMayhem suggested, you can use the `\v` "verymagic" flag:
```
/\v(b|st)one
``` |
8,405 | <p>Vim help's <a href="https://github.com/vim/vim/blob/master/runtime/doc/change.txt#L1171-L1180" rel="nofollow noreferrer"><code>change.txt</code></a> states that</p>
<blockquote>
<p>Note that after a characterwise yank command, Vim leaves the cursor on the
first yanked character that is closest to the start of t... | [
{
"answer_id": 8407,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 3,
"selected": true,
"text": "<p>Here's some vimscript I whipped up that seems to work pretty well. (<strong>disclaimer:</strong> I have not done exten... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8405",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5374/"
] | Vim help's [`change.txt`](https://github.com/vim/vim/blob/master/runtime/doc/change.txt#L1171-L1180) states that
>
> Note that after a characterwise yank command, Vim leaves the cursor on the
> first yanked character that is closest to the start of the buffer. This means
> that "yl" doesn't move the cursor, but "yh... | Here's some vimscript I whipped up that seems to work pretty well. (**disclaimer:** I have not done extensive testing on this. I just threw it together in a couple minutes)
```
function! YankNoMove()
let repcount = v:count
if v:count == 0
let repcount = 1
endif
exe "normal! m'".repcount."y".nr2char(getchar... |
8,406 | <p>I recently got to know that useful info can be shown in title of bash terminal when editing files using vim. Adding below displays file name, path of the file being edited.</p>
<pre><code>set title
</code></pre>
<p>But on exiting vim, the title is set to 'Thanks for flying vim'. I have different title set for each... | [
{
"answer_id": 8408,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>Use the <code>titleold</code> setting:</p>\n\n<pre><code>\" Update term title but restore old title after leaving Vim... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8406",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8092/"
] | I recently got to know that useful info can be shown in title of bash terminal when editing files using vim. Adding below displays file name, path of the file being edited.
```
set title
```
But on exiting vim, the title is set to 'Thanks for flying vim'. I have different title set for each bash terminal and would l... | Use the `titleold` setting:
```
" Update term title but restore old title after leaving Vim
set title
set titleold=
```
From [`:help 'titleold'`](http://vimhelp.appspot.com/options.txt.html#%27titleold%27):
>
> This option will be used for the window title when exiting Vim if the original title cannot be restored.... |
8,409 | <p>I am currently setting up my Vim to work with matlab. In matlab, sections are separated by <code>%%</code>, and I am looking for a command to select my current section. </p>
<p>I currently use </p>
<pre><code>nnoremap <Leader>f mf:?%%<CR><Down>v/%%<CR><Up>$:SlimuxREPLSendSelection<... | [
{
"answer_id": 8408,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>Use the <code>titleold</code> setting:</p>\n\n<pre><code>\" Update term title but restore old title after leaving Vim... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8409",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8152/"
] | I am currently setting up my Vim to work with matlab. In matlab, sections are separated by `%%`, and I am looking for a command to select my current section.
I currently use
```
nnoremap <Leader>f mf:?%%<CR><Down>v/%%<CR><Up>$:SlimuxREPLSendSelection<CR>`f
```
to mark the current position as f, search upwards for... | Use the `titleold` setting:
```
" Update term title but restore old title after leaving Vim
set title
set titleold=
```
From [`:help 'titleold'`](http://vimhelp.appspot.com/options.txt.html#%27titleold%27):
>
> This option will be used for the window title when exiting Vim if the original title cannot be restored.... |
8,412 | <p>Is there a way to preload a named register in vim? </p>
<p>For example: I would like to have an empty comment always available in register "c". This way I could insert it and quickly add the text.</p>
| [
{
"answer_id": 8413,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 3,
"selected": false,
"text": "<p>You can edit the contents of any register in vimscript by using \"@\" before the letter and then using it like a varia... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8412",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8138/"
] | Is there a way to preload a named register in vim?
For example: I would like to have an empty comment always available in register "c". This way I could insert it and quickly add the text. | You can edit the contents of any register in vimscript by using "@" before the letter and then using it like a variable.
```
let @c="Your text here."
``` |
8,415 | <p>I have a program that lists hostnames and IPs. Some hostnames have multiple IPs assigned to them. When I download the IP column .csv, it lists as such: </p>
<pre><code>192.168.xx.xx
"192.168.xx.xx, 192.168.xx.xx"
192.168.xx.xx
</code></pre>
<p>I am putting the contents of this .csv file into a VI file. What I woul... | [
{
"answer_id": 8416,
"author": "Antony",
"author_id": 7878,
"author_profile": "https://vi.stackexchange.com/users/7878",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the <code>:substitute</code> command for this:</p>\n\n<pre><code>:%s/\"//g | %s/, /\\r/g\n</code></pre>\n\n<p... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8415",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8154/"
] | I have a program that lists hostnames and IPs. Some hostnames have multiple IPs assigned to them. When I download the IP column .csv, it lists as such:
```
192.168.xx.xx
"192.168.xx.xx, 192.168.xx.xx"
192.168.xx.xx
```
I am putting the contents of this .csv file into a VI file. What I would like to do is figure out... | You can use the `:substitute` command for this:
```
:%s/"//g | %s/, /\r/g
```
First replace all quotation marks with nothing (I assume there will be no escaped `"`s since these are just IP addresses). Then (`|` is the command separator) replace all `', '` with linebreaks (`\r`).
References:
* [`:help :substitute`]... |
8,419 | <p>I have cursor at first <code>t</code> and I want to delete all this code from <code>t</code> to <code>};\n</code> without counting lines. How can I achieve it? Is there more cleaner way than <kbd>d</kbd><kbd>/</kbd><kbd>}</kbd><kbd>;</kbd><kbd>$</kbd><kbd>/</kbd><kbd>e</kbd>?</p>
<pre><code>tabControl.PropertyChang... | [
{
"answer_id": 8420,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 4,
"selected": true,
"text": "<p>I would have gone for <code>v<down>%<right>d</code>, or <code>vj%ld</code> if you're allergic to cursor ke... | 2016/06/23 | [
"https://vi.stackexchange.com/questions/8419",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8149/"
] | I have cursor at first `t` and I want to delete all this code from `t` to `};\n` without counting lines. How can I achieve it? Is there more cleaner way than `d``/``}``;``$``/``e`?
```
tabControl.PropertyChanged += (s, e) =>
{
...
};
```
If it matters, this is C#. | I would have gone for `v<down>%<right>d`, or `vj%ld` if you're allergic to cursor keys.
Thanks to `v` we can go into visual mode and from here, it looks like an interactive mode to select something on which a command will be applied.
Note: As Tumbler has indicated, you could also have used `V<down>%d` which will neat... |
8,433 | <p>I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press <code><</code> or <code>></code>, I leave visual mode whether I want to or not.</p>
<p>I would rather have it so I stay in visual mode, and keep my selection and cursor position intact.</p>
<p>How can I achi... | [
{
"answer_id": 8434,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 3,
"selected": false,
"text": "<p>I know this isn't an automatic solution, but you can accomplish this by using <code>gv</code> after the visual indent.... | 2016/06/24 | [
"https://vi.stackexchange.com/questions/8433",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press `<` or `>`, I leave visual mode whether I want to or not.
I would rather have it so I stay in visual mode, and keep my selection and cursor position intact.
How can I achieve this? | I have this in my vimrc:
```
"keep visual mode after indent
vnoremap > >gv
vnoremap < <gv
```
Note that you could also simply use `.` (dot) to repeat the last indent action. |
8,443 | <p>I'm writing a Fortran parallel code using MPI.
I mapped <code>ctrl-C</code> to run <code>make</code>, in order to compile the program with proper options and dependencies. I also mapped <code>ctrl-<</code> to run the program executing the command <code>mpirun -np 8 program</code>, but this is limiting, since it r... | [
{
"answer_id": 8444,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 3,
"selected": true,
"text": "<p>Try this:</p>\n\n<pre><code>function! Mpirn()\n let n = nr2char(getchar())\n exe \"!mpirun -np \".n.\" program\"\nen... | 2016/06/24 | [
"https://vi.stackexchange.com/questions/8443",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6498/"
] | I'm writing a Fortran parallel code using MPI.
I mapped `ctrl-C` to run `make`, in order to compile the program with proper options and dependencies. I also mapped `ctrl-<` to run the program executing the command `mpirun -np 8 program`, but this is limiting, since it runs the program on 8 processes. I would like to ma... | Try this:
```
function! Mpirn()
let n = nr2char(getchar())
exe "!mpirun -np ".n." program"
endfunction
nnoremap <C-c> :<C-u>call Mpirn()<cr>
```
(Note, I had trouble mapping to `<C-<>` so I left it mapped to `<C-c>` You can change this to whatever mapping you already have.)
Pretty straightforward answer. Takes... |
8,446 | <h2>Context</h2>
<p>I use <code>vifm</code> as my file manager (that's off topic here, i know, but keep reading) which allows me to edit filenames inside a <code>vim</code> buffer.</p>
<p>One issue i found myself annoyed at are numbered files where I want to keep leading zeros (e.g. <code>movie0001.webm</code>). I c... | [
{
"answer_id": 8449,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 4,
"selected": true,
"text": "<p>This can be done in two relatively simple steps:</p>\n\n<ol>\n<li>Decrement the lines with <code>ctrl-x</code></li>\n<li>... | 2016/06/24 | [
"https://vi.stackexchange.com/questions/8446",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7700/"
] | Context
-------
I use `vifm` as my file manager (that's off topic here, i know, but keep reading) which allows me to edit filenames inside a `vim` buffer.
One issue i found myself annoyed at are numbered files where I want to keep leading zeros (e.g. `movie0001.webm`). I can't get vim to format them properly.
The qu... | This can be done in two relatively simple steps:
1. Decrement the lines with `ctrl-x`
2. Run a substituion on the changed lines to add the leading zeros: `'[,']s/\d\@<!\d\>/0\0/`
You could turn that into a command/function if you think you'll need to do this often.
Another way is to do as muru mentioned and use `sub... |
8,451 | <p>That is, when you hit the marks operator key <kbd>`</kbd> or <kbd>'</kbd> you get a list of the available marks - i.e. the list vim gives from the ex command <code>:marks</code>. Then, when you press a letter to jump to the mark, you will be taken there - as usual. So if I want to jump to say mark <code>m</code>, wi... | [
{
"answer_id": 8453,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 5,
"selected": true,
"text": "<p>You can define a very simple custom mapping that lists the available marks and pre-populates the command-line with the right ... | 2016/06/25 | [
"https://vi.stackexchange.com/questions/8451",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4603/"
] | That is, when you hit the marks operator key ``` or `'` you get a list of the available marks - i.e. the list vim gives from the ex command `:marks`. Then, when you press a letter to jump to the mark, you will be taken there - as usual. So if I want to jump to say mark `m`, with the normal mode command ``m` you would t... | You can define a very simple custom mapping that lists the available marks and pre-populates the command-line with the right command stub, ready for you to type the desired mark name:
```
nnoremap <key> :<C-u>marks<CR>:normal! `
```
---
Note that this simply follows the same pattern as [that famous mapping](http://... |
8,467 | <p>I use the registers a lot for copy/pasting, but I always forgot in which register my content is.</p>
<p>Is there a way to display the registers before pasting?</p>
<p>Ideally it would leave the register on screen when selecting the one we want. </p>
| [
{
"answer_id": 8468,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": true,
"text": "<p>I made up this mapping to display the register list and select the one to be pasted:</p>\n\n<pre><code>nnoremap \"p :reg &l... | 2016/06/27 | [
"https://vi.stackexchange.com/questions/8467",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I use the registers a lot for copy/pasting, but I always forgot in which register my content is.
Is there a way to display the registers before pasting?
Ideally it would leave the register on screen when selecting the one we want. | I made up this mapping to display the register list and select the one to be pasted:
```
nnoremap "p :reg <bar> exec 'normal! "'.input('>').'p'<CR>
```
This display the register list with `:reg` and execute the normal command
```
"Xp
```
Where `X` is the result of `input()`. |
8,472 | <p>I have following code. I want to add spaces around =. With the minimal keystrokes (May be with the help of macro). Do not want search and replace approach.</p>
<pre><code><div className="row">
<div className="col-md-12 text-center">
<h3>vOrderv</h3>
</div>
</div>
... | [
{
"answer_id": 8474,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>Search and replace can be used, but I must admit, the syntax is not simple to remember:</p>\n\n<pre><code>:%s/\\s*=\\... | 2016/06/27 | [
"https://vi.stackexchange.com/questions/8472",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5890/"
] | I have following code. I want to add spaces around =. With the minimal keystrokes (May be with the help of macro). Do not want search and replace approach.
```
<div className="row">
<div className="col-md-12 text-center">
<h3>vOrderv</h3>
</div>
</div>
```
After changes it should look
```
<div class... | I'm not sure why you don't want to use search/replace, but here's a reusable command:
```
command! HTMLArgEq %s/\s\@<!=\+\s\@!/ \0 /g
```
It uses search/replace, but you only need to create it once. Explanation:
```
%s/ - Substitute entire buffer
\s\@<! - Not preceded by whitespace
=\+ - One or more equal cha... |
8,473 | <p>I recently noticed that on some help files it is not possible to move the cursor to the very first column of some lines. To explain it clearly, here is a screenshot where I have done the following:</p>
<ul>
<li><code>vim -u NONE</code></li>
<li><code>:h help</code></li>
<li><kbd>3j</kbd></li>
<li><kbd>0</kbd></li>
... | [
{
"answer_id": 8475,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": true,
"text": "<p>By default, the cursor is positioned on the last cell used to display a tab character.</p>\n\n<p>You can change that behavior... | 2016/06/27 | [
"https://vi.stackexchange.com/questions/8473",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | I recently noticed that on some help files it is not possible to move the cursor to the very first column of some lines. To explain it clearly, here is a screenshot where I have done the following:
* `vim -u NONE`
* `:h help`
* `3j`
* `0`
[](https://i.stac... | By default, the cursor is positioned on the last cell used to display a tab character.
You can change that behavior by enabling the `list` option and defining custom values for the `listchars` option (the default `^I` for tabs is not very practical):
```
set list
set listchars=tab:»\ ,extends:›,precedes:‹,nbsp:·,trai... |
8,480 | <p>I get a human readable list of api functions using</p>
<pre><code>:new|put =map(api_info().functions, 'v:val.name')
</code></pre>
<p>in neovim as suggested on <a href="https://neovim.io/doc/user/msgpack_rpc.html" rel="nofollow">https://neovim.io/doc/user/msgpack_rpc.html</a>.</p>
<p>Problem is, this doesn't show ... | [
{
"answer_id": 8483,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 3,
"selected": true,
"text": "<p>In Python 3, there's an emphasis on unicode strings. <code>sys.stdin</code> has a <code>buffer</code> attribute that let... | 2016/06/27 | [
"https://vi.stackexchange.com/questions/8480",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8156/"
] | I get a human readable list of api functions using
```
:new|put =map(api_info().functions, 'v:val.name')
```
in neovim as suggested on <https://neovim.io/doc/user/msgpack_rpc.html>.
Problem is, this doesn't show the method signatures like the perl example on <http://techblog.babyl.ca/entry/neovim-way-to-go>.
```
#... | In Python 3, there's an emphasis on unicode strings. `sys.stdin` has a `buffer` attribute that lets you get to the underlying byte buffer, but Python 2's `sys.stdin` does not. If you want something that'll work for both versions, you can use the `-u` command line argument, as well as `getattr()`:
```
nvim --api-info |... |
8,496 | <p>I have an autocommand function in my <code>.vimrc</code> that resets the cursor to where it was before I last closed the file. This function looks like this:</p>
<pre><code>function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction ... | [
{
"answer_id": 8498,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 4,
"selected": true,
"text": "<p>Since this should only work for existing files, you'll want to use <code>BufRead</code> instead of <code>BufWinEnter</cod... | 2016/06/28 | [
"https://vi.stackexchange.com/questions/8496",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5043/"
] | I have an autocommand function in my `.vimrc` that resets the cursor to where it was before I last closed the file. This function looks like this:
```
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
aut... | Since this should only work for existing files, you'll want to use `BufRead` instead of `BufWinEnter`. `vim-template` won't trigger `BufRead`.
If you really need `BufWinEnter` to be used to process modelines before calling your function, you can use `BufRead` to set a buffer variable:
```
autocmd BufRead * let b:not_... |
8,504 | <p>I have a file containing special comments in the following forms:</p>
<pre><code>// SPECIAL
// Some stuff
// Some other stuff
// Last line of other stuff
</code></pre>
<p>So I need to be able to delete the line containing <code>SPECIAL</code> and the 3 nexts. Assuming the <code>SPECIAL</code> does not appear in th... | [
{
"answer_id": 8505,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You could use the following command:</p>\n\n<pre><code>:g/SPECIAL/.,.+3d\n</code></pre>\n\n<p>Which can be detailled like ... | 2016/06/29 | [
"https://vi.stackexchange.com/questions/8504",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I have a file containing special comments in the following forms:
```
// SPECIAL
// Some stuff
// Some other stuff
// Last line of other stuff
```
So I need to be able to delete the line containing `SPECIAL` and the 3 nexts. Assuming the `SPECIAL` does not appear in the 3 lines after one `SPECIAL`.
I know I can sea... | You could use the following command:
```
:g/SPECIAL/.,.+3d
```
Which can be detailled like this:
```
:g/ Apply a command on all the lines matching a pattern
SPECIAL/ The pattern to match
.,.+3d The command to execute
.,.+3 Is a range. "." represent the current line (i.e. the matched one
It is upd... |
8,507 | <p>Let's say I have the following buffer:</p>
<pre><code>foo.txt
bar buzz.txt
fizz/foo.txt
fizz/fuzz/fozz.txt
</code></pre>
<p>Representing an arborescence that I need to create.</p>
<p>How can I easily create it from Vim? I.e. How can I visually select the list of
files and execute a function which would create th... | [
{
"answer_id": 8509,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "<p>You can take advantage of the way vim execute command when applied over a range.</p>\n\n<p>Select your lines and do:</p>\n... | 2016/06/29 | [
"https://vi.stackexchange.com/questions/8507",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | Let's say I have the following buffer:
```
foo.txt
bar buzz.txt
fizz/foo.txt
fizz/fuzz/fozz.txt
```
Representing an arborescence that I need to create.
How can I easily create it from Vim? I.e. How can I visually select the list of
files and execute a function which would create the directories and files in the
cur... | You can take advantage of the way vim execute command when applied over a range.
Select your lines and do:
```
:'<,'>call system('mkdir -p '. fnamemodify(fnameescape(getline('.')),':h:p').' && touch '.fnamemodify(fnameescape(getline('.')),':p'))
```
This will apply the command
```
call system(...)
```
over **eve... |
8,510 | <p>Is there any way to make the special symbol <code>%</code> work with path names on the command line? For instance, I'd like to do:</p>
<pre><code>:diffsplit Path\to\other\directory\%
</code></pre>
<p>So that I can do a <code>@:</code> to quickly compare files of the same name. However, this just opens up a new buf... | [
{
"answer_id": 8511,
"author": "Kent",
"author_id": 1569,
"author_profile": "https://vi.stackexchange.com/users/1569",
"pm_score": 0,
"selected": false,
"text": "<p>I don't know if this is ok for you:</p>\n\n<pre><code>:diffsplit Path/to/somewhere/<c-r>%\n</code></pre>\n\n<p>Just o... | 2016/06/29 | [
"https://vi.stackexchange.com/questions/8510",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6489/"
] | Is there any way to make the special symbol `%` work with path names on the command line? For instance, I'd like to do:
```
:diffsplit Path\to\other\directory\%
```
So that I can do a `@:` to quickly compare files of the same name. However, this just opens up a new buffer called `%`.
Of course I *could* do:
```
:... | So it turns out that it's a stupid Windows problem. The remedy to this is to simply use forward slashes in the path name. i.e. `:diffsplit Path/to/other/directory/%` works just fine.
I've remedied this on my system by using the option `set shellslash` which defaults to using forward slashes even on Windows. |
8,522 | <p>I have a text file like this:</p>
<pre><code>Line text,line text
next line
3rd line
Line x
</code></pre>
<p>where 2nd and 3rd, etc lines begin with a single space. I need to concatenate all lines prefixed with a space to the previous one without a space, so that the result looks like this:</p>
<pre><code>Line ... | [
{
"answer_id": 8523,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "<p>You can join lines with <code>J</code>. In your case:</p>\n\n<pre><code>3J\n</code></pre>\n\n<p>Will join your 3 lines.</p... | 2016/06/30 | [
"https://vi.stackexchange.com/questions/8522",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8239/"
] | I have a text file like this:
```
Line text,line text
next line
3rd line
Line x
```
where 2nd and 3rd, etc lines begin with a single space. I need to concatenate all lines prefixed with a space to the previous one without a space, so that the result looks like this:
```
Line text,line text next line 3rd line
Line... | You can replace the new lines plus space by a space:
```
:%s/\n\s/ /
```
This is an ex command i.e. a command used in the command line mode. To enter the command line mode, press `:`. Then insert the command which does the following:
```
% Apply the command on all the lines of the buffer
s/ The command... |
8,538 | <p>I'm trying to use vim-tmux-navigator. I'd like to use default key bindings to move between vim and tmux splits. Which is <code><C-W>hjkl</code>. </p>
<p>But it isn't working. Either you can't remap anything with <code>C-W</code> prefix or something else, I don't know. Is this possible?</p>
<p>I know that a l... | [
{
"answer_id": 8523,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "<p>You can join lines with <code>J</code>. In your case:</p>\n\n<pre><code>3J\n</code></pre>\n\n<p>Will join your 3 lines.</p... | 2016/07/01 | [
"https://vi.stackexchange.com/questions/8538",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6634/"
] | I'm trying to use vim-tmux-navigator. I'd like to use default key bindings to move between vim and tmux splits. Which is `<C-W>hjkl`.
But it isn't working. Either you can't remap anything with `C-W` prefix or something else, I don't know. Is this possible?
I know that a lot of people use `<C-l>` to switch between sp... | You can replace the new lines plus space by a space:
```
:%s/\n\s/ /
```
This is an ex command i.e. a command used in the command line mode. To enter the command line mode, press `:`. Then insert the command which does the following:
```
% Apply the command on all the lines of the buffer
s/ The command... |
8,542 | <p>I want to sort the following based on their keys</p>
<pre><code>case IndexError:
PyErr_SetString(PyExc_IndexError, exc.str.c_str());
break;
case ValueError:
PyErr_SetString(PyExc_ValueError, exc.str.c_str());
break;
case RuntimeError:
PyErr_SetString(PyExc_RuntimeError, exc.str.c_str());
bre... | [
{
"answer_id": 8546,
"author": "Sato Katsura",
"author_id": 2313,
"author_profile": "https://vi.stackexchange.com/users/2313",
"pm_score": 4,
"selected": true,
"text": "<p>The easy way: join the lines in the logical blocks before sorting.</p>\n\n<p>In detail:</p>\n\n<ul>\n<li>mark the li... | 2016/07/01 | [
"https://vi.stackexchange.com/questions/8542",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8259/"
] | I want to sort the following based on their keys
```
case IndexError:
PyErr_SetString(PyExc_IndexError, exc.str.c_str());
break;
case ValueError:
PyErr_SetString(PyExc_ValueError, exc.str.c_str());
break;
case RuntimeError:
PyErr_SetString(PyExc_RuntimeError, exc.str.c_str());
break;
case IOErr... | The easy way: join the lines in the logical blocks before sorting.
In detail:
* mark the lines
* join the indented lines to the lines above: `:'<,'>s/\n /^A/`
* mark the lines again: `gv`
* sort them: `:'<,'>sort`
* mark the lines one more time: `gv`
* split the lines back and restore indentation: `:'<,'>s/^A/\r /g`
... |
8,559 | <p>I use four spaces for indent. I would like to replace the indentation with some UTF-8 chars.</p>
<p>What I have:</p>
<p>1.</p>
<pre><code>def foo(bar):
for jaffa in bar:
print jaffa
</code></pre>
<p>2.</p>
<pre><code>var foo = function(bar){
bar.forEach(function(jaffa){
console.log(jaffa... | [
{
"answer_id": 8560,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": false,
"text": "<p>This could be used <code>call matchadd('Conceal', '\\s\\{'.&ts.'\\}', 10, -1, {'conceal': '►'})</code></p>\n\... | 2016/07/03 | [
"https://vi.stackexchange.com/questions/8559",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8271/"
] | I use four spaces for indent. I would like to replace the indentation with some UTF-8 chars.
What I have:
1.
```
def foo(bar):
for jaffa in bar:
print jaffa
```
2.
```
var foo = function(bar){
bar.forEach(function(jaffa){
console.log(jaffa);
});
}
```
What I want:
1.
```
def foo(ba... | With the following:
```
set conceallevel=2
syn match IndentWS '\v(^( {4}|\t)*)@<=( {4}|\t)' conceal cchar=▶
```
I get:
[](https://i.stack.imgur.com/NfljX.png)
The regex `\v(^( {4}|\t)*)@<=( {4}|\t)`:
* uses [very magic](http://vimhelp.appspot.com... |
8,563 | <p>I put the following lines from <a href="http://vim.wikia.com/wiki/Highlight_unwanted_spaces" rel="nofollow">this page</a> into my <code>~/.vimrc</code> to highlight trailing whitespace in red:</p>
<pre><code>highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match Ex... | [
{
"answer_id": 8564,
"author": "grochmal",
"author_id": 7700,
"author_profile": "https://vi.stackexchange.com/users/7700",
"pm_score": 3,
"selected": true,
"text": "<h3>Extraneous <code>autocmd</code></h3>\n\n<p>First, you told Vim to call your toggle function every time you enter or lea... | 2016/07/03 | [
"https://vi.stackexchange.com/questions/8563",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5043/"
] | I put the following lines from [this page](http://vim.wikia.com/wiki/Highlight_unwanted_spaces) into my `~/.vimrc` to highlight trailing whitespace in red:
```
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match E... | ### Extraneous `autocmd`
First, you told Vim to call your toggle function every time you enter or leave the insert mode. i.e. by using the `InsertEnter` and `InsertLeave` events as follows:
```
autocmd InsertEnter * call ToggleHighlightWhitespace()
autocmd InsertLeave * call ToggleHighlightWhitespace()
```
Those ev... |
8,569 | <p>Currently I’m adding source sections manually, e.g.:</p>
<pre><code>/*******************************************************************************
* entry point
******************************************************************************/
fn main () { println!("Hello World!"); }... | [
{
"answer_id": 8570,
"author": "Rainymood",
"author_id": 5319,
"author_profile": "https://vi.stackexchange.com/users/5319",
"pm_score": 3,
"selected": false,
"text": "<p>I actually wrote a blog post about this: </p>\n\n<p><a href=\"http://rainymood.github.io/jekyll/update/2016/06/25/vim-... | 2016/07/04 | [
"https://vi.stackexchange.com/questions/8569",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8282/"
] | Currently I’m adding source sections manually, e.g.:
```
/*******************************************************************************
* entry point
******************************************************************************/
fn main () { println!("Hello World!"); }
```
The com... | I actually wrote a blog post about this:
<http://rainymood.github.io/jekyll/update/2016/06/25/vim-macro.html>
tl;dr use a Vim Macro
Macro used for the image below
```
qai###<Esc>A<Esc><Space>###<Esc>YppkkVR#jjVR#q
```
[](https://i.stack.imgur.com/0S3ta.gif)
You could... |
8,574 | <p>I have tried to attach to following fugitive mapping:</p>
<pre><code>nnoremap <buffer> <silent> D :<C-U>execute <SID>StageDiff('Gdiff')<CR>
</code></pre>
<p>a <code>:h window-move-cursor</code> mapping:</p>
<pre class="lang-diff prettyprint-override"><code>diff --git a/plugin/fugitiv... | [
{
"answer_id": 8587,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 2,
"selected": false,
"text": "<p>Here is what I came up with to put in your <code>~/.vimrc</code>:</p>\n\n<pre class=\"lang-vim prettyprint-override\... | 2016/07/05 | [
"https://vi.stackexchange.com/questions/8574",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1292/"
] | I have tried to attach to following fugitive mapping:
```
nnoremap <buffer> <silent> D :<C-U>execute <SID>StageDiff('Gdiff')<CR>
```
a `:h window-move-cursor` mapping:
```diff
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
index 805518a..897295a 100644
--- a/plugin/fugitive.vim
+++ b/plugin/fugitive.vim
@@ ... | Based on the answer by Peter Rincker.
Using `feedkeys` works in contrast to attaching the mapping `\<C-w>P` via `<Bar> normal`.
Problem with the answer by Peter Rincker:
Fugitive defines mappings on the fly based on different events which override occasionally the mappings set up by the event `BufEnter`. I couldn'... |
8,602 | <p>99% of the time when I am opening a diff (using the <code>:diffsplit</code> command), it's because I want to reference some code, but still edit the file I started in. However, whenever you open a diff with diffsplit, the new file gets focus. I'd like to make vim automatically switch back (Or not switch in the first... | [
{
"answer_id": 8606,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You could add this to your <code>.vimrc</code>:</p>\n\n<pre><code>command! -nargs=1 -complete=file Diffsplit diffsplit <... | 2016/07/06 | [
"https://vi.stackexchange.com/questions/8602",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6489/"
] | 99% of the time when I am opening a diff (using the `:diffsplit` command), it's because I want to reference some code, but still edit the file I started in. However, whenever you open a diff with diffsplit, the new file gets focus. I'd like to make vim automatically switch back (Or not switch in the first place if that... | You could add this to your `.vimrc`:
```
command! -nargs=1 -complete=file Diffsplit diffsplit <args> | wincmd p
```
This create a `Diffsplit` command (note the capitalized `D`) which takes one argument and accept file names as completion.
The command will create the diffsplit with the argument provided and use the ... |
8,607 | <p>I'm having a hard time understanding how the ANSI colors affect the named colors in Vim. My KiTTY terminal has "regular" and "bold" versions for the main 8 colors, plus foreground/background colors. How are these assigned to the representations of DarkGray, etc. often used to define Vim colorschemes? When I checked ... | [
{
"answer_id": 8606,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You could add this to your <code>.vimrc</code>:</p>\n\n<pre><code>command! -nargs=1 -complete=file Diffsplit diffsplit <... | 2016/07/06 | [
"https://vi.stackexchange.com/questions/8607",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8084/"
] | I'm having a hard time understanding how the ANSI colors affect the named colors in Vim. My KiTTY terminal has "regular" and "bold" versions for the main 8 colors, plus foreground/background colors. How are these assigned to the representations of DarkGray, etc. often used to define Vim colorschemes? When I checked wit... | You could add this to your `.vimrc`:
```
command! -nargs=1 -complete=file Diffsplit diffsplit <args> | wincmd p
```
This create a `Diffsplit` command (note the capitalized `D`) which takes one argument and accept file names as completion.
The command will create the diffsplit with the argument provided and use the ... |
8,617 | <p>I cannot figure out how to open a file that starts with <code>+</code>, e.g. <code>+models/File.m</code>. This is a naming convention for packages in Matlab.</p>
<p>I've tried escaping <code>\+models/File.m</code>. This doesn't work because the backslash is interpreted by the shell. Double escaping <code>\\+model... | [
{
"answer_id": 8619,
"author": "SibiCoder",
"author_id": 7161,
"author_profile": "https://vi.stackexchange.com/users/7161",
"pm_score": 2,
"selected": false,
"text": "<p>You can open <code>vim</code> without any arguments.\nAnd then, in command line, type <code>:e! \\+filename</code></p>... | 2016/07/07 | [
"https://vi.stackexchange.com/questions/8617",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8113/"
] | I cannot figure out how to open a file that starts with `+`, e.g. `+models/File.m`. This is a naming convention for packages in Matlab.
I've tried escaping `\+models/File.m`. This doesn't work because the backslash is interpreted by the shell. Double escaping `\\+models/File.m` allows vim to receive the backslash, but... | From `vim --help:`
```
Arguments:
-- Only file names after this
...
```
So this works on the command line:
```
vim -- +models/File.m
```
From inside Vim you need to escape the `+`:
```
:e \+models/File.m
``` |
8,621 | <p>I have a list of files:</p>
<pre><code>./a.temp.txt ./a.temp.txt
./a/b.temp.txt ./a/b.temp.txt
./a/b/c.temp.txt ./a/b/c.temp.txt
</code></pre>
<p>And I want to remove the <code>temp.</code> on each line, but only the <strong>second occurence</strong>, thus, the file should look like:</p>
<pre><code>./a.temp... | [
{
"answer_id": 8622,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>I'd write a macro with the cursor starting at the top left.\n<code>qq4f.dfpq</code></p>\n\n<p>Then I'd select the rest of ... | 2016/07/07 | [
"https://vi.stackexchange.com/questions/8621",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I have a list of files:
```
./a.temp.txt ./a.temp.txt
./a/b.temp.txt ./a/b.temp.txt
./a/b/c.temp.txt ./a/b/c.temp.txt
```
And I want to remove the `temp.` on each line, but only the **second occurence**, thus, the file should look like:
```
./a.temp.txt ./a.txt
./a/b.temp.txt ./a/b.txt
./a/b/c.temp.txt ... | In general you can match the Nth occurrence of something
using `\zs` and `\{N}`. There's an example given at `:help \zs`.
In your case the command would be:
```
:%s/\(.\{-}\zstemp\.\)\{2}//
``` |
8,625 | <p>I want to insert text like this:</p>
<pre><code>similar text wordA similar text ...
similar text wordB similar text ...
similar text wordC similar text ...
</code></pre>
<p>I know I can paste the text many times then use the substitution to change single word for each line, however I still find this method very in... | [
{
"answer_id": 8626,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>You can use the following function:</p>\n\n<pre><code>function! GenerateLines()\n let firstpart=\"similar text part 1\... | 2016/07/07 | [
"https://vi.stackexchange.com/questions/8625",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8325/"
] | I want to insert text like this:
```
similar text wordA similar text ...
similar text wordB similar text ...
similar text wordC similar text ...
```
I know I can paste the text many times then use the substitution to change single word for each line, however I still find this method very inconvenient.
Is there a wa... | You can use the following function:
```
function! GenerateLines()
let firstpart="similar text part 1"
let secondpart="similar text part 2"
let words=["wordA","wordB","wordC","wordD","wordE"]
for word in words
let line = firstpart . word . secondpart
call append(line('.')+1, line)
... |
8,628 | <p>A common task I run into is having to change the order of arguments. So, for example, I might have something like this:</p>
<pre><code>stringInsert( "text to insert", buffer );
</code></pre>
<p>and need to change it into this:</p>
<pre><code>stringInsert( buffer, "text to insert" );
</code></pre>
<p>Typically th... | [
{
"answer_id": 8634,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>You can try to put this function in your <code>.vimrc</code>:</p>\n\n<pre><code>function! InvertArgs()\n \" Get the ar... | 2016/07/07 | [
"https://vi.stackexchange.com/questions/8628",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | A common task I run into is having to change the order of arguments. So, for example, I might have something like this:
```
stringInsert( "text to insert", buffer );
```
and need to change it into this:
```
stringInsert( buffer, "text to insert" );
```
Typically the way I do this is:
1. `da"` (or whatever is req... | You can try to put this function in your `.vimrc`:
```
function! InvertArgs()
" Get the arguments of the current line (remove the spaces)
let args=substitute(matchstr(getline('.'), '(\zs.*\ze)'), '\s', '', 'g')
" Split the arguments as a list and reverse the list
let argsList=split(args, ',')
call... |
8,630 | <p>Sometimes I need to replace <code>.</code> with <code>-></code> when fixing code.</p>
<p>Usually search and replace cannot be used because there will be many (hundreds of) dots (<code>.</code>) and only a few ones of them must be changed. </p>
<p>However, I find the ones that need to be changed when I am going ... | [
{
"answer_id": 8631,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 4,
"selected": false,
"text": "<p>You could use the <code>s</code> operator, which deletes the character under your cursor and puts you in insert mode. ... | 2016/07/07 | [
"https://vi.stackexchange.com/questions/8630",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | Sometimes I need to replace `.` with `->` when fixing code.
Usually search and replace cannot be used because there will be many (hundreds of) dots (`.`) and only a few ones of them must be changed.
However, I find the ones that need to be changed when I am going through a make *changelist*.
Using the repetition op... | The cw(change word) command will solve your problem.
Put your cursor on the period and type `cw-><Escape>`
>
> something.somethingelse
>
>
>
turns into
>
> something->somethingelse
>
>
>
and the `.` operator will still work, because cw is one operation that does both the deletion and substitution. |
8,648 | <p>Is there a key binding to change a single character, i.e., delete character and enter insert mode? This would be analogous to <code>cw</code> (change word). For example, <code>cx</code> would seem to be logical.</p>
<p>Obviously a macro can be created to do this: </p>
<pre><code>qx`xi`q
</code></pre>
<p>... but a... | [
{
"answer_id": 8651,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>Yup it's <code>s</code> in normal mode. See <a href=\"http://vimdoc.sourceforge.net/htmldoc/change.html#s\"><code>:h s</c... | 2016/07/07 | [
"https://vi.stackexchange.com/questions/8648",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | Is there a key binding to change a single character, i.e., delete character and enter insert mode? This would be analogous to `cw` (change word). For example, `cx` would seem to be logical.
Obviously a macro can be created to do this:
```
qx`xi`q
```
... but a two character macro does not have much logic. | Yup it's `s` in normal mode. See [`:h s`](http://vimdoc.sourceforge.net/htmldoc/change.html#s):
```
["x]s Delete [count] characters [into register x] and start
insert (s stands for Substitute). Synonym for "cl"
(not linewise).
``` |
8,670 | <p>By default, Vim will fold everything it can if folding is enabled. This can be useful from big complicated files, but it tends to get in the way for smaller, simpler files.</p>
<p>For example, if I open a code file that contains just one class, it makes no sense to have that class folded.</p>
<p>I think a reasonab... | [
{
"answer_id": 8671,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": true,
"text": "<p>You can use the <code>line()</code> function to fold or unfold your file:</p>\n\n<pre><code>\" In your vimrc\n\nif line('$'... | 2016/07/08 | [
"https://vi.stackexchange.com/questions/8670",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8349/"
] | By default, Vim will fold everything it can if folding is enabled. This can be useful from big complicated files, but it tends to get in the way for smaller, simpler files.
For example, if I open a code file that contains just one class, it makes no sense to have that class folded.
I think a reasonable metric for whe... | You can use the `line()` function to fold or unfold your file:
```
" In your vimrc
if line('$') > 20
set foldlevel = 1
endif
```
`line('$')` returns the line number of the last (`$`) line of your document.
Of course, this is executed only when you are launching Vim, so you can use a autocommand like so:
```
au... |
8,674 | <p>From <a href="http://vimhelp.appspot.com/options.txt.html#%3Aset" rel="noreferrer"><code>:h :set</code></a> we
know that</p>
<blockquote>
<p><code>:se[t]</code> Show all options that differ from their default value.</p>
</blockquote>
<p>In a vimscript I'd like to save all these options which have been modif... | [
{
"answer_id": 8678,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 2,
"selected": false,
"text": "<p>You can access a setting's value using <code>let option_val = &option</code> in a script. What I've seen done is us... | 2016/07/08 | [
"https://vi.stackexchange.com/questions/8674",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | From [`:h :set`](http://vimhelp.appspot.com/options.txt.html#%3Aset) we
know that
>
> `:se[t]` Show all options that differ from their default value.
>
>
>
In a vimscript I'd like to save all these options which have been modified by
the user, modify them and later restore them to the value set by the user.
How ... | **1. `:mkexrc`**
The easiest way is to use `:mkexrc` command. With this command, we can save all changed options into a file. When you need to restore back all the saved options from the file, just`:source` it.
```
mkexrc snapshot
source snapshot
```
**2. `:set` and `:redir`**
The `:mkexrc` command necessarily us... |
8,680 | <p>Let's say I do a simple shell command like <code>ls</code>. Is there some way to directly pipe the output into a new vim buffer, so that I could edit it in place or just have a look at it. </p>
<p>Basically like <code>less</code> + the ability to edit it and directly save it in some place on the system?</p>
| [
{
"answer_id": 8681,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 3,
"selected": false,
"text": "<p>You can do this from directly inside of vim with the <code>:read</code> command, which is abbreviated to <code>:r</co... | 2016/07/08 | [
"https://vi.stackexchange.com/questions/8680",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6300/"
] | Let's say I do a simple shell command like `ls`. Is there some way to directly pipe the output into a new vim buffer, so that I could edit it in place or just have a look at it.
Basically like `less` + the ability to edit it and directly save it in some place on the system? | You can do this from directly inside of vim with the `:read` command, which is abbreviated to `:r` The 'read' command is intended to allow you to read a file, e.g.
```
:r foo.txt
```
Will insert the contents of `foo.txt` after your current cursor position.
From `:help :r`
```
*:r* *:r... |
8,685 | <p>I've enabled <code>set nowrap</code> since I find that line wrapping makes it harder for me to quickly scan a document. It's also annoying having to scroll right to see the entire line that I am working on.</p>
<p>I'm wondering if there's a way to enable line-wrapping only on the line that my cursor is currently on... | [
{
"answer_id": 8686,
"author": "Durga Swaroop",
"author_id": 5481,
"author_profile": "https://vi.stackexchange.com/users/5481",
"pm_score": 1,
"selected": false,
"text": "<p>I don't think setting the line-wrapping for just a single line is possible. \nBut, there is a small work around th... | 2016/07/08 | [
"https://vi.stackexchange.com/questions/8685",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6420/"
] | I've enabled `set nowrap` since I find that line wrapping makes it harder for me to quickly scan a document. It's also annoying having to scroll right to see the entire line that I am working on.
I'm wondering if there's a way to enable line-wrapping only on the line that my cursor is currently on and exclude all othe... | I was thinking about this more. You can't wrap just the current line in the current window, but you can open the buffer in a new window and enable wrapping there without affecting your current window.
Use a new window
----------------
```
split | setlocal wrap
```
After you're done, close the window that has wrappi... |
8,692 | <p>I mapped <code>zz</code> to <code>1z=</code>, which is great most of the time, but every now and then the first suggestion isn't the right one.</p>
<p>So I'd like to keep repeating <code>zz</code> (or <code>.</code>) to cycle through the other suggestions.</p>
<p>A second <code>zz</code> on the same word, then, wo... | [
{
"answer_id": 8699,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "<p>As @statox suggested, you can use the plugin I wrote: <a href=\"https://github.com/nobe4/vimcorrect\" rel=\"nofollow noref... | 2016/07/09 | [
"https://vi.stackexchange.com/questions/8692",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7642/"
] | I mapped `zz` to `1z=`, which is great most of the time, but every now and then the first suggestion isn't the right one.
So I'd like to keep repeating `zz` (or `.`) to cycle through the other suggestions.
A second `zz` on the same word, then, would work like `u2z=`, a third `zz` would work like `u3z=` and so on.
An... | Here's what I came up with:
Spell Rotate
============
[](https://i.stack.imgur.com/vE9sM.gif)
Features
--------
* The `'[` and `']` marks are used to keep track of the text being worked on. Making a change elsewhere will effectively "accept" the suggested change.
... |
8,696 | <p>I've got this 4-line content:</p>
<pre><code>foo
baa
baz
quz
</code></pre>
<p>and I'd like to replace <code>baa</code> to <code>bar</code> only when <code>quz</code> is found.</p>
<p>I've tried these commands (which highlights <code>baa</code> correctly, but says it's not found):</p>
<pre><code>:/quz/s/baa/bar/
... | [
{
"answer_id": 8697,
"author": "kenorb",
"author_id": 467,
"author_profile": "https://vi.stackexchange.com/users/467",
"pm_score": 2,
"selected": false,
"text": "<p>Ok, it was very close and this actually worked:</p>\n\n<pre><code>:/baa/,/quz/s/baa/bar/\n</code></pre>\n"
},
{
"an... | 2016/07/09 | [
"https://vi.stackexchange.com/questions/8696",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I've got this 4-line content:
```
foo
baa
baz
quz
```
and I'd like to replace `baa` to `bar` only when `quz` is found.
I've tried these commands (which highlights `baa` correctly, but says it's not found):
```
:/quz/s/baa/bar/
:/quz/1,$s@baa@bar@
```
>
> E486: Pattern not found: baa
>
>
>
and this:
```
:/q... | `:/baa/,/quz/s/baa/bar/` works, but that will only work with the first occurrence of `baa`. If you want to replace all occurrences of `baa` with `bar` that come before `quz`:
```
,/quz/s/baa/bar
```
If your scenario calls for replacing all occurrences of `baa` if `quz` is found:
```
/quz/,%s/baa/bar
```
That wil... |
8,709 | <p>I am writing a plugin which needs to have two windows displayed at the same time:</p>
<pre><code> _______
| | |
| A | B |
|___|___|
</code></pre>
<p>I need to keep in memory a reference to those windows as I execute my plugin. This is because I need to be able to jump between the two windows automaticaly.</p>
... | [
{
"answer_id": 8711,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 2,
"selected": false,
"text": "<p>You can't store a window number reliably because it changes every time a window is created and destroyed. You can use <... | 2016/07/10 | [
"https://vi.stackexchange.com/questions/8709",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I am writing a plugin which needs to have two windows displayed at the same time:
```
_______
| | |
| A | B |
|___|___|
```
I need to keep in memory a reference to those windows as I execute my plugin. This is because I need to be able to jump between the two windows automaticaly.
I use the `winnr()` function ... | I think what you are looking for is the function `win_getid()` combined to the
function `win_gotoid()`.
[`:h win_getid()`](http://vimdoc.sourceforge.net/htmldoc/eval.html#win_getid())
says:
>
> win\_getid([{win} [, {tab}]])
>
>
>
> Get the window ID for the specified window.
>
> When {win} is missing use th... |
8,710 | <p><strong>How do I attach a callback to <code>:NeomakeProject</code> so that <code>:cwindow</code> is executed after compilation finishes?</strong></p>
<p>i.e. I'm too lazy and want everything (open the error list) to happen automatically. (currently I'm opening :cwindow with a shortcut)</p>
<p><code>/callback</code... | [
{
"answer_id": 8712,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 2,
"selected": false,
"text": "<p>I don't know first hand if it works with your fork but the following snippets works perfectly in real Vim:</p>\n\n<pre><code... | 2016/07/10 | [
"https://vi.stackexchange.com/questions/8710",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3280/"
] | **How do I attach a callback to `:NeomakeProject` so that `:cwindow` is executed after compilation finishes?**
i.e. I'm too lazy and want everything (open the error list) to happen automatically. (currently I'm opening :cwindow with a shortcut)
`/callback` in `:help neomake` shows that `neomake#Make()` accepts a call... | [Neomake runs a user autocmd called `NeomakeFinished` when it's done.](https://github.com/neomake/neomake/blob/310a86903200f343117425fd82fe61ae2c8a83d5/doc/neomake.txt#L380-L403) It sets the context variable: `g:neomake_hook_context.file_mode`. If it's `1` it's using the location list.
If you only want it to run when ... |
8,715 | <p>Given this command:</p>
<pre><code>ex -sc '%!alfa' -cx file
</code></pre>
<p>I get this result:</p>
<pre><code>sh: alfa: command not found
</code></pre>
<p>which is to be expected. However an unintended side effect of this is that the
file is emptied and saved.</p>
<p>Can this command be modified so that if the... | [
{
"answer_id": 25278,
"author": "Zombo",
"author_id": 7184,
"author_profile": "https://vi.stackexchange.com/users/7184",
"pm_score": 0,
"selected": false,
"text": "<p>As a workaround, I am now using the shell builtin <code>type alfa</code> before the Vim call.</p>\n"
},
{
"answer... | 2016/07/10 | [
"https://vi.stackexchange.com/questions/8715",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | Given this command:
```
ex -sc '%!alfa' -cx file
```
I get this result:
```
sh: alfa: command not found
```
which is to be expected. However an unintended side effect of this is that the
file is emptied and saved.
Can this command be modified so that if the external command is not found, then
Vim bails instead o... | You can use [`v:shell_error`](https://vimhelp.org/eval.txt.html#v%3Ashell_error) to test whether the external command succeeded or failed. Typically a non-zero result means the command failed.
In that case, you can use `:q!` to exit the Ex script with the file unmodified. Or, perhaps better, use the [`:cq!`](https://v... |
8,718 | <p>I want my C code indented as follows:</p>
<pre><code>switch (x)
{
case 1:
break;
case 2:
{
break;
}
}
</code></pre>
<p>Instead of this:</p>
<pre><code>switch (x)
{
case 1:
break;
case 2:
{
break;
}
}
</code></pre>
<p>I looked through cin... | [
{
"answer_id": 8722,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "<p>I don't think it's possible <em>as is</em>, you can work around that though.</p>\n\n<hr>\n\n<p>For your current example yo... | 2016/07/11 | [
"https://vi.stackexchange.com/questions/8718",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8385/"
] | I want my C code indented as follows:
```
switch (x)
{
case 1:
break;
case 2:
{
break;
}
}
```
Instead of this:
```
switch (x)
{
case 1:
break;
case 2:
{
break;
}
}
```
I looked through cinoptions, but didn't find what I need. I'm looking... | I finally came up with a solution with custom indent script:
```
setlocal comments=s1:/*,mb:*,ex:*/
setlocal cindent
setlocal cinoptions=Ls,t0,(0
setlocal indentexpr=GetCaseBlockCorrectedIndent()
setlocal indentkeys=!^F,0{,0},0),0#,o,O,e,:
function! s:PrevNonBlankOrComment(startlnum)
let lnum = a:startlnum
... |
8,726 | <p>I have a file that looks like this:</p>
<pre><code># Section 1
#
# new: a.txt
# new: b.txt
#
#
# Section 2
#
# [n]ew: c.txt
# new: d.txt
# new: e.txt
#
</code></pre>
<p>My cursor is on the first <code>new</code> of the second section and I want to select all the "paragraph", i.e. the 3 <code>new</code> lines start... | [
{
"answer_id": 8727,
"author": "DoYouEvenCodeBro",
"author_id": 2757,
"author_profile": "https://vi.stackexchange.com/users/2757",
"pm_score": 1,
"selected": false,
"text": "<p>Unfortunately, vim doesn't yet support custom-defined paragraphs (from :h todo). </p>\n\n<blockquote>\n <ul>\n... | 2016/07/11 | [
"https://vi.stackexchange.com/questions/8726",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I have a file that looks like this:
```
# Section 1
#
# new: a.txt
# new: b.txt
#
#
# Section 2
#
# [n]ew: c.txt
# new: d.txt
# new: e.txt
#
```
My cursor is on the first `new` of the second section and I want to select all the "paragraph", i.e. the 3 `new` lines starting at this one. But because the paragraph is de... | Using Kana Natsuno's [textobj-user](https://github.com/kana/vim-textobj-user): install [textobj-user](https://github.com/kana/vim-textobj-user), then put the following in a file `textobj-comment-lines/plugin/textobj/comment_lines.vim`:
```
if exists('g:loaded_textobj_comment_lines')
finish
endif
let g:loaded_texto... |
8,729 | <p>I am using git 2.7.0.windows.1 in Windows 10, with <code>core.editor</code> set to <code>vim</code>.</p>
<p>Vim was downloaded from vim.org latest version binary:
VIM - Vi IMproved 7.4.1023 (2013 Aug 10, compiled Jan 2 2016 14:24:35)
MS-Windows 32-bit console version</p>
<p>When I do a git commit in a <code>cmd</... | [
{
"answer_id": 9551,
"author": "martin jakubik",
"author_id": 9272,
"author_profile": "https://vi.stackexchange.com/users/9272",
"pm_score": 1,
"selected": false,
"text": "<p>There's a nice option called background.</p>\n<p>From my .vimrc:</p>\n<pre><code>" sets dark background for ... | 2016/07/11 | [
"https://vi.stackexchange.com/questions/8729",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8393/"
] | I am using git 2.7.0.windows.1 in Windows 10, with `core.editor` set to `vim`.
Vim was downloaded from vim.org latest version binary:
VIM - Vi IMproved 7.4.1023 (2013 Aug 10, compiled Jan 2 2016 14:24:35)
MS-Windows 32-bit console version
When I do a git commit in a `cmd` window, it goes into a vim right in the comma... | There's a nice option called background.
From my .vimrc:
```
" sets dark background for terminal
set background=dark
```
This will tell vim that you have a dark background, and therefore it should make the text light.
In vim, type `:help 'background'` to see the doc for this option. |
8,733 | <p>I need to be break it to you guys, I use <code>emacs</code>. But just for one little thing.</p>
<p>Recently I've been working with a good deal of Japanese people (the company is Japanese) and I got some idea of the language, moreover sometimes I need to write something in Japanese. I do not have a Japanese keyboa... | [
{
"answer_id": 8792,
"author": "grochmal",
"author_id": 7700,
"author_profile": "https://vi.stackexchange.com/users/7700",
"pm_score": 4,
"selected": true,
"text": "<p>OK, this took several days of struggle against the <a href=\"https://github.com/tyru/skk.vim\" rel=\"noreferrer\"><code>... | 2016/07/11 | [
"https://vi.stackexchange.com/questions/8733",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7700/"
] | I need to be break it to you guys, I use `emacs`. But just for one little thing.
Recently I've been working with a good deal of Japanese people (the company is Japanese) and I got some idea of the language, moreover sometimes I need to write something in Japanese. I do not have a Japanese keyboard and I need to conver... | OK, this took several days of struggle against the [`skk.vim` plugin](https://github.com/tyru/skk.vim) mentioned by @SatoKatsura. All the documentation is in Japanese therefore I still do not know of most of its features, and, certainly, there are better ways to accomplish SKK conversion ("Henkan" in Japanese) in Vim t... |
8,741 | <p>I love the "hlsearch" setting, but after I'm done searching, I find it obnoxious. Especially if I search for something that has a lot of matches. I know that I can turn this off with </p>
<pre><code>:set nohlsearch
</code></pre>
<p>But this takes a whole 16 keystrokes, and even more annoyingly, I have to turn it b... | [
{
"answer_id": 8742,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 5,
"selected": false,
"text": "<p>There is a much more convenient way. Rather than using </p>\n\n<pre><code>:set nohlsearch\n</code></pre>\n\n<p>which ... | 2016/07/12 | [
"https://vi.stackexchange.com/questions/8741",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2920/"
] | I love the "hlsearch" setting, but after I'm done searching, I find it obnoxious. Especially if I search for something that has a lot of matches. I know that I can turn this off with
```
:set nohlsearch
```
But this takes a whole 16 keystrokes, and even more annoyingly, I have to turn it back on for my next search ... | There is a much more convenient way. Rather than using
```
:set nohlsearch
```
which actually turns the hlsearch setting off, use
```
:nohls
```
This will only turn hlsearch off until you search again. From `:help nohls`
```
*'hlsearch'* *'hls'* *'nohlsearch'* *'nohls'*
'hlsearch' 'hls' bool... |
8,751 | <h1>Original post</h1>
<p>I've got a colorscheme configured in my .vimrc but sometimes I'd like to turn it off completely which means that I would like Vim to use the default background and foreground colors of my terminal.</p>
<p>My problem is that I don't know how to easily do it. When I use <code>:syntax off</code... | [
{
"answer_id": 8755,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<h2>Disabling Colours Entirely</h2>\n<p>If you want Vim not to use colours at <em>all</em>, you just need to run the command:</p>... | 2016/07/13 | [
"https://vi.stackexchange.com/questions/8751",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6043/"
] | Original post
=============
I've got a colorscheme configured in my .vimrc but sometimes I'd like to turn it off completely which means that I would like Vim to use the default background and foreground colors of my terminal.
My problem is that I don't know how to easily do it. When I use `:syntax off` Vim turns off ... | Disabling Colours Entirely
--------------------------
If you want Vim not to use colours at *all*, you just need to run the command:
```
:set t_Co=0
```
This tells Vim that it is running in a terminal that does not support colours, so Vim will only output black and white text (which will then be displayed by your t... |
8,754 | <p>I would like to easily transform these two lines : </p>
<blockquote>
<p>One line.<br>
long line with many words in this example</p>
</blockquote>
<p>into the line :</p>
<blockquote>
<p>One long line with many words in this example line.</p>
</blockquote>
<p>How I currently do it :</p>
<ul>
<li>place curso... | [
{
"answer_id": 8755,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<h2>Disabling Colours Entirely</h2>\n<p>If you want Vim not to use colours at <em>all</em>, you just need to run the command:</p>... | 2016/07/13 | [
"https://vi.stackexchange.com/questions/8754",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8409/"
] | I would like to easily transform these two lines :
>
> One line.
>
> long line with many words in this example
>
>
>
into the line :
>
> One long line with many words in this example line.
>
>
>
How I currently do it :
* place cursor on the *l* of *long*
* enter visual mode
* go to the end of the line... | Disabling Colours Entirely
--------------------------
If you want Vim not to use colours at *all*, you just need to run the command:
```
:set t_Co=0
```
This tells Vim that it is running in a terminal that does not support colours, so Vim will only output black and white text (which will then be displayed by your t... |
8,757 | <p>When I insert a line break inside a line of Python 3 code, the remaining part of the line is indented by two additional tab widths (2 time 4 spaces) in the next line.</p>
<pre><code># Before
example_function(argument_name_1, argument_name_2)
# After
example_function(argument_name_1,
argument_name_2)
</code... | [
{
"answer_id": 8763,
"author": "DoYouEvenCodeBro",
"author_id": 2757,
"author_profile": "https://vi.stackexchange.com/users/2757",
"pm_score": 2,
"selected": false,
"text": "<p>I'm assuming you are using the default vim python indentation file. That's where this behavior is set, and it's... | 2016/07/13 | [
"https://vi.stackexchange.com/questions/8757",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3255/"
] | When I insert a line break inside a line of Python 3 code, the remaining part of the line is indented by two additional tab widths (2 time 4 spaces) in the next line.
```
# Before
example_function(argument_name_1, argument_name_2)
# After
example_function(argument_name_1,
argument_name_2)
```
How can I chan... | The script that controls Vim's indentation of Python files is located at `$VIMRUNTIME/indent/python.vim`. You can see the help file for it with `:help ft-python-indent`. From that, we learn there are a few global variables that can be used to control the indentation's behaviour:
>
> The amount of indent can be set fo... |
8,770 | <p>For example, if I had source text like this (with the numbers on the left representing line numbers that are not part of the source text):</p>
<pre><code>1 foo
2 bar
3
4 baz
</code></pre>
<p>it would appear as:</p>
<pre><code>1 foo
2 bar
4 baz
</code></pre>
<p>To clarify, when I say "blank lines" I mean li... | [
{
"answer_id": 8771,
"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 a feature called \"Folds\". Try adding this to your <code>.vimrc</code>:</p>\n\n<pre><code>syn m... | 2016/07/14 | [
"https://vi.stackexchange.com/questions/8770",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8423/"
] | For example, if I had source text like this (with the numbers on the left representing line numbers that are not part of the source text):
```
1 foo
2 bar
3
4 baz
```
it would appear as:
```
1 foo
2 bar
4 baz
```
To clarify, when I say "blank lines" I mean lines that would match the regex `^$`. | You can do this with a feature called "Folds". Try adding this to your `.vimrc`:
```
syn match MyEmptyLines "\(^$\)\+" fold
syn sync fromstart
setlocal foldmethod=syntax
```
This tell's vim to create folds based off of the syntax of your file, and then adds a new syntax, e.g. any number of lines that match `^$`. The... |
8,777 | <p>When I visually select text and enter <code>:</code> I'll get this:</p>
<pre><code>:'<,'>
</code></pre>
<p>Now I can enter a substitution to be done on those lines. However, what if I wanted to do several substitution, e.g. <code>foo</code> to <code>bar</code> and <code>hello</code> to <code>world</code>? Wh... | [
{
"answer_id": 8778,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 2,
"selected": false,
"text": "<p>While there are probably ways to do it all in a single substitution, I think that probably the most <em>practical</em>... | 2016/07/14 | [
"https://vi.stackexchange.com/questions/8777",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6300/"
] | When I visually select text and enter `:` I'll get this:
```
:'<,'>
```
Now I can enter a substitution to be done on those lines. However, what if I wanted to do several substitution, e.g. `foo` to `bar` and `hello` to `world`? What would I need to do then? | Using `gv` is a good option. Another alternative is to just hit `:`
`Up` after you do your first substitution. This will bring up your previous substitution with the `:'<,'>` text at the beginning.
Then, you can edit the previous command with your cursor keys and backspace.
This works because conveniently, the `:'<,... |
8,780 | <p>This happens to me semi-frequently. I have two tabs open, and I would like to merge them into one tab with a vertical split. Essentially, I want to do the opposite of <a href="http://vimdoc.sourceforge.net/htmldoc/windows.html#CTRL-W_T" rel="noreferrer">CTRL-w_T</a>. Right now, I have to this:</p>
<pre><code>:wq<... | [
{
"answer_id": 8781,
"author": "grochmal",
"author_id": 7700,
"author_profile": "https://vi.stackexchange.com/users/7700",
"pm_score": 2,
"selected": false,
"text": "<p>Dirty solution (only works if you have exactly two tabs):</p>\n\n<pre><code>vim -p file1 file2\n\n:exe 'normal! gt' | e... | 2016/07/14 | [
"https://vi.stackexchange.com/questions/8780",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2920/"
] | This happens to me semi-frequently. I have two tabs open, and I would like to merge them into one tab with a vertical split. Essentially, I want to do the opposite of [CTRL-w\_T](http://vimdoc.sourceforge.net/htmldoc/windows.html#CTRL-W_T). Right now, I have to this:
```
:wq<cr><C-w>v:browse old<cr>q1<cr>
```
Is the... | Assuming I understand you correctly, try the following:
```
function! MergeTab()
let bufnums = tabpagebuflist()
hide tabclose
topleft vsplit
for n in bufnums
execute 'sbuffer ' . n
wincmd _
endfor
wincmd t
quit
wincmd =
endfunction
command! MergeTab call MergeTab()
```
... |
8,789 | <p>So I do a visual selection and hit a <code>vnoremap</code> which calls a function and executes <code>mode()</code>, but everything it ever does it output <code>n</code>, indicating I'm in normal mode, even though that is certainly not true.</p>
<pre><code>vnoremap <silent> qb :<c-u>call <sid>func(... | [
{
"answer_id": 8790,
"author": "Antony",
"author_id": 7878,
"author_profile": "https://vi.stackexchange.com/users/7878",
"pm_score": 2,
"selected": false,
"text": "<p>Vim has left Visual mode by the time <code>Func</code> is called.\nThe following will get <code>mode()</code> to echo<cod... | 2016/07/14 | [
"https://vi.stackexchange.com/questions/8789",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6300/"
] | So I do a visual selection and hit a `vnoremap` which calls a function and executes `mode()`, but everything it ever does it output `n`, indicating I'm in normal mode, even though that is certainly not true.
```
vnoremap <silent> qb :<c-u>call <sid>func()<cr>
function! func()
echo mode()
endfunction
``` | In `visual mode`, press `:`, then press enter or escape. The selection is gone and you're in `normal mode`. This is what's happening with your maps and why `mode()` returns `n`.
To deal with this, you need tell your function that it *should be* in visual mode. You already know that it will be since you're using `vmap`... |
8,797 | <p>In my fortran code I have a lot of blocks like the following</p>
<pre><code>subroutine name(arg1,arg2,arg3,...)
:
end subroutine
</code></pre>
<p>and I want them to become</p>
<pre><code>subroutine name(arg1,arg2,arg3,...)
:
end subroutine name
</code></pre>
<p>Where each of these blocks can be indented by any a... | [
{
"answer_id": 8798,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>A possible workaround is to use a macro:</p>\n\n<pre><code>qa/^subroutine<CR>f<space>/end subroutine<CR>... | 2016/07/15 | [
"https://vi.stackexchange.com/questions/8797",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6498/"
] | In my fortran code I have a lot of blocks like the following
```
subroutine name(arg1,arg2,arg3,...)
:
end subroutine
```
and I want them to become
```
subroutine name(arg1,arg2,arg3,...)
:
end subroutine name
```
Where each of these blocks can be indented by any amount of spaces (in fact, such blocks can be nest... | You could use a combination of `:global`, [matchit](https://github.com/tmhedberg/matchit) and `:normal!`:
```
:g/^\s*subroutine/norm ^whye^%$p
```
Explanation:
* `:g/^\s*subroutine`: for all lines matching `^\s*subroutine`, do:
* `normal`: enter normal mode (~~`!` means no mappings~~ do **not** use `norm!`, as the ... |
8,808 | <p>Currently when I click somewhere in the terminal with <code>mouse=a</code> enabled, Vim exits visual mode. How can I force Vim to remain in Visual mode, and thereby use mouse <em>clicks</em> (not drags) to create a selection from the line/location where visual mode was entered?</p>
<hr>
<p><strong>Edit</strong>: I... | [
{
"answer_id": 8809,
"author": "mMontu",
"author_id": 1405,
"author_profile": "https://vi.stackexchange.com/users/1405",
"pm_score": 1,
"selected": false,
"text": "<p>This behavior works fine on <strong>gVim</strong> if the mouse is enabled (<code>:set mouse=a</code>) and the <code>'sele... | 2016/07/15 | [
"https://vi.stackexchange.com/questions/8808",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8084/"
] | Currently when I click somewhere in the terminal with `mouse=a` enabled, Vim exits visual mode. How can I force Vim to remain in Visual mode, and thereby use mouse *clicks* (not drags) to create a selection from the line/location where visual mode was entered?
---
**Edit**: I came up with a set of remaps that solves ... | You could do this:
```
:xnoremap <LeftMouse> m`<LeftMouse>v``
```
This allows you to *click* on where you want to extend the visual selection to, rather than drag. It works best if you also
```
:set slm=
``` |
8,816 | <p>I am making some remaps for inserting/removing comments and "dividers" for different languages. In my ftplugins files the variable <code>g:CommentChar</code> is defined. For some reason I am getting the following error:</p>
<p><code>E114: Missing quote: "\
E15: Invalid expression: ":normal! mA^i".g:CommentChar."\</... | [
{
"answer_id": 8817,
"author": "Sato Katsura",
"author_id": 2313,
"author_profile": "https://vi.stackexchange.com/users/2313",
"pm_score": 3,
"selected": true,
"text": "<p>Use <code><expr></code> instead of <code>:execute 'normal! ...'</code>:</p>\n\n<pre><code>nnoremap <expr>... | 2016/07/16 | [
"https://vi.stackexchange.com/questions/8816",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8084/"
] | I am making some remaps for inserting/removing comments and "dividers" for different languages. In my ftplugins files the variable `g:CommentChar` is defined. For some reason I am getting the following error:
`E114: Missing quote: "\
E15: Invalid expression: ":normal! mA^i".g:CommentChar."\`
when trying to use the `... | Use `<expr>` instead of `:execute 'normal! ...'`:
```
nnoremap <expr> <Leader>_ 'mao'.g:CommentChar.'<Esc>100a-<Esc>`a<CR>'
nnoremap <expr> <Leader>c 'mA^i'.g:CommentChar.'<Esc>`A<CR>'
nnoremap <expr> <Leader>C 'mA^mBi'.g:CommentChar.'<Esc>f'.g:CommentChar.'dl`Bdl`A<CR>'
vnoremap <expr> <Leader>c ':s/^/'.g:CommentChar... |
8,829 | <p>I have a Vi running as BusyBox executable (VMware ESXi):</p>
<pre><code>$ vi --version
BusyBox v1.20.2 (2014-08-27 12:48:18 PDT) multi-call binary.
</code></pre>
<p>Is there a way to disable auto-indent when pasting the code? Neither of the methods described in <a href="https://stackoverflow.com/questions/2514445/... | [
{
"answer_id": 8831,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": true,
"text": "<p>Judging by <a href=\"https://git.busybox.net/busybox/tree/editors/vi.c\">the source</a>, the only settable options in \"BusyB... | 2016/07/17 | [
"https://vi.stackexchange.com/questions/8829",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5334/"
] | I have a Vi running as BusyBox executable (VMware ESXi):
```
$ vi --version
BusyBox v1.20.2 (2014-08-27 12:48:18 PDT) multi-call binary.
```
Is there a way to disable auto-indent when pasting the code? Neither of the methods described in [Turning off auto indent when pasting text into vim](https://stackoverflow.com/... | Judging by [the source](https://git.busybox.net/busybox/tree/editors/vi.c), the only settable options in "BusyBox Vi" are:
```
autoindent
showmatch
ignorecase
```
So, the answer seems to be "no". |