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
5,586
<p>I want to have the command which is stated in the title. I looked for it in intrinsic Vim command but did not find it. I ran some tutorial online about functions in vim, The idea would be to have something like that in my <code>.vimrc</code>:</p> <pre><code>map &lt;command&gt; &lt;argument&gt;: call nextWordWithLet...
[ { "answer_id": 5587, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 3, "selected": false, "text": "<p><strong>Edit</strong> : <a href=\"https://vi.stackexchange.com/a/5592/4939\">Peter Rincker</a>'s answer is shorter, easi...
2015/11/24
[ "https://vi.stackexchange.com/questions/5586", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4562/" ]
I want to have the command which is stated in the title. I looked for it in intrinsic Vim command but did not find it. I ran some tutorial online about functions in vim, The idea would be to have something like that in my `.vimrc`: ``` map <command> <argument>: call nextWordWithLetter(argument) function nextWordWithL...
You can use `getchar()` and `search()` to accomplish your goal. ``` nnoremap <key> :call search('\<' . nr2char(getchar()), 'W', line('.'))<cr> ``` The idea is we use `nr2char(getchar())` to wait for a character to be typed and use `search()` to search for the next instance of the character at the beginning of a word...
5,594
<p>I am looking for an easy way to reflow blocks of comments (in GO). According to <a href="https://stackoverflow.com/questions/8435808/reflowing-comment-blocks-with-vim">this post</a> I should be able to just run <code>gq</code> on a block and it will reflow automatically, but this doesn't seem to work.</p> <p>Here ...
[ { "answer_id": 5602, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>You need to check your <code>formatoptions</code> setting. According to the <a href=\"https://vimhelp.appspot.com...
2015/11/25
[ "https://vi.stackexchange.com/questions/5594", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5423/" ]
I am looking for an easy way to reflow blocks of comments (in GO). According to [this post](https://stackoverflow.com/questions/8435808/reflowing-comment-blocks-with-vim) I should be able to just run `gq` on a block and it will reflow automatically, but this doesn't seem to work. Here is some sample text: ``` // Prin...
In my vimrc file I had `set paste` turned on. When I removed this configuration I was able to get comments to flow correctly.
5,595
<p>There comes a time where I'm in a situation of downloading multiple files. And the name of files are in series. Something like.</p> <pre><code>http://www.example.com/files/images/img01.jpg http://www.example.com/files/images/img02.jpg http://www.example.com/files/images/img03.jpg ... </code></pre> <p>and so on. </...
[ { "answer_id": 5596, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": false, "text": "<ol>\n<li><p>Assuming you have this line:</p>\n\n<pre><code>http://www.example.com/files/images/img01.jpg\n</code></pre></li>\n...
2015/11/25
[ "https://vi.stackexchange.com/questions/5595", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5425/" ]
There comes a time where I'm in a situation of downloading multiple files. And the name of files are in series. Something like. ``` http://www.example.com/files/images/img01.jpg http://www.example.com/files/images/img02.jpg http://www.example.com/files/images/img03.jpg ... ``` and so on. Suppose there are files fr...
Here is a different version, that assumes you have Vim [7.4.754](https://github.com/vim/vim/commit/3a304b23823b089e499063e8211c5695d049f3ba) (25 Jun 2015) or newer: If you have this line: ``` http://www.example.com/files/images/img01.jpg ``` Now copy and paste it 48 times `yy48p`. Then go to the *second line*, visu...
5,598
<p>I want to record a macro, which generates a formatted text that includes a number. I want the number to be counted up whenever the macro is invoked.</p> <p>For example:</p> <pre><code>abc 1 def abc 2 def abc 3 def </code></pre> <p>Can I do that?</p> <p><code>Vim</code>'s version is <code>7.0</code>. OS is <code>...
[ { "answer_id": 5599, "author": "Steve", "author_id": 1313, "author_profile": "https://vi.stackexchange.com/users/1313", "pm_score": 1, "selected": false, "text": "<p>I do something similar in a function to number a list but taking note that the register may change between sessions someth...
2015/11/25
[ "https://vi.stackexchange.com/questions/5598", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2951/" ]
I want to record a macro, which generates a formatted text that includes a number. I want the number to be counted up whenever the macro is invoked. For example: ``` abc 1 def abc 2 def abc 3 def ``` Can I do that? `Vim`'s version is `7.0`. OS is `CentOS 6`.
Use `<c-a>` mapping will increment a number in your macro. ``` qqyyp<c-a>q@q ``` The idea is to duplicate the current line (`yy` and `p`) and then increment the newly duplicated line (`<c-a>`). For more help see: ``` :h q :h CTRL-A :h @ ```
5,619
<p>When I run ctags for a project written in bash, tags for functions are generated, but not for variables.<br> e.g. if I run <code>ctags --list-kinds=sh</code></p> <blockquote> <p>f functions</p> </blockquote> <p>As compared to if I run the list for the "c" language alot more tag types get included.<br> Is it pos...
[ { "answer_id": 5816, "author": "Cometsong", "author_id": 2303, "author_profile": "https://vi.stackexchange.com/users/2303", "pm_score": 2, "selected": false, "text": "<p>A regex can be built to find variable declarations like <code>[A-z]…=[A-z0-9]</code></p>\n\n<p>Another for variable us...
2015/11/27
[ "https://vi.stackexchange.com/questions/5619", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
When I run ctags for a project written in bash, tags for functions are generated, but not for variables. e.g. if I run `ctags --list-kinds=sh` > > f functions > > > As compared to if I run the list for the "c" language alot more tag types get included. Is it possible to generate tags for bash variables? or ...
based on the prompt from @Cometsong I added wrote the regex expression below and added to my `~/.ctags` ``` --regex-sh=/^[ \t]*(local)?[ \t]*([A-Za-z0-9_-]+)=/\2/v,variable,variables/ ``` So far it seems to be working quite nicely
5,622
<p>I am trying to get the <a href="http://vimawesome.com/plugin/vim-airline-sad-beautiful-tragic" rel="noreferrer">vim-airline</a> up and running.</p> <p>I have required it via vundle in my <code>~./vimrc</code>:</p> <pre><code>Plugin 'bling/vim-airline' </code></pre> <p>I have installed it and expected my Vim to lo...
[ { "answer_id": 5623, "author": "k0pernikus", "author_id": 5449, "author_profile": "https://vi.stackexchange.com/users/5449", "pm_score": 6, "selected": true, "text": "<p>One has to realize that the feature implemented by airline are inspired by the <a href=\"https://powerline.readthedocs...
2015/11/27
[ "https://vi.stackexchange.com/questions/5622", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
I am trying to get the [vim-airline](http://vimawesome.com/plugin/vim-airline-sad-beautiful-tragic) up and running. I have required it via vundle in my `~./vimrc`: ``` Plugin 'bling/vim-airline' ``` I have installed it and expected my Vim to look like the screenshot on its project page: ![Expected Vim theme](https...
One has to realize that the feature implemented by airline are inspired by the [powerline](https://powerline.readthedocs.org/en/latest/) plugin. Furthermore, I was relying on the docs too much, not realizing that there is well-written airline help document shipped with itself: ``` :h airline ``` Reading its documen...
5,624
<p>I just learned about tabs, meaning I can open them via</p> <pre><code>:tabe some/file :tabe yet/another/file :tabe foo </code></pre> <p>and circle them via gt (activate right one) and gT (activate left one).</p> <p>Yet when I close my vim instance via quit-all <code>:qa</code>, all my tabs are gone. How can I res...
[ { "answer_id": 5625, "author": "apparat", "author_id": 5331, "author_profile": "https://vi.stackexchange.com/users/5331", "pm_score": 4, "selected": false, "text": "<p>You can save a session of vim with all its settings including your open tabs with</p>\n\n<pre><code>:mksession ~/session...
2015/11/27
[ "https://vi.stackexchange.com/questions/5624", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
I just learned about tabs, meaning I can open them via ``` :tabe some/file :tabe yet/another/file :tabe foo ``` and circle them via gt (activate right one) and gT (activate left one). Yet when I close my vim instance via quit-all `:qa`, all my tabs are gone. How can I restore them all when entering vim again?
You can save a session of vim with all its settings including your open tabs with ``` :mksession ~/session.vim ``` and load it with ``` :source ~/session.vim ``` if you don't want to store options like your colorscheme and font size you can disable storing them with this entry in your vimrc ``` set sessionoption...
5,630
<p>I often have to add stuff at the end of a file, hence I go to the last line:</p> <pre><code>:$ </code></pre> <p>yet this is at the beginning of the line. Often I discover myself doing:</p> <p><kbd>Ctrl</kbd> + <kbd>Arrow Right</kbd> to jump by word until I am at the end of the line.</p> <p>Then I enter insert mo...
[ { "answer_id": 5631, "author": "k0pernikus", "author_id": 5449, "author_profile": "https://vi.stackexchange.com/users/5449", "pm_score": 2, "selected": false, "text": "<ul>\n<li><code>:$</code> jumps to the end of the file</li>\n<li><kbd>Shift</kbd> + <kbd>A</kbd> # enters insert mode at...
2015/11/27
[ "https://vi.stackexchange.com/questions/5630", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
I often have to add stuff at the end of a file, hence I go to the last line: ``` :$ ``` yet this is at the beginning of the line. Often I discover myself doing: `Ctrl` + `Arrow Right` to jump by word until I am at the end of the line. Then I enter insert mode us via `a`, and hit Enter and do whatever I need there....
If file is already opened in normal mode ---------------------------------------- Use: ``` Go ``` * `G` goes to the end of the file * `o` enters insert mode on a line below the current one If you are opening the file from the command line ------------------------------------------------- You can open vim on the l...
5,638
<p>I have a parenthesis in my LaTeX document that is intentionally unmatched. This breaks syntax highlighting for all of the following text.</p> <p>Is there some way to reset syntax highlighting after this point?</p> <p>The <code>%stopzone</code> trick that works for other LaTeX syntax breakages doesn't work here. Ne...
[ { "answer_id": 5646, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 3, "selected": true, "text": "<p>This is a very difficult problem. It is such a corner case of what people need, that I would not personally want to...
2015/11/28
[ "https://vi.stackexchange.com/questions/5638", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5459/" ]
I have a parenthesis in my LaTeX document that is intentionally unmatched. This breaks syntax highlighting for all of the following text. Is there some way to reset syntax highlighting after this point? The `%stopzone` trick that works for other LaTeX syntax breakages doesn't work here. Neither does inserting a match...
This is a very difficult problem. It is such a corner case of what people need, that I would not personally want to support it directly. Thus I also won't try to come with a direct answer to your question. Instead, I want to propose two indirect solutions: * Put the unmatched paranthesis inside a verbatim command, e....
5,643
<p>Let's say I have a vertical split, and four buffers open.</p> <p>I'd like to be able to have one buffer open on the left, and cycle through just the other three on the right. Something like <code>:bnext</code> but skipping open/visible buffers.</p>
[ { "answer_id": 5645, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 3, "selected": false, "text": "<p>This is barely tested, but should work:</p>\n\n<pre><code> fu! CycleBuffer()\n let i=get(s:, 'cycle_buf...
2015/11/28
[ "https://vi.stackexchange.com/questions/5643", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5462/" ]
Let's say I have a vertical split, and four buffers open. I'd like to be able to have one buffer open on the left, and cycle through just the other three on the right. Something like `:bnext` but skipping open/visible buffers.
This is a good new feature idea Here is another implementation. This one will ignore unlisted buffers, and also it won't rely on a global to decide which is next. Instead the *next* definition is relative to the current buffer number. ``` nnoremap <silent> <Plug>CycleToNextBuffer :call <sid>CycleToNext('after')<cr> i...
5,647
<p>As far as I know, all "good" scripts/programs start off with a shebang line as the first line:</p> <pre><code>#!/bin/bash #!/usr/bin/env python #!/usr/bin/perl </code></pre> <p>etc. Is it possible to pass that line to Vim in <code>command</code>-mode to generically determine the program to use when executing the ...
[ { "answer_id": 5652, "author": "cbaumhardt", "author_id": 3282, "author_profile": "https://vi.stackexchange.com/users/3282", "pm_score": 3, "selected": false, "text": "<p>You could use the fact that your shell understands the Shebang:</p>\n\n<pre><code>:!./%\n</code></pre>\n\n<p>Please b...
2015/11/29
[ "https://vi.stackexchange.com/questions/5647", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5465/" ]
As far as I know, all "good" scripts/programs start off with a shebang line as the first line: ``` #!/bin/bash #!/usr/bin/env python #!/usr/bin/perl ``` etc. Is it possible to pass that line to Vim in `command`-mode to generically determine the program to use when executing the current file. For example, perl file ...
I'm not sure this is what you want but you could try this mapping using the `<F7>` key: ``` nnoremap <F7> :<C-U>sil! exe '!' . matchstr(getline(1), '#!\zs.*') . ' ' . shellescape(expand('%:p'), 1) <Bar> redraw!<CR> ``` * `matchstr(getline(1), '#!\zs.*')` extract the text after the shebang * `shellescape(expand('%:p'...
5,651
<p>When setting <code>spelllang</code> for the first time, I was prompted to auto-download the appropriate spell file. Somehow I aborted the process due to unclear instructions, when it asked me, into which directory it should go.</p> <p>Now when I <code>:set spelllang</code> it just says <code>Warning: Cannot find wo...
[ { "answer_id": 5654, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 5, "selected": true, "text": "<p>The <a href=\"https://vimhelp.appspot.com/spell.txt.html#spellfile.vim\" rel=\"noreferrer\">help</a> states this:<...
2015/11/29
[ "https://vi.stackexchange.com/questions/5651", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1066/" ]
When setting `spelllang` for the first time, I was prompted to auto-download the appropriate spell file. Somehow I aborted the process due to unclear instructions, when it asked me, into which directory it should go. Now when I `:set spelllang` it just says `Warning: Cannot find word list`… but does not offer to downl...
The [help](https://vimhelp.appspot.com/spell.txt.html#spellfile.vim) states this: ``` The plugin has a default place where to look for spell files, on the Vim ftp server. If you want to use another location or another protocol, set the g:spellfile_URL variable to the directory that holds the spell files. The netrw p...
5,658
<p>Currently my <code>init.vim</code> (<code>neovim</code>'s equivalent to the <code>.vimrc</code>) sets the <code>foldmethod</code> to <code>marker</code>: </p> <pre><code>set foldmethod=marker </code></pre> <p>When I open a file all sections are folded and if the curser is placed in the according line and moved to ...
[ { "answer_id": 5654, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 5, "selected": true, "text": "<p>The <a href=\"https://vimhelp.appspot.com/spell.txt.html#spellfile.vim\" rel=\"noreferrer\">help</a> states this:<...
2015/11/29
[ "https://vi.stackexchange.com/questions/5658", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5454/" ]
Currently my `init.vim` (`neovim`'s equivalent to the `.vimrc`) sets the `foldmethod` to `marker`: ``` set foldmethod=marker ``` When I open a file all sections are folded and if the curser is placed in the according line and moved to the left it will open automatically. It would be awesome if there was a way to h...
The [help](https://vimhelp.appspot.com/spell.txt.html#spellfile.vim) states this: ``` The plugin has a default place where to look for spell files, on the Vim ftp server. If you want to use another location or another protocol, set the g:spellfile_URL variable to the directory that holds the spell files. The netrw p...
5,677
<p>I would like to have a mapping that opens a buffer with all the lines containing the word under the cursor.</p> <p>I know such a mapping already exists in vanilla vim in normal mode <code>[I</code>.<br> But I don't like the output, the controls to move seem limited and I don't know how to edit it like a normal buff...
[ { "answer_id": 5678, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 3, "selected": true, "text": "<p>You command looks like follow without the <code>:execute</code>:</p>\n\n<pre><code>:g/pat/let @a.= line('.') . \"\\t\...
2015/12/02
[ "https://vi.stackexchange.com/questions/5677", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4939/" ]
I would like to have a mapping that opens a buffer with all the lines containing the word under the cursor. I know such a mapping already exists in vanilla vim in normal mode `[I`. But I don't like the output, the controls to move seem limited and I don't know how to edit it like a normal buffer. I've come up with...
You command looks like follow without the `:execute`: ``` :g/pat/let @a.= line('.') . "\t" . getline('.') . "\n" ``` Adding in the `:execute` means you need to quote things correctly. The real trick is to use single quote. Also properly escape your single quotes or switching to double quotes. ``` :execute 'g/' . e...
5,680
<p>I find both <em>number</em> and <em>relativenumber</em> useful. Is there any way to display them both at the same time?</p>
[ { "answer_id": 5684, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 3, "selected": false, "text": "<p>Showing all the line numbers and relative numbers at the same time isn't possible. But you can get the current line numbe...
2015/12/02
[ "https://vi.stackexchange.com/questions/5680", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/650/" ]
I find both *number* and *relativenumber* useful. Is there any way to display them both at the same time?
Showing all the line numbers and relative numbers at the same time isn't possible. But you can get the current line number and the relative number for all the others. From `:help number_relativenumber`: ``` The 'relativenumber' option changes the displayed number to be relative to the cursor. Together with 'number' t...
5,681
<p>Due to a quirk in the domain-specific language I am working with, I frequently face the task of (selectively, not globally) replacing <code>term</code> or <code>TERM</code> with <code>word</code> or <code>WORD</code>, respectively.</p> <p>This means, I search case-insensitively for <code>term</code>, and want to re...
[ { "answer_id": 5682, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 5, "selected": true, "text": "<p>Michaels Geddes' plugin <a href=\"https://www.vim.org/scripts/script.php?script_id=6\" rel=\"nofollow noreferrer\">kee...
2015/12/02
[ "https://vi.stackexchange.com/questions/5681", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1726/" ]
Due to a quirk in the domain-specific language I am working with, I frequently face the task of (selectively, not globally) replacing `term` or `TERM` with `word` or `WORD`, respectively. This means, I search case-insensitively for `term`, and want to replace that with `word` *while keeping the uppercase / lowercase o...
Michaels Geddes' plugin [keepcase](https://www.vim.org/scripts/script.php?script_id=6) ([GitHub](https://github.com/vim-scripts/keepcase.vim)) has all you need: ``` :%SubstituteCase/\cterm/word/g ``` Other syntax elements from `:substitute` are also supported.
5,685
<p>I don't use any <code>g combinations</code> except of <code>gg</code>, in normal mode. How can I make it so that pressing <code>g</code> once will be enough?</p> <p><code>nnoremap g gg</code> makes it wait for 3 seconds or so for a continuation of the command. Unmapping <code>g</code> beforehand doesn't work either...
[ { "answer_id": 5690, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 6, "selected": true, "text": "<p>Assuming you have a newer version of Vim (7.3.1261+) you can use <code>&lt;nowait&gt;</code></p>\n\n<pre><code>nnorem...
2015/12/02
[ "https://vi.stackexchange.com/questions/5685", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5365/" ]
I don't use any `g combinations` except of `gg`, in normal mode. How can I make it so that pressing `g` once will be enough? `nnoremap g gg` makes it wait for 3 seconds or so for a continuation of the command. Unmapping `g` beforehand doesn't work either, because I can't map to `gg` if I unmap `g`. Should I unmap ever...
Assuming you have a newer version of Vim (7.3.1261+) you can use `<nowait>` ``` nnoremap <nowait> g gg ``` Although, I can not stress the usefulness of some of the `g` mappings. Here is a short list of useful `g` mappings: * `gE` - backwards end of word motion * `g_` - to the last non-blank character of a line * `g...
5,692
<p>Is is possible to get the original working directory of vim after changing the local working directory?</p> <p>Let's say I open vim with parent directory:</p> <p><code>~/projects/myproject</code></p> <p>and then I open a file and change the working directory:</p> <p><code>~/projects/myproject/tasks/mytask.js</co...
[ { "answer_id": 5693, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 0, "selected": false, "text": "<pre><code>:echo system(\"pwd\")\n</code></pre>\n\n<p>should give you the information you want.</p>\n" }, { "answer_id"...
2015/12/02
[ "https://vi.stackexchange.com/questions/5692", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5498/" ]
Is is possible to get the original working directory of vim after changing the local working directory? Let's say I open vim with parent directory: `~/projects/myproject` and then I open a file and change the working directory: `~/projects/myproject/tasks/mytask.js` ``` autocmd BufEnter * silent! lcd %:p:h ``` *...
### Fugitive If your project is under git's control then you use [Fugitive.vim](https://github.com/tpope/vim-fugitive). ``` :echo fugitive#repo().tree() ``` To edit a file relative to the git root you an use `:Gedit` and a `/`: ``` :Gedit /tasks/mytask.js ``` For more help see: ``` :h fugitive :h :Gedit ``` #...
5,696
<p>I'm using Vim with the Vaxe plugin for syntax highlighting, the plugin's highlighting file is <a href="https://github.com/jdonaldson/vaxe/blob/master/syntax/haxe.vim" rel="noreferrer">here</a> for reference.</p> <p>I'm trying to add some conceals to tidy up the code visually, but I can't seem to get anything to app...
[ { "answer_id": 5698, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>The problem in your case is, that the syntax highlighting script for <a href=\"https://github.com/jdonaldson/vaxe/...
2015/12/03
[ "https://vi.stackexchange.com/questions/5696", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5502/" ]
I'm using Vim with the Vaxe plugin for syntax highlighting, the plugin's highlighting file is [here](https://github.com/jdonaldson/vaxe/blob/master/syntax/haxe.vim) for reference. I'm trying to add some conceals to tidy up the code visually, but I can't seem to get anything to apply. The simplest thing I'm trying to ...
The problem in your case is, that the syntax highlighting script for [package](https://github.com/jdonaldson/vaxe/blob/master/syntax/haxe.vim#L23) uses a keyword (`:h syn-keyword`) and that always has priority before any of the syn-match or syn-region rules. In your case, I would therefore simply use a `matchadd()` ca...
5,714
<p>I want to join multiple consecutive blank lines into single blank line. </p> <p>To do this, I use the following global command:</p> <pre><code>g/^\s*$/,/./-j </code></pre> <p>But this doesn't work in some exceptional cases. For example in the following scenario, 3 blank lines between "c" and "d" are reduced to 2 ...
[ { "answer_id": 5715, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 0, "selected": false, "text": "<p>Your global command is explained in details <a href=\"https://vi.stackexchange.com/a/1921/4939\">here</a>.</p>\n<pre><co...
2015/12/04
[ "https://vi.stackexchange.com/questions/5714", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5506/" ]
I want to join multiple consecutive blank lines into single blank line. To do this, I use the following global command: ``` g/^\s*$/,/./-j ``` But this doesn't work in some exceptional cases. For example in the following scenario, 3 blank lines between "c" and "d" are reduced to 2 blank lines instead of 1. [![Fig...
Why your command doesn't work ----------------------------- The simple answer is the `.` as the end range for your `:j` command will match the space in your offending line. This means that your nearly empty line will not be removed/compressed. This can be solved by searching for `\S` (non-whitespace character) instea...
5,723
<p>Vi and Vim, as all of you know, have many synonyms. There are three ways I know of to save the file and exit Vim and Vi. These are <em>:wq</em> <strong>&lt;cr&gt;</strong>, <em>:x</em> <strong>&lt;cr&gt;</strong> and <em>ZZ</em>. I have heard that these are different in some way.</p> <p>Are there any practical diff...
[ { "answer_id": 5726, "author": "akshay", "author_id": 246, "author_profile": "https://vi.stackexchange.com/users/246", "pm_score": 7, "selected": true, "text": "<p>From Vim's documentation, <a href=\"http://vimhelp.appspot.com/editing.txt.html#%3Ax\" rel=\"noreferrer\"><code>:x</code></a...
2015/12/04
[ "https://vi.stackexchange.com/questions/5723", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3032/" ]
Vi and Vim, as all of you know, have many synonyms. There are three ways I know of to save the file and exit Vim and Vi. These are *:wq* **<cr>**, *:x* **<cr>** and *ZZ*. I have heard that these are different in some way. Are there any practical differences between using: `:``x``<cr>` `:``w``q``<cr>` or `Z``Z` to...
From Vim's documentation, [`:x`](http://vimhelp.appspot.com/editing.txt.html#%3Ax) and [`ZZ`](http://vimhelp.appspot.com/editing.txt.html#ZZ) are equivalent; they only save the file if it has been modified, then quit Vim: ``` Write current file, if modified, and quit (same as ":x"). (Note: If there are several windo...
5,729
<p>I want to see the value of a variable, so I run the command </p> <pre><code>:let </code></pre> <p>Vim displays the results of this command using the <code>--more--</code> pager.<br> How can I search this for a phrase, e.g. <code>html</code>?<br> I've looked the man page for the more pager which says <code>+/</code...
[ { "answer_id": 5730, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": true, "text": "<p>This is not the <code>more</code> pager, this is Vim's internal and minimalistic pager which doesn't have search capabilities...
2015/12/05
[ "https://vi.stackexchange.com/questions/5729", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
I want to see the value of a variable, so I run the command ``` :let ``` Vim displays the results of this command using the `--more--` pager. How can I search this for a phrase, e.g. `html`? I've looked the man page for the more pager which says `+/` is used for search but it doesn't seem to work, neither doe...
This is not the `more` pager, this is Vim's internal and minimalistic pager which doesn't have search capabilities. But you can use the `:redir` command: ``` :redir @a redirect output of following commands to register a :let list every current option and its value G<CR> go straight to the end of the...
5,732
<p>When using <em>gVim</em> on <em>Windows 7</em> I cannot use <strong>^]</strong> (<kbd>CTRL</kbd>+<kbd>]</kbd>) to jump to tags as described in the <em>Vim</em> documentation:</p> <pre><code>&lt;C-LeftMouse&gt; *&lt;C-LeftMouse&gt;* *CTRL-]* CTRL-] Jump to the definition of the keyword under t...
[ { "answer_id": 5733, "author": "wefwefa3", "author_id": 3032, "author_profile": "https://vi.stackexchange.com/users/3032", "pm_score": 2, "selected": false, "text": "<p>I just found out why I had this problem.</p>\n\n<h1>The cause of the problem</h1>\n\n<p>The problem is that I used a No...
2015/12/05
[ "https://vi.stackexchange.com/questions/5732", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3032/" ]
When using *gVim* on *Windows 7* I cannot use **^]** (`CTRL`+`]`) to jump to tags as described in the *Vim* documentation: ``` <C-LeftMouse> *<C-LeftMouse>* *CTRL-]* CTRL-] Jump to the definition of the keyword under the cursor. Same as ":tag {ident}", where {ident} is the ...
Say hello to knowledge fragmentation: <https://stackoverflow.com/q/6932702/520162> This question was already asked and answered on StackOverflow. **The key is to press `CTRL` and the key that is located where the `]` lives on the US keyboard**. I had the issue with a QUERTZ German keyboard and have to press `CTRL`-`+`...
5,750
<p>I know that gv reselects the last visual selection. This is great and I use it frequently.</p> <p>But sometimes I want to do something related but different: from the current cursor position, select a block in the same shape as the prior visual selection, but <em>positioned</em> where the cursor is now.</p> <p>In ...
[ { "answer_id": 5751, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 4, "selected": true, "text": "<p>This is a simple remap that allows you to re-select last pasted (or changed) text:</p>\n\n<pre><code>noremap gV `[v`]\n<...
2015/12/07
[ "https://vi.stackexchange.com/questions/5750", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4985/" ]
I know that gv reselects the last visual selection. This is great and I use it frequently. But sometimes I want to do something related but different: from the current cursor position, select a block in the same shape as the prior visual selection, but *positioned* where the cursor is now. In particular, I often have...
This is a simple remap that allows you to re-select last pasted (or changed) text: ``` noremap gV `[v`] ``` From comments in original post, perhaps you want to save the coordinates of the last change/paste *before* other/further changes, and restore *that* visual selection?
5,753
<p>I often find myself accidentally pressing <code>&lt;c-e&gt;</code>/<code>^E</code> while in normal mode inside a terminal buffer. This causes the terminal buffer to scroll down and a line with a <code>~</code> is displayed, like when your file doesn't reach the bottom of the screen.</p> <p>I've created a mapping th...
[ { "answer_id": 5776, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 2, "selected": false, "text": "<p>The following function and calls to that function work in Vim. It seems like they should work in Neovim but I don't hav...
2015/12/08
[ "https://vi.stackexchange.com/questions/5753", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1472/" ]
I often find myself accidentally pressing `<c-e>`/`^E` while in normal mode inside a terminal buffer. This causes the terminal buffer to scroll down and a line with a `~` is displayed, like when your file doesn't reach the bottom of the screen. I've created a mapping that stops `^E` from being called if the current bu...
This is what you want to use: ``` nmap <expr> <c-e> &buftype !=# 'terminal' ? "\<c-e>" : '' ``` To make this more convenient: ``` function! s:terminal_ignore(key, ...) abort execute printf('nmap <expr> %s &buftype !=# "terminal" ? "%s" : "%s"', \ a:key, a:key, a:0 ? a:1 : '') endfunction call s:terminal_...
5,761
<p>By searching, I've highlighted the string that I want to change. Now I want to replace only the highlighted text. I'm using <code>n</code> to advance to the next instance of the search string. I was thinking I could do something like <code>ciw</code> but that changes the whole word not just the highlighted text. </...
[ { "answer_id": 5762, "author": "Raphael Ahrens", "author_id": 350, "author_profile": "https://vi.stackexchange.com/users/350", "pm_score": 3, "selected": false, "text": "<p>If you have already searched for a word with <code>/word</code> or <code>?word</code>.</p>\n\n<p>You can use <code>...
2015/12/08
[ "https://vi.stackexchange.com/questions/5761", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1132/" ]
By searching, I've highlighted the string that I want to change. Now I want to replace only the highlighted text. I'm using `n` to advance to the next instance of the search string. I was thinking I could do something like `ciw` but that changes the whole word not just the highlighted text. I'm familiar with `:%s/old...
Use the `gn` motion to edit the current search match. The following example will change the current match to "FooBar": ``` cgnFooBar ``` The great part about this technique is that you can repeat the change via `.`. Assuming the next match will be changed the same way you can just use `.` to repeat. Or skip a few ma...
5,766
<p>If I want to indent all lines in a document, I can type <code>&gt;G</code> to apply it to the current line and below, followed by and <code>&gt;gg</code> to apply it to the lines above.</p> <p>Is there a combination I can use to just apply <code>&gt;</code> to all lines at once?</p>
[ { "answer_id": 5767, "author": "user21497", "author_id": 2377, "author_profile": "https://vi.stackexchange.com/users/2377", "pm_score": 3, "selected": false, "text": "<p>One way to indent all lines in a document:</p>\n\n<pre><code>:%&gt;\n</code></pre>\n" }, { "answer_id": 5768, ...
2015/12/08
[ "https://vi.stackexchange.com/questions/5766", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/69/" ]
If I want to indent all lines in a document, I can type `>G` to apply it to the current line and below, followed by and `>gg` to apply it to the lines above. Is there a combination I can use to just apply `>` to all lines at once?
You are looking for the `:>` command and a range of `1,$` (`%` for short) for the whole file. ``` :%> ``` For more help see: ``` :h :> :h :range ```
5,771
<p>Is it possible to change that somehow? Either to make Vim go one symbol further in normal mode, or one symbol less in visual mode?</p>
[ { "answer_id": 5772, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 2, "selected": false, "text": "<p>As far as I know, there's no built-in way to stop visual mode from being <em>inclusive</em> and normal mode from being <em>e...
2015/12/08
[ "https://vi.stackexchange.com/questions/5771", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5365/" ]
Is it possible to change that somehow? Either to make Vim go one symbol further in normal mode, or one symbol less in visual mode?
You can make `$` go one symbol further in normal mode by enabling setting `virtualedit=onemore` and remapping `$` to `g$`. ``` :set virtualedit=onemore :nnoremap $ g$ ``` --- As @statox mentions in the comments You can also make $ go one symbol less in visual mode with the following mapping: ``` :vnoremap $ $h ...
5,779
<p>I'm using Vim 7.3 on OS X Terminal version 2.6.1 (OS X version 10.11.2). If it's relevant, my version is compiled <em>without</em> X11.</p> <p>When I open a file in Vim, the terminal title bar changes to show the file name, as expected. Quitting the file with <code>:q</code> clears the title bar, also expected. The...
[ { "answer_id": 5772, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 2, "selected": false, "text": "<p>As far as I know, there's no built-in way to stop visual mode from being <em>inclusive</em> and normal mode from being <em>e...
2015/12/09
[ "https://vi.stackexchange.com/questions/5779", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5598/" ]
I'm using Vim 7.3 on OS X Terminal version 2.6.1 (OS X version 10.11.2). If it's relevant, my version is compiled *without* X11. When I open a file in Vim, the terminal title bar changes to show the file name, as expected. Quitting the file with `:q` clears the title bar, also expected. The problem comes when using `C...
You can make `$` go one symbol further in normal mode by enabling setting `virtualedit=onemore` and remapping `$` to `g$`. ``` :set virtualedit=onemore :nnoremap $ g$ ``` --- As @statox mentions in the comments You can also make $ go one symbol less in visual mode with the following mapping: ``` :vnoremap $ $h ...
5,780
<p>How can I get a list of the names of filetypes that vim currently knows about?</p> <p>I want to be able to do this so that when vim doesn't automatically detect a filetype I can try some of the filetypes vim knows about that may be similar and see if they provide reasonable syntax highlighting.</p> <p>I know that ...
[ { "answer_id": 5782, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 8, "selected": true, "text": "<p><strong>Simple Solution</strong></p>\n\n<p>Type <code>:setfiletype</code> <em>(with a space afterwards)</em>, then pr...
2015/12/09
[ "https://vi.stackexchange.com/questions/5780", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/268/" ]
How can I get a list of the names of filetypes that vim currently knows about? I want to be able to do this so that when vim doesn't automatically detect a filetype I can try some of the filetypes vim knows about that may be similar and see if they provide reasonable syntax highlighting. I know that vimscript files d...
**Simple Solution** Type `:setfiletype` *(with a space afterwards)*, then press `Ctrl-d`. See `:help cmdline-completion` for more on autocompletion in vim's command line. **Complicated Solution** This solution uses the `'runtimepath'` option to get all available syntax directories, and then fetches a list of the vi...
5,791
<p>Hot exit is one of killer features of Sublime Text editor. It allows to close editor at any point of time without worrying about modifications in opened files - it just closes without any question. When launch ST again all opened and edited files will be at the same state as they were before close</p> <p>I wonder i...
[ { "answer_id": 5794, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 1, "selected": false, "text": "<p>Yes. It's called \"session\" and you can read all about it in:</p>\n\n<pre><code>:help session\n</code></pre>\n" }, { ...
2015/12/10
[ "https://vi.stackexchange.com/questions/5791", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5608/" ]
Hot exit is one of killer features of Sublime Text editor. It allows to close editor at any point of time without worrying about modifications in opened files - it just closes without any question. When launch ST again all opened and edited files will be at the same state as they were before close I wonder is there a ...
Vim can do this, though it may be a bit clunky and take some setup. [romainl](https://vi.stackexchange.com/a/5794/2736) gets you partway with `session`. The missing bits are swap files, `:preserve`, and the `&` flag for `cpoptions`. Swap files are intended for recovery if Vim or your system crashes. They enable you t...
5,792
<p>I would like to apply macro <code>a</code> to a set of lines. For consecutive lines, this can be done by</p> <pre><code>:5,10norm! @a </code></pre> <p>(<a href="https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines">https://stackoverflow.com/questions/390174/in-vim-how-do-i-app...
[ { "answer_id": 5796, "author": "PhilippFrank", "author_id": 1296, "author_profile": "https://vi.stackexchange.com/users/1296", "pm_score": 4, "selected": true, "text": "<p>How about writing a 2nd macro that moves down n lines and then executes @a? Using a mark you can easily jump back to...
2015/12/10
[ "https://vi.stackexchange.com/questions/5792", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I would like to apply macro `a` to a set of lines. For consecutive lines, this can be done by ``` :5,10norm! @a ``` (<https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines>). How to do it for every `n`-th line from my current cursor position?
How about writing a 2nd macro that moves down n lines and then executes @a? Using a mark you can easily jump back to your original position. E.g., having defined your macro in register a, press `qb` to record in register b, press `5j` to go to line 6, press `@a` to execute a and then `q` to quit recording. Using `9@b`...
5,800
<p>Hi I am having some issue trying to unmap this key in my .<strong>vimrc</strong>. I've tried a lot of suggestions and remapping but it seems to be resetting itself every time.</p> <pre><code>unamp &lt;Esc&gt; unmap! &lt;Esc&gt; map &lt;Esc&gt;^[ &lt;Esc&gt;^[ map &lt;Esc&gt; &lt;Nop&gt; </code></pre> <p>Everytime...
[ { "answer_id": 5801, "author": "TheLazyChap", "author_id": 2129, "author_profile": "https://vi.stackexchange.com/users/2129", "pm_score": 0, "selected": false, "text": "<p>I think I found the 'potentially' culprit. I would love an explanation if anyone can explain it.</p>\n\n<p>These two...
2015/12/11
[ "https://vi.stackexchange.com/questions/5800", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2129/" ]
Hi I am having some issue trying to unmap this key in my .**vimrc**. I've tried a lot of suggestions and remapping but it seems to be resetting itself every time. ``` unamp <Esc> unmap! <Esc> map <Esc>^[ <Esc>^[ map <Esc> <Nop> ``` Everytime I open a file in vim and type the following in command mode: ``` :map <Es...
`Ctrl`-`[` [is the the same as ESC](http://vim.wikia.com/wiki/Avoid_the_escape_key), as mentioned in `:help <Esc>`: ``` notation meaning equivalent decimal value(s) ~ ----------------------------------------------------------------------- <Nul> zero CTRL-@ 0 (stored as 10) *<Nul>* <B...
5,804
<p>I want to zoom in VIM, like Sublime text or Atom, using <code>CTRL +</code> &amp; <code>CTRL -</code> and <code>CTRL 0</code> for reset to default font-size.</p>
[ { "answer_id": 5805, "author": "apparat", "author_id": 5331, "author_profile": "https://vi.stackexchange.com/users/5331", "pm_score": 5, "selected": true, "text": "<p>If you are using vim in a terminal you can simply use its zoom shortcuts. For Gnome-Terminal this is <kbd>Ctrl</kbd>+<kbd...
2015/12/12
[ "https://vi.stackexchange.com/questions/5804", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5631/" ]
I want to zoom in VIM, like Sublime text or Atom, using `CTRL +` & `CTRL -` and `CTRL 0` for reset to default font-size.
If you are using vim in a terminal you can simply use its zoom shortcuts. For Gnome-Terminal this is `Ctrl`+`+`. In others it may be `Ctrl`+`Shift`+`+`. Also there are several plugins out there for this purpose. e.x: <https://github.com/drmikehenry/vim-fontsize> As an alternative you can define your own functions lik...
5,806
<p>I know many ways to copy things:</p> <p><code>yiw</code> = yank in current word<br> <code>yaw</code> = yank all word (includes a trailing space)<br> <code>yy</code> = yank the current line<br> <code>3yy</code> = yank three lines starting at the current one<br> <code>yap</code> = yank all paragraph (includes traili...
[ { "answer_id": 5811, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 8, "selected": true, "text": "<p>Composing the yank operation with the so often used \"one character to the right\" motion should work: <code>yl</code>. ...
2015/12/12
[ "https://vi.stackexchange.com/questions/5806", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1111/" ]
I know many ways to copy things: `yiw` = yank in current word `yaw` = yank all word (includes a trailing space) `yy` = yank the current line `3yy` = yank three lines starting at the current one `yap` = yank all paragraph (includes trailing newline) I can also delete or change a single character: `x` = d...
Composing the yank operation with the so often used "one character to the right" motion should work: `yl`. BTW (to comment on a OP comment), for me `»` can be yanked in this manner, in gVim or terminal Vim. Perhaps a (file)encoding issue?
5,819
<p>I have words like <code>lblSERINOd</code> in sentences. Words are separated by white space.</p> <p>I want to replace the <code>d</code> at the end of all such words with <code>u</code>. So for example <code>lblSERINOd</code> will look like <code>lblSERINOu</code>.</p> <p>I have tried <code>s/.*\ud /u /g</code> but...
[ { "answer_id": 5821, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 4, "selected": true, "text": "<p>One way to do it would be this:</p>\n\n<pre><code>:%s/\\u\\zsd\\&gt;/u/g\n</code></pre>\n\n<p>Initially I assumed that t...
2015/12/14
[ "https://vi.stackexchange.com/questions/5819", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4840/" ]
I have words like `lblSERINOd` in sentences. Words are separated by white space. I want to replace the `d` at the end of all such words with `u`. So for example `lblSERINOd` will look like `lblSERINOu`. I have tried `s/.*\ud /u /g` but Vim says it cannot find `.*\ud`. What is the problem here?
One way to do it would be this: ``` :%s/\u\zsd\>/u/g ``` Initially I assumed that the new Vim regex engine (being advertised as "faster, but limited") can't understand `\u` in `:substitute`, but this isn't the case. I *rather* think now that the OP forgot to use `%` and simply searched on the wrong line; this would ...
5,823
<p>My Vim config includes <a href="http://goo.gl/dQVhzo" rel="nofollow">plugins that try to handle current project, build tags, etc</a>. This is quite useful for my daily programming in Vim, but it's just annoying when I use Vim for some quick edits, like:</p> <ul> <li>edit a git commit message;</li> <li>edit a shell ...
[ { "answer_id": 5824, "author": "gniourf_gniourf", "author_id": 963, "author_profile": "https://vi.stackexchange.com/users/963", "pm_score": 4, "selected": true, "text": "<p>There are (at least) two possibilities:</p>\n\n<ol>\n<li><p>use <code>env</code>:</p>\n\n<pre><code>EDITOR='/usr/bi...
2015/12/12
[ "https://vi.stackexchange.com/questions/5823", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2913/" ]
My Vim config includes [plugins that try to handle current project, build tags, etc](http://goo.gl/dQVhzo). This is quite useful for my daily programming in Vim, but it's just annoying when I use Vim for some quick edits, like: * edit a git commit message; * edit a shell command when I type `Ctrl+x``Ctrl+e` in zsh or ...
There are (at least) two possibilities: 1. use `env`: ``` EDITOR='/usr/bin/env VIM_LIGHT_MODE=1 vim' ``` 2. use `vim` with another initialization file, say `.vimrc-light`: ``` EDITOR='/usr/bin/vim -u ~/.vimrc-light' ```
5,829
<p>When starting vim in a mingw64 terminal emulator on windows, the command <code>:py print(1)</code> fails, saying</p> <pre><code>Could not load library msys-python2.7.dll Sorry, this command is disabled, the Python library could not be loaded. </code></pre> <p>My vim installation DOES have python support, as <code>...
[ { "answer_id": 5831, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>The <code>:help python-dynamic</code> mentions the following:</p>\n\n<blockquote>\n <p>To use the Python interface the P...
2015/12/15
[ "https://vi.stackexchange.com/questions/5829", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2455/" ]
When starting vim in a mingw64 terminal emulator on windows, the command `:py print(1)` fails, saying ``` Could not load library msys-python2.7.dll Sorry, this command is disabled, the Python library could not be loaded. ``` My vim installation DOES have python support, as `vim --version` shows both `python/dyn` as...
The `:help python-dynamic` mentions the following: > > To use the Python interface the Python DLL must be in your search > path. In a console window type "path" to see what directories are > used. > > > The name of the DLL must match the Python version Vim was compiled > with. Currently the name is "python24.dll...
5,835
<p>I currently deal with lots of json files and am quite fond of the bash comand <code>jq</code>, e.g. if I want to format the file I do</p> <pre><code>jq . ugly.json &gt; formated.json </code></pre> <p>Now, I don't want to leave vim, but run it directly within my current open file.</p> <p>How can I do it?</p> <p>I...
[ { "answer_id": 5836, "author": "k0pernikus", "author_id": 5449, "author_profile": "https://vi.stackexchange.com/users/5449", "pm_score": 4, "selected": false, "text": "<p>By sheer luck I found out that both:</p>\n\n<pre><code>:%!jq . %\n</code></pre>\n\n<p>or shorter:</p>\n\n<pre><code>:...
2015/12/15
[ "https://vi.stackexchange.com/questions/5835", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
I currently deal with lots of json files and am quite fond of the bash comand `jq`, e.g. if I want to format the file I do ``` jq . ugly.json > formated.json ``` Now, I don't want to leave vim, but run it directly within my current open file. How can I do it? I tried: ``` :!jq . % ``` `!` runs a bash command `%...
`:!{cmd}` sends `{cmd}` to the shell which executes it and shows its output on the screen. `:{range}!{filter}` sends the lines from the current buffer inside `{range}` as the input of the `{filter}` program and replaces them with its output. In your example, `:%!jq` : * `%` is the range, which means: *all the lines ...
5,851
<p>I want to teach myself to prefer hjkl more over the arrow keys in order to stay on the home row. (I am very aware that <a href="http://vimcasts.org/blog/2013/02/habit-breaking-habit-making/" rel="noreferrer">one should not use hjkl as the main navigation keys</a> as there are more powerful movement commands availabl...
[ { "answer_id": 5852, "author": "Amadan", "author_id": 4729, "author_profile": "https://vi.stackexchange.com/users/4729", "pm_score": 6, "selected": true, "text": "<p>You can install the <a href=\"https://github.com/wikitopian/hardmode\" rel=\"noreferrer\">hardmode plugin</a> and in your ...
2015/12/17
[ "https://vi.stackexchange.com/questions/5851", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
I want to teach myself to prefer hjkl more over the arrow keys in order to stay on the home row. (I am very aware that [one should not use hjkl as the main navigation keys](http://vimcasts.org/blog/2013/02/habit-breaking-habit-making/) as there are more powerful movement commands available yet this is more about breaki...
You can install the [hardmode plugin](https://github.com/wikitopian/hardmode) and in your `.vimrc` put in ``` let g:HardMode_level = 'wannabe' let g:HardMode_hardmodeMsg = 'Don''t use this!' autocmd VimEnter,BufNewFile,BufReadPost * silent! call HardMode() ``` If you don't want to use a plugin (which may be a better...
5,853
<p>I have the following code:</p> <pre><code>namespace { template&lt;typename T&gt; struct One // This is the odd line { // impl details } template&lt;typename T&gt; struct Two { // impl details } } </code></pre> <p>I would want to change the indent rules to make it look like this:</p> <pre><code...
[ { "answer_id": 25197, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 2, "selected": false, "text": "<p>This is <code>:h cino-+</code>.</p>\n\n<p>It looks like <code>get_c_indent()</code> (from <code>src/cindent.c</code>) do...
2015/12/17
[ "https://vi.stackexchange.com/questions/5853", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5693/" ]
I have the following code: ``` namespace { template<typename T> struct One // This is the odd line { // impl details } template<typename T> struct Two { // impl details } } ``` I would want to change the indent rules to make it look like this: ``` namespace { template<typename T> struct One {...
``` " tell which cinoption take effect for current line com! WhichCinoption call s:which_cinoption() function s:which_cinoption() abort " test if cindent take effect if !empty(&indentexpr) echo "'indentexpr' exists, it overrides 'cindent'." return endif if !&cindent echo "'cindent' is currently d...
5,864
<p>In my vimrc I have the following:</p> <pre><code>vmap Q gw nmap Q gwap set formatoptions+=cj set formatoptions-=t </code></pre> <p>This disables automatic text wrapping, and allows me to correctly wrap the paragraph my cursor is on right now by pressing <kbd>Shift</kbd>+<kbd>Q</kbd>.</p> <p>Normally, formatting a...
[ { "answer_id": 5877, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>The problem is, your motion \"<a href=\"https://vimhelp.appspot.com/motion.txt.html#ap\" rel=\"nofollow\">ap</a>\...
2015/12/17
[ "https://vi.stackexchange.com/questions/5864", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/260/" ]
In my vimrc I have the following: ``` vmap Q gw nmap Q gwap set formatoptions+=cj set formatoptions-=t ``` This disables automatic text wrapping, and allows me to correctly wrap the paragraph my cursor is on right now by pressing `Shift`+`Q`. Normally, formatting a paragraph is exactly what I want to do, but here's...
The problem is, your motion "[ap](https://vimhelp.appspot.com/motion.txt.html#ap)" moves to the end of a paragraph. And a [paragraph](https://vimhelp.appspot.com/motion.txt.html#paragraph) is defined as: ``` A paragraph begins after each empty line, and also at each of a set of paragraph macros, specified by the pairs...
5,869
<p>In bash one can edit the current commandline in <code>$EDITOR</code> by pressing <code>&lt;c-x&gt;&lt;c-e&gt;</code>.</p> <p>I am running bash inside a terminal buffer within Neovim. I would like to be able to press <code>&lt;c-x&gt;&lt;c-e&gt;</code> and have Neovim open a new buffer (<code>:new</code>), in the sa...
[ { "answer_id": 5871, "author": "Brett Y", "author_id": 1472, "author_profile": "https://vi.stackexchange.com/users/1472", "pm_score": 3, "selected": true, "text": "<p>I've now turned the script below into a plugin: <a href=\"https://github.com/brettanomyces/nvim-editcommand\" rel=\"nofol...
2015/12/17
[ "https://vi.stackexchange.com/questions/5869", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1472/" ]
In bash one can edit the current commandline in `$EDITOR` by pressing `<c-x><c-e>`. I am running bash inside a terminal buffer within Neovim. I would like to be able to press `<c-x><c-e>` and have Neovim open a new buffer (`:new`), in the same Neovim instance, with the current contents of the commandline. When I close...
I've now turned the script below into a plugin: [nvim-editcommand](https://github.com/brettanomyces/nvim-editcommand), or if you don't mind starting you terminals with a plugin command [nvim-terminus](https://github.com/brettanomyces/nvim-terminus) provides a few more features --- Finally got it working in pure (ugly...
5,878
<p>Today, I found my <code>.vimrc</code> didn't take effect. It was ok just hours ago.</p> <p>When I launched vim with <code>$vim --plugin</code>, <code>:scriptnames</code> echoed nothing: <code>.vimrc</code> file was not sourced. (Note: <code>/etc/vimrc</code> was removed to debug this problem.) </p> <p>Then I tried...
[ { "answer_id": 5882, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 3, "selected": false, "text": "<p>You probably misunderstood the documentation:</p>\n\n<blockquote>\n<pre><code> c. Four places are searched for initializa...
2015/12/18
[ "https://vi.stackexchange.com/questions/5878", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5510/" ]
Today, I found my `.vimrc` didn't take effect. It was ok just hours ago. When I launched vim with `$vim --plugin`, `:scriptnames` echoed nothing: `.vimrc` file was not sourced. (Note: `/etc/vimrc` was removed to debug this problem.) Then I tried to google and found `$VIMINIT` variable suspicious. Here is the value...
Expanding on @mMontu's answer; Vim hunts for initialization in order of that list till it finds one. Since the `$VIMINIT` variable take precedent to the `.vimrc` file, it satisfies the search and any other option after that is **ignored**. The reason it still didn't work after: ``` $ VIMINIT= $ echo $VIMINIT ``` Is...
5,886
<p>I have a rather long chat transcript that I copied out of a window, and when I pasted it into vim, it put two line breaks after every username, and then what the user typing said. I'd like to:</p> <ol> <li>Search for the <code>&gt;</code> character</li> <li>Go to the top of the file.</li> <li>Start recording the m...
[ { "answer_id": 5887, "author": "Steve", "author_id": 4655, "author_profile": "https://vi.stackexchange.com/users/4655", "pm_score": 3, "selected": false, "text": "<p>One way of deleting two new lines after every <code>&gt;</code> is as follows</p>\n\n<pre><code>:%s/&gt;\\n\\n/&gt; /\n</c...
2015/12/18
[ "https://vi.stackexchange.com/questions/5886", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
I have a rather long chat transcript that I copied out of a window, and when I pasted it into vim, it put two line breaks after every username, and then what the user typing said. I'd like to: 1. Search for the `>` character 2. Go to the top of the file. 3. Start recording the macro 4. Move to the next match. 5. Press...
As steve pointed out, `:%s/>\n\n/> /` is useful here (although the `g` flag he used is superfluous.) I want to mention another command that is applicable here: the "join" command, which is `J`. So for a macro you could use: `ggqq/>$``Enter``JJq999@q` Explanation: ``` gg # Move to start of file q...
5,898
<p>There is a file with name <code>./folderA/folderB/file.</code>.</p> <p>And there is text: </p> <pre><code>./folderA/folderB/file.:abcdefg </code></pre> <p>When I move the cursor on letter <code>B</code> and type <code>&lt;c-w&gt;f</code>, it says </p> <pre><code>E447: Can't find file "./folderA/folderB/file" in ...
[ { "answer_id": 5900, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 3, "selected": false, "text": "<p>From <code>:help gf</code>:</p>\n\n<pre><code>Trailing punctuation characters \".,:;!\" are ignored.\n</code></pre>\n\n<...
2015/12/20
[ "https://vi.stackexchange.com/questions/5898", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1080/" ]
There is a file with name `./folderA/folderB/file.`. And there is text: ``` ./folderA/folderB/file.:abcdefg ``` When I move the cursor on letter `B` and type `<c-w>f`, it says ``` E447: Can't find file "./folderA/folderB/file" in path ``` Note that the file name is `file.`. There is a dot at the end of the fil...
Another option is to set `includeexpr`. From `:help includeexpr`: ``` *'includeexpr'* *'inex'* 'includeexpr' 'inex' string (default "") local to buffer {not in Vi} {not available when compiled without the ...
5,901
<p>I am using neovim with qt-neovim (linux arch). On gvim I could launch a maximized window with:</p> <pre><code>if has(&quot;gui_running&quot;) set lines 999 columns 999 endif </code></pre> <p>That is not working now though. I tried removing the <code>if</code> without success. Is there any way I can achieve that?...
[ { "answer_id": 6969, "author": "Ingo", "author_id": 3343, "author_profile": "https://vi.stackexchange.com/users/3343", "pm_score": 2, "selected": false, "text": "<p>The reason seems to stem from the fact that neovim sets <code>gui_running</code> only <em>after</em> your <code>.vimrc</cod...
2015/12/20
[ "https://vi.stackexchange.com/questions/5901", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5732/" ]
I am using neovim with qt-neovim (linux arch). On gvim I could launch a maximized window with: ``` if has("gui_running") set lines 999 columns 999 endif ``` That is not working now though. I tried removing the `if` without success. Is there any way I can achieve that?
Try putting ``` call rpcnotify(0, 'Gui', 'WindowMaximized', 1) ``` in your `ginit.vim`. I haven't tested on Linux, but it works on Windows 7.
5,902
<p>I would like to use the normal commands <code>g,</code> and <code>g;</code> more often to navigate through the change list. </p> <p>The problem is I usually don't know how far I am in the change list from the edit I'm interested in and I have to repeat the commands many times to reach it.<br> Usually, what I do is...
[ { "answer_id": 5903, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 3, "selected": true, "text": "<p>There is no way of accomplishing this by default. However, you can capture the output of the <code>:changes</code> c...
2015/12/20
[ "https://vi.stackexchange.com/questions/5902", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4939/" ]
I would like to use the normal commands `g,` and `g;` more often to navigate through the change list. The problem is I usually don't know how far I am in the change list from the edit I'm interested in and I have to repeat the commands many times to reach it. Usually, what I do is : * use the Ex command `:changes...
There is no way of accomplishing this by default. However, you can capture the output of the `:changes` command with the `:redir` command and paste it into a new split buffer. Here is my implementation: ``` command! ChangeList call <SID>ChangeList() function! s:ChangeList() abort " Save z register let l:oldz ...
5,905
<p>I don't know if there's some function to check a window's position, I mean is it currently sitting at bottom or top, left or right??</p> <pre><code>__________________________ | | | | | | | left | right | | | | | | | |_____...
[ { "answer_id": 5906, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 3, "selected": false, "text": "<p>I don't think there is any way to check this, unfortunately.</p>\n\n<p>There might be a way to make a custom funct...
2015/12/21
[ "https://vi.stackexchange.com/questions/5905", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1276/" ]
I don't know if there's some function to check a window's position, I mean is it currently sitting at bottom or top, left or right?? ``` __________________________ | | | | | | | left | right | | | | | | | |___________|_______...
Summing up the comments of the question: > > -- I'm trying to write a function to rotate window splits to vertical if > current layout it's horizontal and vice versa when there're just two > windows. > > > -- Why not simply use ctrl-W\_L? (or ctrl-W\_R) > > > -- I want it to be convenient toggle function, it wi...
5,921
<p>Right now I'm using fugitive to manage almost everything git related, but I can't find a good workflow to quickly visualize and switch between available branches.</p> <p>I can do <code>:Git checkout &lt;branch-name&gt;</code>, the problem is that it autocompletes both file names and branches, and I'd prefer a branc...
[ { "answer_id": 5925, "author": "65-e9-7e-17", "author_id": 5763, "author_profile": "https://vi.stackexchange.com/users/5763", "pm_score": 3, "selected": false, "text": "<p>You should embrace your terminal. If you use <kbd>CTRL-Z</kbd>, it will background Vim (or whichever process you are...
2015/12/22
[ "https://vi.stackexchange.com/questions/5921", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3216/" ]
Right now I'm using fugitive to manage almost everything git related, but I can't find a good workflow to quickly visualize and switch between available branches. I can do `:Git checkout <branch-name>`, the problem is that it autocompletes both file names and branches, and I'd prefer a branch list.
To summarize the answers, here are the ways to accomplish this: Vanilla Terminal Vim in a shell with job control ------------------------------------------------ Press `CTRL`-`Z` in normal mode will drop you back in to the shell and suspend Vim. After executing your `git checkout [branchname]`, run the `fg` builtin t...
5,941
<p>While working in various source files, (C, Ruby, etc.) I find that I'm often hunting around for functions. Is there a way to have an auto-generated HUD that lists the structure of the current file? It would be fantastic if it linked to different <em>parts</em> of the file, similar to how NERDTree links to different ...
[ { "answer_id": 5943, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": true, "text": "<p>You could try either <a href=\"http://vim-taglist.sourceforge.net/\">TagList</a> or <a href=\"http://majutsushi.github.io/tag...
2015/12/24
[ "https://vi.stackexchange.com/questions/5941", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4748/" ]
While working in various source files, (C, Ruby, etc.) I find that I'm often hunting around for functions. Is there a way to have an auto-generated HUD that lists the structure of the current file? It would be fantastic if it linked to different *parts* of the file, similar to how NERDTree links to different files. Or,...
You could try either [TagList](http://vim-taglist.sourceforge.net/) or [TagBar](http://majutsushi.github.io/tagbar/) but such a list could be generated as needed (no third party tool or configuration needed) with a simple: ``` :g/func/# ``` See `:help :global`. If you don't mind a little bit of per-filetype configu...
5,949
<p>I have the following in my vimrc:</p> <pre><code>func! AddSpaceBeforeEqual() s/\([a-z)_0-9"'\[\]]\)=/\1 =/ge endfunc </code></pre> <p>I'm using <a href="https://github.com/Kuniwak/vint">vint</a> to lint my vimrc, and got the following warning : </p> <blockquote> <p><strong>ProhibitCommandWithUnintendedSideEff...
[ { "answer_id": 5952, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 4, "selected": false, "text": "<p>The reason it is warning you about unintended side effects is because <code>:substitute</code> does move the cursor ...
2015/12/24
[ "https://vi.stackexchange.com/questions/5949", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1543/" ]
I have the following in my vimrc: ``` func! AddSpaceBeforeEqual() s/\([a-z)_0-9"'\[\]]\)=/\1 =/ge endfunc ``` I'm using [vint](https://github.com/Kuniwak/vint) to lint my vimrc, and got the following warning : > > **ProhibitCommandWithUnintendedSideEffect** Avoid commands with unintended side effects. Avoid usi...
The reason it is warning you about unintended side effects is because `:substitute` does move the cursor and overwrite the previous search *(if used outside of a function)*. However, this does not mean you shouldn't use it, as you can reverse the side effects of `:substitute`. For example, here is a function I made tha...
5,959
<p>I'm trying to set up normal mode mappings to make it easy to add white space around the cursor:</p> <p><code>&lt;C-h&gt;</code> will add one space to the right of the cursor;<br> <code>&lt;C-j&gt;</code> will add a newline below;<br> <code>&lt;C-k&gt;</code> will add a newline above;<br> <code>&lt;C-l&gt;</code> wi...
[ { "answer_id": 5960, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 4, "selected": true, "text": "<p>You can set a local mark to where you're before opening a new line, and go back to this mark afterwards.</p>\n\n<p>You ca...
2015/12/25
[ "https://vi.stackexchange.com/questions/5959", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2593/" ]
I'm trying to set up normal mode mappings to make it easy to add white space around the cursor: `<C-h>` will add one space to the right of the cursor; `<C-j>` will add a newline below; `<C-k>` will add a newline above; `<C-l>` will add one space to the right of the cursor; and `<C-Enter>` will add a newlin...
You can set a local mark to where you're before opening a new line, and go back to this mark afterwards. You can choose any letter for the mark, let's say for example `x`: ``` nnoremap <C-k> mxO<esc>`x nnoremap <C-j> mxo<esc>`x ``` * `mx` sets the mark `x` where the cursor is * ``x` moves the cursor back to the pos...
5,982
<p>Have been reading vim scripting posts for an hour, but I'm afraid I don't have the skills to apply these posts to my problem. Editing math in latex documents, I'm frequently wanting to replace math symbols such as +, -, = with \Pad{+}, \Pad{-}, \Pad{=}, where \Pad is a latex macro I've defined to put space around...
[ { "answer_id": 5983, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 4, "selected": true, "text": "<pre><code>function! s:PadMacro(type) abort\n if a:type ==# 'char'\n normal! `[v`]d\n elseif a:type ==# 'line'\...
2015/12/29
[ "https://vi.stackexchange.com/questions/5982", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4667/" ]
Have been reading vim scripting posts for an hour, but I'm afraid I don't have the skills to apply these posts to my problem. Editing math in latex documents, I'm frequently wanting to replace math symbols such as +, -, = with \Pad{+}, \Pad{-}, \Pad{=}, where \Pad is a latex macro I've defined to put space around the s...
``` function! s:PadMacro(type) abort if a:type ==# 'char' normal! `[v`]d elseif a:type ==# 'line' normal! '[V']d elseif a:type ==# 'v' normal! `<v`>d else return endif let string = '\Pad{' . @" . '}' silent execute "normal! i\<c-r>=string\r" endfunction nnorem...
5,989
<p>I want to run the following shell.</p> <pre><code>wea-this is the end of the second word | vim j exit 0 </code></pre> <p>Which I had hoped would pipe the key strokes <code>w</code> (move forward a word) then <code>e</code> (end of the word) then <code>a</code> (append) then <code>-this is the end of the second wor...
[ { "answer_id": 5990, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 5, "selected": true, "text": "<p>To insert the string <code>\"hello\"</code> on the first line of the file <code>j</code>, you could type in your shell th...
2015/12/29
[ "https://vi.stackexchange.com/questions/5989", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2695/" ]
I want to run the following shell. ``` wea-this is the end of the second word | vim j exit 0 ``` Which I had hoped would pipe the key strokes `w` (move forward a word) then `e` (end of the word) then `a` (append) then `-this is the end of the second word` (text) to the Vim document named `j` which already has words ...
To insert the string `"hello"` on the first line of the file `j`, you could type in your shell the following command: `vim +"1 | put! ='hello'" j` * `:1` moves the cursor to the first line of the buffer * `:put! ='hello'` pastes the string "hello" above the current line To insert the string `"hello"` and then save a...
5,995
<p>I'm used to set marks with <code>m&lt;char&gt;</code> where <code>&lt;char&gt;</code> is any character I choose and then reaching the marks with <code>]`</code> or <code>[`</code>.</p> <p>I'm wondering if it is possible to use a command to set a mark with an <strong>incremental index</strong> instead of a character...
[ { "answer_id": 5996, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 2, "selected": false, "text": "<p>I'm not sure I understood what you wanted. But if you want to cycle through all the available local marks from <code>a</...
2015/12/30
[ "https://vi.stackexchange.com/questions/5995", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5707/" ]
I'm used to set marks with `m<char>` where `<char>` is any character I choose and then reaching the marks with `]`` or `[``. I'm wondering if it is possible to use a command to set a mark with an **incremental index** instead of a character, avoiding to override marks previously set.
There is nothing built in to vim, but you can script something like this: ``` fu! s:IncrementalMark() abort let b:index_mark=get(b:, 'index_mark', -1)+1 " configure, which marks to use let marks='abcdefghijklmnopqrstuvwxyz' return 'm'.marks[b:index_mark%strlen(marks)] endfu nnoremap <silent><expr> <lea...
5,998
<p>From Vim's help document (see: <code>:help 'path'</code>):</p> <blockquote> <p>'path' String(default on Unix: "<code>.,/usr/include,,</code>")</p> <p>-To search relative to the directory of the current file, use:</p> <pre><code>:set path=. </code></pre> <p>-To search in the current directory use an emp...
[ { "answer_id": 5999, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": true, "text": "<p>\"Current directory\" and \"directory of the current file\" are two different things.</p>\n\n<p>The \"current directory\" is ...
2015/12/30
[ "https://vi.stackexchange.com/questions/5998", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5510/" ]
From Vim's help document (see: `:help 'path'`): > > 'path' String(default on Unix: "`.,/usr/include,,`") > > > -To search relative to the directory of the current file, use: > > > > ``` > :set path=. > > ``` > > -To search in the current directory use an empty string between two commas: > > > > ``` > :set p...
"Current directory" and "directory of the current file" are two different things. The "current directory" is by default the directory in which you started Vim. You ask Vim what it is with `:pwd` and change it with `:cd` or `:lcd` or by setting the `autochdir` option. If you never change it, it will stay the same until...
6,008
<p>I would like to join lines together only for lines which have certain pattern (such as <code>;</code>), however when using <code>g/;/j</code> it doesn't work as expected unless called couple of times.</p> <p>For example the following content:</p> <pre><code>a 1; 2; 3; 4; 5; b 6; 7; 8; 9; c </code></pre> <p>when u...
[ { "answer_id": 6009, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 5, "selected": true, "text": "<p><strong>Possible explanation of the problem</strong></p>\n\n<p>I think the reason why <code>:g/;/j</code> doesn't work is...
2015/12/31
[ "https://vi.stackexchange.com/questions/6008", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/467/" ]
I would like to join lines together only for lines which have certain pattern (such as `;`), however when using `g/;/j` it doesn't work as expected unless called couple of times. For example the following content: ``` a 1; 2; 3; 4; 5; b 6; 7; 8; 9; c ``` when using: `:g/;/j` the output is: ``` a 1; 2; 3; 4; 5; b 6...
**Possible explanation of the problem** I think the reason why `:g/;/j` doesn't work is because the `:g` command operates with a 2-pass algorithm: * during the first pass it marks the lines containing the pattern `;` * during the second pass it operates on the marked lines During the second pass, `:g` joins the line...
6,019
<p>I often write functions in my <code>~/.vimrc</code> or in <code>~/.vim/autoload/myfunctions.vim</code>, which when executed result in an error such as: </p> <pre><code>Error detected while processing function SomeFunction: line xx: </code></pre> <p>Those errors can be read in the output of the Ex command <code>...
[ { "answer_id": 6022, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>I don't have a complete solution for you but most complex plugins have some kind of logging function for handling errors in ...
2016/01/01
[ "https://vi.stackexchange.com/questions/6019", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4939/" ]
I often write functions in my `~/.vimrc` or in `~/.vim/autoload/myfunctions.vim`, which when executed result in an error such as: ``` Error detected while processing function SomeFunction: line xx: ``` Those errors can be read in the output of the Ex command `:messages`. Is there a way to populate the quickfix...
A [recent question on SO](https://stackoverflow.com/a/34078655/15934) inspired me to develop a [function that decodes `v:throwpoint`](https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/exception.vim) that I use in a new [logger](https://github.com/LucHermitte/lh-vim-lib/commit/268a18a5c9af7e5f411934a67f2...
6,025
<p>When I want to recursively search files for a text pattern I use</p> <pre><code>:grep -R 'color:' . </code></pre> <p>Vim then lists the results in a quicklist window for easy access.<br> But now I need to perform another grep pass to exclude some results.<br> So far I have tried</p> <pre><code>:grep -R 'color:' ....
[ { "answer_id": 6027, "author": "trailing slash", "author_id": 5871, "author_profile": "https://vi.stackexchange.com/users/5871", "pm_score": 3, "selected": false, "text": "<p>The reason the pipe isn't functioning like you'd expect is because you're not grepping through the shell, you're ...
2016/01/02
[ "https://vi.stackexchange.com/questions/6025", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
When I want to recursively search files for a text pattern I use ``` :grep -R 'color:' . ``` Vim then lists the results in a quicklist window for easy access. But now I need to perform another grep pass to exclude some results. So far I have tried ``` :grep -R 'color:' . \| grep -v '@' ``` result: empty lis...
The reason the pipe isn't functioning like you'd expect is because you're not grepping through the shell, you're grepping through Vim (see digression). For instance, this would be using your shell from Vim to perform your search: ``` :!grep -R 'color:' . | grep -v '@' ``` Note the `!` at the beginning, which means "...
6,029
<p>I want to make a mapping that does the following:</p> <pre><code>nnoremap &lt;F1&gt; oHello, (user inputs their name. Ex. Jason). You have a very nice name.&lt;ESC&gt; </code></pre> <p>This mapping should make a non-recursive map to F1 that starts a new line in insert mode. Next it types "Hello, " then waits for t...
[ { "answer_id": 6030, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 4, "selected": true, "text": "<p>You can use a mapping with the <code>&lt;expr&gt;</code> flag to achieve this. Mappings with the <code>&lt;expr&gt;<...
2016/01/02
[ "https://vi.stackexchange.com/questions/6029", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2695/" ]
I want to make a mapping that does the following: ``` nnoremap <F1> oHello, (user inputs their name. Ex. Jason). You have a very nice name.<ESC> ``` This mapping should make a non-recursive map to F1 that starts a new line in insert mode. Next it types "Hello, " then waits for the user to type their name and then en...
You can use a mapping with the `<expr>` flag to achieve this. Mappings with the `<expr>` flag will evaluate the right hand side of the mapping as an expression and then apply the result as key strokes. This can be combined with the `input()` function to achieve what you want. Here is your mapping implemented with these...
6,032
<p>I want to use the combination <code>gggqG</code> to go to the top of the file and format the whole file from there, so that it fits into my 80 col textwidth border.</p> <p>But when I do, vim ignores my markdown headers. So I want basically to ignore all markdown headers for formatting. How can I do that?</p> <p><s...
[ { "answer_id": 6034, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 4, "selected": true, "text": "<p>Since you don't have wrapping for comments enabled, the workaround in <a href=\"https://stackoverflow.com/a/2686502/2072269\">...
2016/01/02
[ "https://vi.stackexchange.com/questions/6032", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2354/" ]
I want to use the combination `gggqG` to go to the top of the file and format the whole file from there, so that it fits into my 80 col textwidth border. But when I do, vim ignores my markdown headers. So I want basically to ignore all markdown headers for formatting. How can I do that? **before** ``` #this is a h1 ...
Since you don't have wrapping for comments enabled, the workaround in [this Stack Overflow post](https://stackoverflow.com/a/2686502/2072269) can be used: ``` set comments+=n:# set fo+=q ``` This adds `#` as a comment marker (allowing `n`esting, so that `##`, `###`, etc. also count). I'd suggest leaving a space aft...
6,045
<p>I would like to make some modification to the code of <a href="https://github.com/tpope/vim-rsi" rel="nofollow noreferrer">this plugin</a>.</p> <p>It adds / changes some default keybindings. Among them are <code>&lt;C-b&gt;</code> and <code>&lt;C-f&gt;</code> which move the cursor one character to the left / right....
[ { "answer_id": 6046, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": true, "text": "<p>You can find all the patches <a href=\"http://ftp.vim.org/pub/vim/patches/\" rel=\"nofollow\">on Vim's FTP server</a>. <code>...
2016/01/06
[ "https://vi.stackexchange.com/questions/6045", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4939/" ]
I would like to make some modification to the code of [this plugin](https://github.com/tpope/vim-rsi). It adds / changes some default keybindings. Among them are `<C-b>` and `<C-f>` which move the cursor one character to the left / right. The problem is they [break the undo sequence](https://vi.stackexchange.com/ques...
You can find all the patches [on Vim's FTP server](http://ftp.vim.org/pub/vim/patches/). `<C-g>U` was added in [patch 7.4.849](http://ftp.vim.org/pub/vim/patches/7.4/7.4.849).
6,050
<p>I've the following file (which is a simplification of the <code>hosts</code> file):</p> <pre><code>126.0.0.1 127.0.0.1 128.0.0.1 </code></pre> <p>and I'm trying to invoke the following command:</p> <pre><code>ex +g/127/d -cwq file </code></pre> <p>which is supposed to remove lines consisting <code>127</code>, th...
[ { "answer_id": 6053, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 1, "selected": false, "text": "<p>If it works with the Vim Ex mode but fails with <a href=\"http://sourceforge.net/projects/ex-vi/\" rel=\"nofollow\">Ex v4...
2016/01/07
[ "https://vi.stackexchange.com/questions/6050", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/467/" ]
I've the following file (which is a simplification of the `hosts` file): ``` 126.0.0.1 127.0.0.1 128.0.0.1 ``` and I'm trying to invoke the following command: ``` ex +g/127/d -cwq file ``` which is supposed to remove lines consisting `127`, then write and quit. It works when using `vim -e`, however it doesn't wo...
There are some problems here. First ex is made for interactive use. You can't use several -c commands. Second, and this is a specialty of the :g command, you can't separate several commands using the '|'. A `:g/127/d|wq` command would write and quit after the first match) This makes it effectively useless to add anothe...
6,061
<p>Is there a specific historical reason for this?</p> <hr> <p><strong>Background</strong> — (you can skip this part if you already understand the question.)</p> <p>As intermediate/advanced <code>vi</code> users will know, <code>y</code> is the "yank" command—it yanks (copies) the text specified by the following mov...
[ { "answer_id": 6135, "author": "Borys Serebrov", "author_id": 6013, "author_profile": "https://vi.stackexchange.com/users/6013", "pm_score": 5, "selected": true, "text": "<p>I found a paper <a href=\"https://docs.freebsd.org/44doc/usd/12.vi/paper.html\">\"An Introduction to Display Editi...
2016/01/08
[ "https://vi.stackexchange.com/questions/6061", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
Is there a specific historical reason for this? --- **Background** — (you can skip this part if you already understand the question.) As intermediate/advanced `vi` users will know, `y` is the "yank" command—it yanks (copies) the text specified by the following movement command.\* Thus `ye` yanks to the end of the wo...
I found a paper ["An Introduction to Display Editing with Vi"](https://docs.freebsd.org/44doc/usd/12.vi/paper.html) by William Joy (vi creator) and Mark Horton (vi maintainer since 1979). From the paper it is clear that the default Y behavior is not a mistake, but a desired feature. In the ["Rearranging and duplicatin...
6,063
<p>Is there any alternative in vim search and replace for strings, than having to escape every special character in string.</p> <p>For example, If I want to match following string and replace with something</p> <pre><code>[ERROR] Login unsucessful </code></pre> <p>Then I have to do </p> <pre><code>:%s/\[ERROR\]\ Lo...
[ { "answer_id": 6064, "author": "PhilippFrank", "author_id": 1296, "author_profile": "https://vi.stackexchange.com/users/1296", "pm_score": 5, "selected": true, "text": "<p>You can use the <code>very-nomagic</code> switch. See <code>:h \\V</code> for details. This would give you <code>%s/...
2016/01/08
[ "https://vi.stackexchange.com/questions/6063", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5019/" ]
Is there any alternative in vim search and replace for strings, than having to escape every special character in string. For example, If I want to match following string and replace with something ``` [ERROR] Login unsucessful ``` Then I have to do ``` :%s/\[ERROR\]\ Login\ unsucessful/something/g ``` And it be...
You can use the `very-nomagic` switch. See `:h \V` for details. This would give you `%s/\V[ERROR] Login unsuccessful/something/g`. There is also the `nomagic` switch `\M`, which is a lighter version of `\V` and does not seem to be widely used. Also note that you don't have to escape spaces as you do in your example, e...
6,070
<p>I'm trying to make Vim wait after the leader key indefinitely without messing with the <code>timeoutlen</code> of other keys. Currently I have this lines in my vimrc:</p> <pre><code>let mapleader=" " set timeoutlen=2000 ttimeoutlen=0 </code></pre> <p>Setting <code>ttimeoutlen</code> make commands such as <code>ciw...
[ { "answer_id": 6076, "author": "joeytwiddle", "author_id": 630, "author_profile": "https://vi.stackexchange.com/users/630", "pm_score": 2, "selected": false, "text": "<p>Here is a dirty workaround you could consider:</p>\n\n<pre><code>\" Increase timeoutlen when &lt;Leader&gt; is pressed...
2016/01/08
[ "https://vi.stackexchange.com/questions/6070", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2131/" ]
I'm trying to make Vim wait after the leader key indefinitely without messing with the `timeoutlen` of other keys. Currently I have this lines in my vimrc: ``` let mapleader=" " set timeoutlen=2000 ttimeoutlen=0 ``` Setting `ttimeoutlen` make commands such as `ciw` last permanently. The Spacemacs plugin for Emacs w...
Here is a dirty workaround you could consider: ``` " Increase timeoutlen when <Leader> is pressed " Only one of these lines is needed. I am not sure which is most recommended. "nmap <silent> <Leader> :<C-U>set timeoutlen=99999 ttimeoutlen=99999<CR><Leader> nnoremap <silent> <Leader> :<C-U>set timeoutlen=99999 ttimeou...
6,071
<p><code>:help section</code> states:</p> <blockquote> <p>The "]" and "[" commands stop at the '{' or '}' in the first column. This is useful to find the start or end of a function in a C program.</p> </blockquote> <p>Is it possible to change the <code>[</code> and <code>]</code> commands to jump to a different ...
[ { "answer_id": 6074, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>I stole and renamed the function below from <code>$VIMRUNTIME/ftplugin/python.vim</code>\n:</p>\n\n<pre><code>function! Custo...
2016/01/08
[ "https://vi.stackexchange.com/questions/6071", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5952/" ]
`:help section` states: > > The "]" and "[" commands stop at the '{' or '}' in the first column. This is > useful to find the start or end of a function in a C program. > > > Is it possible to change the `[` and `]` commands to jump to a different character or pattern. For example in Markdown, I would like secti...
I stole and renamed the function below from `$VIMRUNTIME/ftplugin/python.vim` : ``` function! CustomJump(motion) range let cnt = v:count1 let save = @/ mark ' while cnt > 0 silent! execute a:motion let cnt = cnt - 1 endwhile call histdel('/', -1) let @/ = save endfunction `...
6,081
<p>Sadly over time a few of my mappings have ended up overlapping.</p> <p>For example I toggle wrapping with <kbd>\w</kbd> but I later introduced <a href="https://github.com/joeytwiddle/rc_files/blob/master/.vim/plugin/change_with.vim" rel="nofollow">a mapping</a> on <kbd>\wi</kbd>. </p> <p>As a result, when I press ...
[ { "answer_id": 6082, "author": "Sakari Cajanus", "author_id": 1672, "author_profile": "https://vi.stackexchange.com/users/1672", "pm_score": 3, "selected": false, "text": "<p>It seems any key you map to <code>&lt;Nop&gt;</code> correctly terminates the mapping, without doing anything els...
2016/01/10
[ "https://vi.stackexchange.com/questions/6081", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/630/" ]
Sadly over time a few of my mappings have ended up overlapping. For example I toggle wrapping with `\w` but I later introduced [a mapping](https://github.com/joeytwiddle/rc_files/blob/master/.vim/plugin/change_with.vim) on `\wi`. As a result, when I press `\w`, Vim waits for some time to see if I will follow it with...
It seems any key you map to `<Nop>` correctly terminates the mapping, without doing anything else. With ``` set notimeout inoremap w foo inoremap ww bar inoremap <space> <Nop> ``` You can use `w<space>` to insert foo, and `ww` to insert bar. Of course, this would be the same as mapping `w<space>` in the first place,...
6,083
<p>I want to find all the characters upto the first occurence of the character "/".</p> <p>I tried using </p> <blockquote> <p>/.\{-}\/ </p> </blockquote> <p>but this included every character upto the last occurrence.</p> <p>for example, </p> <blockquote> <p>test/path/to/something</p> </blockquote> <p>matched ...
[ { "answer_id": 6084, "author": "akshay", "author_id": 246, "author_profile": "https://vi.stackexchange.com/users/246", "pm_score": 2, "selected": false, "text": "<p>Vim has start and end anchors (<code>\\zs</code> and <code>\\ze</code> respectively) that you can use. In this case, the <c...
2016/01/10
[ "https://vi.stackexchange.com/questions/6083", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5964/" ]
I want to find all the characters upto the first occurence of the character "/". I tried using > > /.\{-}\/ > > > but this included every character upto the last occurrence. for example, > > test/path/to/something > > > matched "test/path/to/" but I want it to only match "test/"
It doesn't actually match `test/path/to/` -- it matches three times: `test/`, `path/` and `to/`. If you want to match only match the first one, the easiest way is to anchor the pattern to something, for example, beginning of line: ``` /^.\{-}\/ ``` which works if you really want to match everything before. In practi...
6,100
<p>How can I remove the horrible color of my vim status bar has? I'd like it to be the same color as the background.</p> <p><a href="https://i.stack.imgur.com/wrvUg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wrvUg.png" alt="enter image description here"></a></p> <p>My current settings in my <c...
[ { "answer_id": 6116, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 2, "selected": false, "text": "<p>There are several places in the code where you specifically set the statusline background to a sort of grayish colour with co...
2016/01/11
[ "https://vi.stackexchange.com/questions/6100", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5981/" ]
How can I remove the horrible color of my vim status bar has? I'd like it to be the same color as the background. [![enter image description here](https://i.stack.imgur.com/wrvUg.png)](https://i.stack.imgur.com/wrvUg.png) My current settings in my `~./.vimrc` file (or `~/.vimrc.after` file as I use) which relate to t...
There are several places in the code where you specifically set the statusline background to a sort of grayish colour with commands like: ``` hi statusline guibg=#c5c8c6 ... ``` You need to replace these with lines like: ``` hi statusline guibg=NONE ... ``` ...to remove the colour. If your statusline background ...
6,101
<ul> <li><p>Is there a text object for current line?</p></li> <li><p>Is there a text object for <code>^$</code>?</p></li> </ul>
[ { "answer_id": 6102, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": true, "text": "<p>Here is a crude \"line\" text-objects:</p>\n\n<pre><code>xnoremap il g_o0\nonoremap il :normal vil&lt;CR&gt;\nxnoremap al $o0...
2016/01/12
[ "https://vi.stackexchange.com/questions/6101", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2082/" ]
* Is there a text object for current line? * Is there a text object for `^$`?
Here is a crude "line" text-objects: ``` xnoremap il g_o0 onoremap il :normal vil<CR> xnoremap al $o0 onoremap al :normal val<CR> ``` And a crude "buffer" text-object: ``` xnoremap i% GoggV onoremap i% :normal vi%<CR> ``` ---EDIT--- An "operator" is a command that doesn't do anything by itself: `d`, `y`, etc. P...
6,112
<p>In order to ensure that behaviour is not affected by my personal config, I want to start Vim in a way that ignores <em>all</em> my user-installed config files, as if Vim had just been freshly installed for the first time and the user had run it immediately.</p> <p>This is addressed <a href="http://vimhelp.appspot.c...
[ { "answer_id": 6114, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 4, "selected": false, "text": "<p>One way to eliminate user-specific files would be to use a different value of <code>$HOME</code>. To allow nothing to be read...
2016/01/13
[ "https://vi.stackexchange.com/questions/6112", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/343/" ]
In order to ensure that behaviour is not affected by my personal config, I want to start Vim in a way that ignores *all* my user-installed config files, as if Vim had just been freshly installed for the first time and the user had run it immediately. This is addressed [in the FAQ](http://vimhelp.appspot.com/vim_faq.tx...
As of Vim [8.0.1554](https://github.com/vim/vim/commit/072687032683b1994d25a114893d9a6f8bc36612), you can use **`vim --clean`** (or **`nvim --clean`** for Neovim). This method is recommended by [`:help bugs`](https://vimhelp.appspot.com/intro.txt.html#bugs). [`:help --clean`](https://vimhelp.appspot.com/starting.txt.h...
6,123
<p>Both <em>background</em> and <em>colorscheme</em> in <code>~/.vimrc</code> are badly misbehaving!</p> <p>I have setup <em>solarized</em> to work on <em>vim</em> and it can manually toggle between <em>background</em> <em>light</em>/<em>dark</em>. My general settings in <code>~/.vimrc</code> are:</p> <pre><code>Plug...
[ { "answer_id": 6129, "author": "Borys Serebrov", "author_id": 6013, "author_profile": "https://vi.stackexchange.com/users/6013", "pm_score": 2, "selected": false, "text": "<p>Something is definitely not right.\nI have in my .vimrc something like this:</p>\n\n<pre><code>set background=dar...
2016/01/14
[ "https://vi.stackexchange.com/questions/6123", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4617/" ]
Both *background* and *colorscheme* in `~/.vimrc` are badly misbehaving! I have setup *solarized* to work on *vim* and it can manually toggle between *background* *light*/*dark*. My general settings in `~/.vimrc` are: ``` Plug 'altercation/vim-colors-solarized' "I use plug.vim syntax enable set background=light set t...
Something is definitely not right. I have in my .vimrc something like this: ``` set background=dark colorscheme solarized ``` And when I do `:set bg?` after that, it shows "light". I think that's the reason the if/else/endif in you function doesn't work after 'colorsheme solarized'. The only workaround I can think ...
6,131
<p>I have a string like <code>'foobar'</code>, and I want to surround it with parentheses: <code>('foobar')</code>.</p> <p>With vim-surround, I can do <code>ysi')</code>, which produces <code>'(foobar)'</code>... Not what I want</p> <p>I can also <code>ysa')</code>, but that will include whitespace: <code>( 'foob...
[ { "answer_id": 6144, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 5, "selected": true, "text": "<p>It's not specific to vim-surround - <code>va'</code> also selects the leading whitespace. From <a href=\"http://vimhelp.appspo...
2016/01/15
[ "https://vi.stackexchange.com/questions/6131", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6018/" ]
I have a string like `'foobar'`, and I want to surround it with parentheses: `('foobar')`. With vim-surround, I can do `ysi')`, which produces `'(foobar)'`... Not what I want I can also `ysa')`, but that will include whitespace: `( 'foobar')`... Meh, close. In vim, I can `2yi'`, which yanks exactly what I need `'foo...
It's not specific to vim-surround - `va'` also selects the leading whitespace. From [`:h a'`](http://vimhelp.appspot.com/motion.txt.html#a%27): ``` a" v_aquote aquote a' v_a' a' a` ...
6,142
<pre><code># vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 23:36:07) # cat /root/.vimrc map &lt;F2&gt; :w\|!sh % &lt;cr&gt; map &lt;F3&gt; :w\|!bash % &lt;cr&gt; map &lt;F4&gt; :w\|!python % &lt;cr&gt; map &lt;F5&gt; :w\|!python % &amp;&lt;cr&gt; highlight RedundantWhitespace ctermbg=DarkBlue...
[ { "answer_id": 9587, "author": "Alexis Wilke", "author_id": 9276, "author_profile": "https://vi.stackexchange.com/users/9276", "pm_score": 0, "selected": false, "text": "<p>I get these with <code>CMakeList.txt</code> files. It is part of the syntax highlight mechanism. I also get it in \...
2016/01/16
[ "https://vi.stackexchange.com/questions/6142", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6039/" ]
``` # vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 23:36:07) # cat /root/.vimrc map <F2> :w\|!sh % <cr> map <F3> :w\|!bash % <cr> map <F4> :w\|!python % <cr> map <F5> :w\|!python % &<cr> highlight RedundantWhitespace ctermbg=DarkBlue guibg=red match RedundantWhitespace /\s\+$\|\t/ syntax on...
This could be an issue with vim's system for recognising and then highlighting syntactic "keywords" not getting enough context to recognise keywords. The basic concepts of vim's syntax system (finding and tagging basic syntax elements) is explained in `:h usr_44` Basically vim uses regex to recognise syntactic eleme...
6,146
<p>I am taking notes in an outline format that looks like this:</p> <pre><code>* Micro topic 1 ** Microbes are small ** You can't see them! *** Isn't that something? * Micro topic 2 ** I hope I like the teacher *** She will be great! ** Micro is cool! </code></pre> <p>where one star is a top level heading, and more s...
[ { "answer_id": 9587, "author": "Alexis Wilke", "author_id": 9276, "author_profile": "https://vi.stackexchange.com/users/9276", "pm_score": 0, "selected": false, "text": "<p>I get these with <code>CMakeList.txt</code> files. It is part of the syntax highlight mechanism. I also get it in \...
2016/01/18
[ "https://vi.stackexchange.com/questions/6146", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6053/" ]
I am taking notes in an outline format that looks like this: ``` * Micro topic 1 ** Microbes are small ** You can't see them! *** Isn't that something? * Micro topic 2 ** I hope I like the teacher *** She will be great! ** Micro is cool! ``` where one star is a top level heading, and more stars indicate subheadings ...
This could be an issue with vim's system for recognising and then highlighting syntactic "keywords" not getting enough context to recognise keywords. The basic concepts of vim's syntax system (finding and tagging basic syntax elements) is explained in `:h usr_44` Basically vim uses regex to recognise syntactic eleme...
6,148
<p>Vim's popup menu is a very cool and modern feature. However, if the list is very long (such as completion) and I keep pressing <code>&lt;C-N&gt;</code> to navigate through the menu quickly, the popup menu will flash to refresh the content, which is sometimes a little dizzy.<br/> So what may be the cause? Is this a l...
[ { "answer_id": 6149, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 1, "selected": false, "text": "<blockquote>\n <p>So what may be the cause? Is this a limit of the terminal or is there\n any plugin which make Vim ineffi...
2016/01/18
[ "https://vi.stackexchange.com/questions/6148", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4754/" ]
Vim's popup menu is a very cool and modern feature. However, if the list is very long (such as completion) and I keep pressing `<C-N>` to navigate through the menu quickly, the popup menu will flash to refresh the content, which is sometimes a little dizzy. So what may be the cause? Is this a limit of the terminal o...
I think this is an issue with Vim itself. When exploring the popup menu with Ctrl-N or Ctrl-P, Vim replaces your text with the highlighted item, which implies switching back-and-forth between the menu and the window behind it. You can bypass the issue by using the up and down arrows instead of Ctrl-P and Ctr-N, because...
6,150
<p>I'm trying to tune the highlighting in my vim and I'm trying to set some syntax groups via the <code>match</code> command and highlight them in my <code>vimrc</code> file, because those groups are generic and do not belong to any particular language syntax file.</p> <p>But my approach works only for a single highli...
[ { "answer_id": 6151, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>From <code>:help :match</code></p>\n\n<blockquote>\n <p>Highlighting matches using :match are limited to three<br>\n matches...
2016/01/18
[ "https://vi.stackexchange.com/questions/6150", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2798/" ]
I'm trying to tune the highlighting in my vim and I'm trying to set some syntax groups via the `match` command and highlight them in my `vimrc` file, because those groups are generic and do not belong to any particular language syntax file. But my approach works only for a single highlighting, as soon as I add another...
From `:help :match` > > Highlighting matches using :match are limited to three > > matches (aside from :match, :2match and :3match are > > available). matchadd() does not have this limitation and in > > addition makes it possible to prioritize matches. > > > So you can use: ``` hi NewLineWin ctermfg=...
6,160
<p>Consider this string:</p> <pre><code>1 1 1 </code></pre> <p>When I mark the first two 1s in visual mode and then <code>:'&lt;,'&gt;s/1/2/g</code>, all 1s on the line are replaced by 2s, not just those in the selected region. Why is this the case and how can I restrict the operation to the selected text?</p>
[ { "answer_id": 6161, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 4, "selected": true, "text": "<p>The <code>:s[ubstitue]</code> command operates on whole lines and the <code>[range]</code> prefix is a range of lines.</...
2016/01/18
[ "https://vi.stackexchange.com/questions/6160", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6066/" ]
Consider this string: ``` 1 1 1 ``` When I mark the first two 1s in visual mode and then `:'<,'>s/1/2/g`, all 1s on the line are replaced by 2s, not just those in the selected region. Why is this the case and how can I restrict the operation to the selected text?
The `:s[ubstitue]` command operates on whole lines and the `[range]` prefix is a range of lines. To restrict the operation to just the visually-selected region, you can use the `\%V` atom in your search pattern. That is, visually-select the first two 1s in your example, then use this command to replace just those 1s: ...
6,164
<p>I'm on Arch, and recently the <code>vim-python3</code> and <code>gvim-python3</code> packages were removed, so I'm working on building vim from source such that the <code>:python</code> command will act as <code>python3</code>. Specifically, I'm doing this so that the <code>vim-jedi</code> package will work properly...
[ { "answer_id": 6174, "author": "Davis Yoshida", "author_id": 6067, "author_profile": "https://vi.stackexchange.com/users/6067", "pm_score": 4, "selected": true, "text": "<p>Thanks to x33a on the Arch forums, I was able to solve my problem. (<a href=\"https://bbs.archlinux.org/viewtopic.p...
2016/01/19
[ "https://vi.stackexchange.com/questions/6164", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6067/" ]
I'm on Arch, and recently the `vim-python3` and `gvim-python3` packages were removed, so I'm working on building vim from source such that the `:python` command will act as `python3`. Specifically, I'm doing this so that the `vim-jedi` package will work properly. I tried changing the ``` --enable-pythoninterp=dynamic...
Thanks to x33a on the Arch forums, I was able to solve my problem. (<https://bbs.archlinux.org/viewtopic.php?pid=1596987#p1596987>) I changed the python 3 flag from ``` --enable-python3interp=dyanmic ``` to ``` --enable-python3interp ``` This resulted in only python 3 being available.
6,167
<p>I would like the first line of some documents I have to be highlighted as a comment.</p> <p>I would like something like:</p> <pre><code>syntax match myTypeComment /{apply only to first line}^.*$/ </code></pre> <p>But I don't know how this regex should work for only one line (e.g. the first line) in syntax matchin...
[ { "answer_id": 6168, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>You can use the <code>\\%l</code> regex atom to make sure to match at a particular line. \nSo you would likely wa...
2016/01/19
[ "https://vi.stackexchange.com/questions/6167", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6072/" ]
I would like the first line of some documents I have to be highlighted as a comment. I would like something like: ``` syntax match myTypeComment /{apply only to first line}^.*$/ ``` But I don't know how this regex should work for only one line (e.g. the first line) in syntax matching. Thank you very much!
You can use the `\%1l`; this will match a specific line. For example, to highlight the first line if it starts with `# Hello`: ``` :syntax match myTypeComment /\%1l# Hello.*/ :hi myTypeComment ctermfg=red ``` This also works for other lines (e.g. `\%42l` for the 42nd line) and you can use `\%42<l` and `\%42>l` for ...
6,171
<p>I'm trying to set up a plugin to enable indentation guides, following an answer to <a href="https://vi.stackexchange.com/questions/666/how-to-add-indentation-guides-lines">this question</a>. The plugin is <a href="https://github.com/Yggdroot/indentLine" rel="nofollow noreferrer">Yggdroot/indentLine</a>. It has instr...
[ { "answer_id": 6173, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 3, "selected": true, "text": "<p>You are close. You need to use this form:</p>\n\n<pre><code>:let foobar=\"\\u1234\"\n</code></pre>\n\n<p>Using \"\...
2016/01/19
[ "https://vi.stackexchange.com/questions/6171", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2798/" ]
I'm trying to set up a plugin to enable indentation guides, following an answer to [this question](https://vi.stackexchange.com/questions/666/how-to-add-indentation-guides-lines). The plugin is [Yggdroot/indentLine](https://github.com/Yggdroot/indentLine). It has instructions to set up a custom glyph to be shown instea...
You are close. You need to use this form: ``` :let foobar="\u1234" ``` Using "\u" allows to use up to 4 hex digits. Until recently, it was not possible to use more, but with newer Vims you can now use "\U" plus up to 8 hex numbers. The details are explained at `:h expr-quote`
6,177
<p>I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands:</p> <pre><code>set history=0 set nobackup set nomodeline set noshelltemp set noswapfile set noundofile set nowritebackup set secure set viminfo="" </code></pre> <p><em>Let me know if you ...
[ { "answer_id": 6678, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": false, "text": "<p>Well, a bit belated but to respond to:</p>\n\n<blockquote>\n <ol start=\"6\">\n <li>Some magic (from a comment by ...
2016/01/19
[ "https://vi.stackexchange.com/questions/6177", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6043/" ]
I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands: ``` set history=0 set nobackup set nomodeline set noshelltemp set noswapfile set noundofile set nowritebackup set secure set viminfo="" ``` *Let me know if you can think of any additional c...
Well, a bit belated but to respond to: > > 6. Some magic (from a comment by Carpetsmoker in this thread) > > > My general idea was that you always want to start "private mode" if you're using an encrypted file, so this autocommand will do that for you: ``` au BufRead * if &key!= "" \ | setlocal history=0 nob...
6,178
<p>Does neovim set any environment variables that would let me detect from bash that the terminal is neovim? I want to change the behavior of my <code>.bashrc</code> if neovim is the terminal.</p>
[ { "answer_id": 6179, "author": "alxndr", "author_id": 67, "author_profile": "https://vi.stackexchange.com/users/67", "pm_score": 5, "selected": true, "text": "<p>I compared the output of running <code>env</code> in a standard terminal to the output when running it within Neovim, and it l...
2016/01/20
[ "https://vi.stackexchange.com/questions/6178", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/268/" ]
Does neovim set any environment variables that would let me detect from bash that the terminal is neovim? I want to change the behavior of my `.bashrc` if neovim is the terminal.
I compared the output of running `env` in a standard terminal to the output when running it within Neovim, and it looks like these variables are new: ``` VIMRUNTIME=/usr/local/Cellar/neovim/HEAD/share/nvim/runtime VIM=/usr/local/Cellar/neovim/HEAD/share/nvim NVIM_LISTEN_ADDRESS=/var/folders/_8/sy7jjpw55mbgn2prml0fbsgc...
6,184
<p>I have just created a file <code>.html</code>. When I run <code>set filetype?</code> I get <code>filetype=html</code>. Then I select this code:</p> <pre><code>&lt;div&gt; &lt;span&gt; &lt;/span&gt; &lt;/div&gt; </code></pre> <p>and press <code>=</code> but the code is not indented... I don't have problems to inden...
[ { "answer_id": 6185, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>Try checking the options mentioned in <code>:help =</code>:</p>\n\n<pre><code>={motion} Filter {motion} lines through t...
2016/01/20
[ "https://vi.stackexchange.com/questions/6184", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6086/" ]
I have just created a file `.html`. When I run `set filetype?` I get `filetype=html`. Then I select this code: ``` <div> <span> </span> </div> ``` and press `=` but the code is not indented... I don't have problems to indent `php` files for example using the same procedure.
Try checking the options mentioned in `:help =`: ``` ={motion} Filter {motion} lines through the external program given with the 'equalprg' option. When the 'equalprg' option is empty (this is the default), use the internal formatting function |C-indenting| and |'lisp...
6,187
<p>Assume I have the text <code>Fnord</code> yanked before and that my cursor resides on the <code>B</code> of the line:</p> <pre><code>M:mock(Baz) </code></pre> <p>How can I change the text inside () with the previously yanked text?</p> <p>Currently, I often make the mistake by doing:</p> <ul> <li><code>di(</code>...
[ { "answer_id": 6188, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 1, "selected": false, "text": "<p>Assuming \"Fnord\" is in register a you can do (with the cursor at the beginning of the line)\n<code>f(ci(&lt;c-r...
2016/01/20
[ "https://vi.stackexchange.com/questions/6187", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
Assume I have the text `Fnord` yanked before and that my cursor resides on the `B` of the line: ``` M:mock(Baz) ``` How can I change the text inside () with the previously yanked text? Currently, I often make the mistake by doing: * `di(` aka "delete inside ()" * SHIFT+P yet which leaves me with the exact text ag...
You can use visual selection to select the text to replace, and then paste over it as follows: `vi(p` `vi(` selects Baz (because it is enclosed in parenthesis), `p` pastes Fnord over it. However, this will yank Baz to the register after the paste, which might not be what you want.
6,194
<p>This has always bugged me about the <code>w</code> and <code>W</code> motion commands—they seem to work differently when used with the <code>c</code>hange command than they do when used alone, or with the <code>d</code>elete command.</p> <hr> <p>For example, with the cursor on the "q" of this text:</p> <pre><code...
[ { "answer_id": 6197, "author": "fruglemonkey", "author_id": 4932, "author_profile": "https://vi.stackexchange.com/users/4932", "pm_score": 6, "selected": true, "text": "<p>It's a special case. Check <a href=\"http://vimhelp.appspot.com/motion.txt.html#WORD\">the documentation for WORD</a...
2016/01/20
[ "https://vi.stackexchange.com/questions/6194", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
This has always bugged me about the `w` and `W` motion commands—they seem to work differently when used with the `c`hange command than they do when used alone, or with the `d`elete command. --- For example, with the cursor on the "q" of this text: ``` The quick brown fox jumps over the lazy dog. ``` typing `dw` re...
It's a special case. Check [the documentation for WORD](http://vimhelp.appspot.com/motion.txt.html#WORD), under "Special case": > > Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is on a non-blank. This is because "cw" is interpreted as > change-word, and a word does not include the followi...
6,196
<p>On bash's readline in emacs mode, I recently discovered the <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Transpose.html" rel="noreferrer">transpose</a> functionality, giving me the opportunity to quickly fix a typo like</p> <pre><code>dc dir </code></pre> <p>to </p> <pre><code>cd dir </code><...
[ { "answer_id": 6198, "author": "Wildcard", "author_id": 4676, "author_profile": "https://vi.stackexchange.com/users/4676", "pm_score": 5, "selected": true, "text": "<p>For characters, it's fairly simple: <code>xp</code> to swap the letter under the cursor with the following letter, and <...
2016/01/20
[ "https://vi.stackexchange.com/questions/6196", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
On bash's readline in emacs mode, I recently discovered the [transpose](http://www.gnu.org/software/emacs/manual/html_node/emacs/Transpose.html) functionality, giving me the opportunity to quickly fix a typo like ``` dc dir ``` to ``` cd dir ``` by pressing `CTRL`+`T` on the `c` character. Is there something si...
For characters, it's fairly simple: `xp` to swap the letter under the cursor with the following letter, and `Xp` to swap the letter under the cursor with the previous letter. The `x` command deletes the character under the cursor, leaving the cursor on the next character. The `X` command deletes the character just bef...
6,203
<p>I a have PHP syntax highlighting file in <code>~/.vim/syntax/php.vim</code>. Thus, PHP functions are highlighted differently than my own custom functions and Wordpress functions. Therefore, VIM does have a way to determine if a function is a PHP built-in or not.</p> <p>I am using <a href="https://stackoverflow.com/...
[ { "answer_id": 6204, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>You can determine the current syntax group with this expression:</p>\n\n<pre><code>count(map(synstack(line('.'), col('.')), '...
2016/01/21
[ "https://vi.stackexchange.com/questions/6203", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/989/" ]
I a have PHP syntax highlighting file in `~/.vim/syntax/php.vim`. Thus, PHP functions are highlighted differently than my own custom functions and Wordpress functions. Therefore, VIM does have a way to determine if a function is a PHP built-in or not. I am using [this script](https://stackoverflow.com/a/16328217/34330...
You can determine the current syntax group with this expression: ``` count(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), "phpFunction") ``` which should return `1` if the word under the cursor belongs to the `phpFunction` group and `0` if it doesn't.
6,206
<p>I use the shift keys a lot and it is an unnecessary strain on the pinky. The <code>enter</code> and <code>backspace</code> functionalities are conveniently located under a dominant finger (ctrl-m and ctrl-h). Similarly:</p> <blockquote> <p>Is there a way to map the shift function to a dominant finger? </p> </bloc...
[ { "answer_id": 6212, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>I'm not sure if a clean implementation of this feature is possible in Vimscript. (I suspect it's not, and I fully agree with t...
2016/01/21
[ "https://vi.stackexchange.com/questions/6206", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2882/" ]
I use the shift keys a lot and it is an unnecessary strain on the pinky. The `enter` and `backspace` functionalities are conveniently located under a dominant finger (ctrl-m and ctrl-h). Similarly: > > Is there a way to map the shift function to a dominant finger? > > > But in the vim spirit I want to get this f...
I'm not sure if a clean implementation of this feature is possible in Vimscript. (I suspect it's not, and I fully agree with the commenters who suggest it's better to implement this outside of Vim.) Nevertheless, here's a proof-of-concept of a hacky function that maps insert-mode `fd` to a function which waits for a s...
6,208
<p>I usually search for words by <code>:/string</code>, but if I have to search entire current line, how to do that.</p> <pre><code>event: 1 beacon: 0x02 //line 1 event: 19 beacon: 0x02 //line 2 event: 1 beacon: 0x03 //line 3 event: 1 beacon: 0x02 //line 4 event: ...
[ { "answer_id": 6209, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 2, "selected": false, "text": "<p>Personally I would get a <a href=\"https://github.com/nelstrom/vim-visual-star-search\" rel=\"nofollow\">visual star...
2016/01/21
[ "https://vi.stackexchange.com/questions/6208", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2706/" ]
I usually search for words by `:/string`, but if I have to search entire current line, how to do that. ``` event: 1 beacon: 0x02 //line 1 event: 19 beacon: 0x02 //line 2 event: 1 beacon: 0x03 //line 3 event: 1 beacon: 0x02 //line 4 event: 8 beacon: 0x01 ...
Here's how I'd do it: 1. Yank the line (into the unnamed register), without including the newline at the end: `0y$` 2. Initiate a *very nomagic* search: `/\V` 3. Add the yanked line: `<c-r>"` 4. Fire off the search: `<cr>` As [@EvergreenTree points out in a comment](https://vi.stackexchange.com/questions/6208/how-to-...
6,214
<p>Consider I work on a file like this:</p> <pre><code>'90008000','90008005' </code></pre> <p>How can I insert the following text after <code>'90008000',</code> in Vim:</p> <pre><code>'90008001','90008002','90008003','90008004', </code></pre> <p>I have read <a href="https://vi.stackexchange.com/questions/12/how-can...
[ { "answer_id": 6216, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 3, "selected": false, "text": "<p>Personally, I'd probably just do this manually using regular insert/motion operations, <code>y</code>, <code>p</code>, and <c...
2016/01/22
[ "https://vi.stackexchange.com/questions/6214", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5510/" ]
Consider I work on a file like this: ``` '90008000','90008005' ``` How can I insert the following text after `'90008000',` in Vim: ``` '90008001','90008002','90008003','90008004', ``` I have read [this post](https://vi.stackexchange.com/questions/12/how-can-i-generate-a-list-of-sequential-numbers-one-per-line), b...
You could use a macro. Starting with the cursor on the first character of the line, type `qqyf,P<C-a>F'q3@q`: ``` qq "start the macro recording to register `q` yf, "yank the part you are looking to duplicate, P "paste it *before* the cursor. <C-a> "increment the next number by one F' "move backwa...
6,254
<p>The current working directory is <code>./A/B/</code>. An empty document is opened when I type <code>vim</code>, and the netrw is opened with command <code>:e.</code> The window is split by <code>vs.</code>, and I can navigate to the upper level directory, i.e., <code>./A/</code>. Now I'd like to copy a file <code>a_...
[ { "answer_id": 6262, "author": "Borys Serebrov", "author_id": 6013, "author_profile": "https://vi.stackexchange.com/users/6013", "pm_score": 4, "selected": false, "text": "<p>I would do this from the command line mode:</p>\n\n<ul>\n<li>Select the file you need in netrw</li>\n<li>Open com...
2016/01/26
[ "https://vi.stackexchange.com/questions/6254", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1080/" ]
The current working directory is `./A/B/`. An empty document is opened when I type `vim`, and the netrw is opened with command `:e.` The window is split by `vs.`, and I can navigate to the upper level directory, i.e., `./A/`. Now I'd like to copy a file `a_file.jpg` from `./A/B/` to `./A/`. I tried `yy` on the target ...
You cannot use `y`, `p` etc., to copy files in netrw - it comes with its own commands. See [`:h netrw-mc`](http://vimhelp.appspot.com/pi_netrw.txt.html#netrw-mc): ``` MARKED FILES: COPYING netrw-mc {{{2 (See netrw-mf and netrw-mr for how to mark files) ...
6,269
<p>I was looking at <a href="https://unix.stackexchange.com/q/257819/135943">this question</a> and then wondered how I might implement <a href="https://unix.stackexchange.com/a/257913/135943">my answer which uses <code>sed</code></a> using purely <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ex.htm...
[ { "answer_id": 6276, "author": "Wildcard", "author_id": 4676, "author_profile": "https://vi.stackexchange.com/users/4676", "pm_score": 2, "selected": false, "text": "<p>It would appear that the only POSIX way to do this is to use an external filter, such as <code>sed</code>.</p>\n\n<p>Fo...
2016/01/27
[ "https://vi.stackexchange.com/questions/6269", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
I was looking at [this question](https://unix.stackexchange.com/q/257819/135943) and then wondered how I might implement [my answer which uses `sed`](https://unix.stackexchange.com/a/257913/135943) using purely [POSIX `ex`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ex.html). The trick is that while in ...
It would appear that the only POSIX way to do this is to use an external filter, such as `sed`. For example, to delete the 17th line of your file only if it is exactly identical to the 5th line, and otherwise leave it unchanged, you can do the following: ``` :1,17!sed '5h;17{G;/^\(.*\)\n\1$/d;s/\n.*$//;}' ``` (You ...
6,287
<p>First of all, with this being my first post here, I'd just like to say that I've found VIM to be a great tool and the forum here to be very helpful in finding answers to questions, with lots of helpful people providing invaluable assistance. I'm still very new to VIM, so pretty much everything I've learned about it ...
[ { "answer_id": 6288, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 5, "selected": true, "text": "<p>The command <code>:Reverse</code> explained at <a href=\"http://vim.wikia.com/wiki/Reverse_all_lines\" rel=\"noreferrer\">...
2016/01/29
[ "https://vi.stackexchange.com/questions/6287", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6195/" ]
First of all, with this being my first post here, I'd just like to say that I've found VIM to be a great tool and the forum here to be very helpful in finding answers to questions, with lots of helpful people providing invaluable assistance. I'm still very new to VIM, so pretty much everything I've learned about it has...
The command `:Reverse` explained at [Vim Wiki](http://vim.wikia.com/wiki/Reverse_all_lines) can be used for this (you may include it in your `.vimrc` to make it permanent): ``` command! -bar -range=% Reverse <line1>,<line2>g/^/m<line1>-1|nohl ``` Then you can record a macro to run the command on every four lines: `...
6,294
<p>I have Windows 7 64-bit, with python 2.7.11 and python 3.5.1 (both 32-bit) installed, and I have compiled vim with python/dyn and python3/dyn, but I keep getting the following error:</p> <pre><code>:py print "hello" E887: Sorry, this command is disabled, the Python's site module could not be loaded </code></pre> <...
[ { "answer_id": 6348, "author": "afontaine", "author_id": 2010, "author_profile": "https://vi.stackexchange.com/users/2010", "pm_score": 4, "selected": true, "text": "<p>All right, apparently the state is this: VIM on Windows supports python <code>2.7.9</code>, not <code>2.7.11</code>. It...
2016/01/29
[ "https://vi.stackexchange.com/questions/6294", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2010/" ]
I have Windows 7 64-bit, with python 2.7.11 and python 3.5.1 (both 32-bit) installed, and I have compiled vim with python/dyn and python3/dyn, but I keep getting the following error: ``` :py print "hello" E887: Sorry, this command is disabled, the Python's site module could not be loaded ``` However, the following a...
All right, apparently the state is this: VIM on Windows supports python `2.7.9`, not `2.7.11`. It might work with `2.7.10`, I did not test it. Even though I compiled VIM on Windows with a reference to the `2.7.11` DLL, it suddenly worked when I tried swapping out `2.7.11` for `2.7.9` I'm not sure if I did something w...
6,296
<p>I am a new vim user, and I don't know why but my first buffer (the [No Name] buffer) is not empty each time I open it, still after rebooting my computer.</p> <p>It begins with <code>:q!</code> then the end of my .vimrc file.</p> <p>And when I open a file with vim from the command line it says before :</p> <pre><c...
[ { "answer_id": 6348, "author": "afontaine", "author_id": 2010, "author_profile": "https://vi.stackexchange.com/users/2010", "pm_score": 4, "selected": true, "text": "<p>All right, apparently the state is this: VIM on Windows supports python <code>2.7.9</code>, not <code>2.7.11</code>. It...
2016/01/29
[ "https://vi.stackexchange.com/questions/6296", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6078/" ]
I am a new vim user, and I don't know why but my first buffer (the [No Name] buffer) is not empty each time I open it, still after rebooting my computer. It begins with `:q!` then the end of my .vimrc file. And when I open a file with vim from the command line it says before : ``` "client.c" "client.c" 58L, 1558C P...
All right, apparently the state is this: VIM on Windows supports python `2.7.9`, not `2.7.11`. It might work with `2.7.10`, I did not test it. Even though I compiled VIM on Windows with a reference to the `2.7.11` DLL, it suddenly worked when I tried swapping out `2.7.11` for `2.7.9` I'm not sure if I did something w...
6,305
<p>Many sections of stuff we right is such that it could be automatically formatted by user defined rules. Here are a couple of examples:</p> <ul> <li><p>List of include files in languages such as C. It is customary to sort these alphabetically, and this sorting is also part of style guides such as those of Google.</p...
[ { "answer_id": 6309, "author": "fruglemonkey", "author_id": 4932, "author_profile": "https://vi.stackexchange.com/users/4932", "pm_score": 3, "selected": true, "text": "<p>You want to automatically run a command when you write your buffer, and the n save your buffer after the command.. T...
2016/01/30
[ "https://vi.stackexchange.com/questions/6305", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5919/" ]
Many sections of stuff we right is such that it could be automatically formatted by user defined rules. Here are a couple of examples: * List of include files in languages such as C. It is customary to sort these alphabetically, and this sorting is also part of style guides such as those of Google. * Ditto for `usepac...
You want to automatically run a command when you write your buffer, and the n save your buffer after the command.. This means you're looking for an [autocmd](http://vimdoc.sourceforge.net/htmldoc/autocmd.html#autocmd-intro) that runs during a [BufWrite](http://vimdoc.sourceforge.net/htmldoc/autocmd.html#BufWrite). Pla...
6,307
<p>I was reading <strong>vimtutor</strong> and in lesson 2.1 there was this note about typing commands like <strong>dw</strong>:</p> <pre><code>NOTE: The letter d will appear on the last line of the screen as you type it. Vim is waiting for you to type w . If you see another character than d you typed s...
[ { "answer_id": 6308, "author": "joeytwiddle", "author_id": 630, "author_profile": "https://vi.stackexchange.com/users/630", "pm_score": 4, "selected": false, "text": "<p>This behaviour is controlled by the <code>showcmd</code> option.</p>\n\n<p>Try:</p>\n\n<pre><code>:set showcmd\n</code...
2016/01/31
[ "https://vi.stackexchange.com/questions/6307", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6219/" ]
I was reading **vimtutor** and in lesson 2.1 there was this note about typing commands like **dw**: ``` NOTE: The letter d will appear on the last line of the screen as you type it. Vim is waiting for you to type w . If you see another character than d you typed something wrong; press <ESC> and start ...
Add this line into you .vimrc , either source it or restart vim. ``` set showcmd ``` And yes If you are experimenting with your vimrc and tired of sourcing it after every change, add this line. ``` autocmd BufWritePost .vimrc source % ```