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
7,167
<p>I really like to jump from one <code>&lt;el&gt;</code> to the end of <code>&lt;/el&gt;</code> with matchit. I am using it for jsx, but it does not seem to work if I have an element that is declared with <code>/&gt;</code>, does anybody have an idea how to fix the issue. </p> <p>Here is an example of what is not wor...
[ { "answer_id": 7288, "author": "Jair López", "author_id": 6698, "author_profile": "https://vi.stackexchange.com/users/6698", "pm_score": 2, "selected": true, "text": "<p>Let's suppose you have the following lines in your <code>~/.vimrc</code></p>\n\n<pre><code>source $VIMRUNTIME/macros/m...
2016/04/03
[ "https://vi.stackexchange.com/questions/7167", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3003/" ]
I really like to jump from one `<el>` to the end of `</el>` with matchit. I am using it for jsx, but it does not seem to work if I have an element that is declared with `/>`, does anybody have an idea how to fix the issue. Here is an example of what is not working: ``` <Scene key="tabbar" component={NavigationDrawer...
Let's suppose you have the following lines in your `~/.vimrc` ``` source $VIMRUNTIME/macros/matchit.vim filetype plugin on ``` If the offending lines are in a `.html` file, then: ``` b:match_words = '<:>,' . \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' . \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@...
7,179
<p>Sometimes ex commands have the useless side effect of jumping, probably to the last place they affected. Can this be prevented? I would prefer it if ex commands left my screen exactly the same as before their execution.</p>
[ { "answer_id": 7241, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>While I don't see in the doc any option/flag you can use for a ex command, I think you can simply use the <code>C-o</code> ...
2016/04/04
[ "https://vi.stackexchange.com/questions/7179", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4505/" ]
Sometimes ex commands have the useless side effect of jumping, probably to the last place they affected. Can this be prevented? I would prefer it if ex commands left my screen exactly the same as before their execution.
While I don't see in the doc any option/flag you can use for a ex command, I think you can simply use the `C-o` command afterward. From the documentation: ``` CTRL-O Go to [count] Older cursor position in jump list (not a motion command). {not in Vi} {not available without th...
7,201
<p>I've the file, like:</p> <pre><code>name = foo # unknown number of lines ... features_exclude[rules_config][] = rule1 features_exclude[rules_config][] = rule2 features_exclude[rules_config][] = rule3 features_exclude[rules_config][] = rule4 </code></pre> <p>and I'd like to run <a href="https://vi.stackexchange....
[ { "answer_id": 7202, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 2, "selected": false, "text": "<p>I imagine there must be an easier way. Since <code>@:</code> is accessing a special register, you can use registers yourself:...
2016/04/05
[ "https://vi.stackexchange.com/questions/7201", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/467/" ]
I've the file, like: ``` name = foo # unknown number of lines ... features_exclude[rules_config][] = rule1 features_exclude[rules_config][] = rule2 features_exclude[rules_config][] = rule3 features_exclude[rules_config][] = rule4 ``` and I'd like to run [`:/_exclude/s///`](https://vi.stackexchange.com/a/7195/467)...
[:help E30](https://vimhelp.appspot.com/change.txt.html#E30) states > > The command-line is only stored in this register when at least one character of it was typed. Thus it remains unchanged if the command was completed from a mapping. > > > It seems like Vim is not considering commands specified via `+` (or `-c...
7,217
<p>In order to open PDFs using an external application, one can use the following script:</p> <pre><code>augroup nonvim au! au BufRead *.pdf sil exe "!open " . shellescape(expand("&lt;afile&gt;")) | bd augroup end </code></pre> <p>However, this is not optimal, because the pdf would still be loaded into vim, w...
[ { "answer_id": 7223, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 4, "selected": true, "text": "<p>A better option would be <a href=\"http://vimhelp.appspot.com/autocmd.txt.html#BufReadCmd\" rel=\"noreferrer\"><code>BufReadCm...
2016/04/05
[ "https://vi.stackexchange.com/questions/7217", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4947/" ]
In order to open PDFs using an external application, one can use the following script: ``` augroup nonvim au! au BufRead *.pdf sil exe "!open " . shellescape(expand("<afile>")) | bd augroup end ``` However, this is not optimal, because the pdf would still be loaded into vim, which will take a while if it is ...
A better option would be [`BufReadCmd`](http://vimhelp.appspot.com/autocmd.txt.html#BufReadCmd): ``` BufReadCmd BufReadCmd Before starting to edit a new buffer. Should read the file into the buffer. Cmd-event ...
7,224
<p>I'm VIM user for a few months now (life changing) but I have a small issue with the backspace key which is quite far from everything else (I already use <kbd>CapsLock</kbd> for the <kbd>Esc</kbd> key).</p> <p>Which mapping is best appropriate for using vim and touch typing for the backspace key. Or is it my mistake...
[ { "answer_id": 7225, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>Personally I don't have the <kbd>backspace</kbd> key remapped to another. Actually I think the important point about your...
2016/04/06
[ "https://vi.stackexchange.com/questions/7224", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7125/" ]
I'm VIM user for a few months now (life changing) but I have a small issue with the backspace key which is quite far from everything else (I already use `CapsLock` for the `Esc` key). Which mapping is best appropriate for using vim and touch typing for the backspace key. Or is it my mistake for using backspace for del...
I agree with statox's answer, and I want to point out that you have insert-mode ways of deleting more than 1 character at the time: ``` :h insert-index ... |i_<BS>| <BS> delete character before the cursor |i_CTRL-H| CTRL-H same as <BS> |i_CTRL-U| CTRL-U delete all entered characters in the curre...
7,252
<p>I have a problem with my cursor in gVim, this happens in both Normal and insert(Whenever I type fast) modes. </p> <p>When I move my cursor it seems that the cursor goes to a random position for a very short time before it goes back where it should go. Here is a gif to demonstrate that : <a href="http://giphy.com/gi...
[ { "answer_id": 7270, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>You should try following the procedure described on <a href=\"http://vimhelp.appspot.com/vim_faq.txt.html#faq-2.5\" rel=\...
2016/04/07
[ "https://vi.stackexchange.com/questions/7252", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7147/" ]
I have a problem with my cursor in gVim, this happens in both Normal and insert(Whenever I type fast) modes. When I move my cursor it seems that the cursor goes to a random position for a very short time before it goes back where it should go. Here is a gif to demonstrate that : [Vim cursor](http://giphy.com/gifs/xTi...
You should try following the procedure described on [Vim-FAQ 2.5](http://vimhelp.appspot.com/vim_faq.txt.html#faq-2.5). Some relevant parts follows: > > 2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a > problem with my setup or with Vim? / Have I found a bug in Vim? > > > First, you need to...
7,258
<p>This drives me crazy, I do </p> <pre><code>:set ft=text </code></pre> <p>To see something, otherwise all the links disappear in markdown and quotes in JSON.</p> <p>How do disable this once and for all?</p>
[ { "answer_id": 7263, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 6, "selected": true, "text": "<p>(guessing here, please provide a screenshot/more information)</p>\n\n<p>You may want to change your <code>conceallevel</cod...
2016/04/08
[ "https://vi.stackexchange.com/questions/7258", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/237/" ]
This drives me crazy, I do ``` :set ft=text ``` To see something, otherwise all the links disappear in markdown and quotes in JSON. How do disable this once and for all?
(guessing here, please provide a screenshot/more information) You may want to change your `conceallevel` setup: ``` :h 'conceallevel' 'conceallevel' 'cole' *'conceallevel'* *'cole'* number (default 0) local to window {not in Vi} {not available when compiled withou...
7,259
<p>I tried replacing 30 chars from the beginning of each line of my text, but could not figure out how to specify to <code>vi</code> <code>sed</code> to do it.</p> <p>I tried this:</p> <pre><code>:%s/.{3}/xx/ </code></pre> <p>But it could not find my pattern. I thought <code>{3}</code> would mean <em>3 times</em> th...
[ { "answer_id": 7260, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 4, "selected": true, "text": "<p>If you look at <a href=\"http://vimhelp.appspot.com/pattern.txt.html#%2Fmagic\" rel=\"noreferrer\"><code>:h magic</code></a>:<...
2016/04/08
[ "https://vi.stackexchange.com/questions/7259", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6946/" ]
I tried replacing 30 chars from the beginning of each line of my text, but could not figure out how to specify to `vi` `sed` to do it. I tried this: ``` :%s/.{3}/xx/ ``` But it could not find my pattern. I thought `{3}` would mean *3 times* the previous, but unfortunately not. `{` is not interpreted as a regex comm...
If you look at [`:h magic`](http://vimhelp.appspot.com/pattern.txt.html#%2Fmagic): Examples: ``` after: \v \m \M \V matches 'magic' 'nomagic' $ $ $ \$ matches end-of-line . . \. \. matches any ch...
7,298
<p>Given file <em>alfa.txt</em>:</p> <pre><code>foxtrot golf hotel india juliet </code></pre> <p>I would like to insert a newline after lines 2 and 4. I have this command:</p> <pre><code>ex -sc '2pu_|4pu_|x' alfa.txt </code></pre> <p>However it is inserting lines after line 2 and 3, instead of 2 and 4:</p> <pre><c...
[ { "answer_id": 7299, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 3, "selected": false, "text": "<p>The commands are executed serially, which means that before the <code>4pu_</code> command is executed, a newline h...
2016/04/11
[ "https://vi.stackexchange.com/questions/7298", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7184/" ]
Given file *alfa.txt*: ``` foxtrot golf hotel india juliet ``` I would like to insert a newline after lines 2 and 4. I have this command: ``` ex -sc '2pu_|4pu_|x' alfa.txt ``` However it is inserting lines after line 2 and 3, instead of 2 and 4: ``` foxtrot golf hotel india juliet ```
Here is an example based on the comment: ``` ex -sc 'g/\v%2l|%4l/pu_' -cx alfa.txt ``` Here is a working alternative to my original command: ``` ex -sc '4pu_|2pu_|x' alfa.txt ```
7,301
<p>I'd like to delete all spaces on empty lines before saving files. I've figured out how to do that.</p> <pre><code>autocmd BufWritePre * silent! %s/\v^\s+$//e </code></pre> <p>But this moves my cursor to the line where the spaces have been removed. I know that not in autocmd I can just press <code>''</code> and tha...
[ { "answer_id": 7302, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>You could achieve <code>''</code> on an autocmd using the following:</p>\n\n<pre><code>:call setpos('.', getpos(\"''\"))\...
2016/04/11
[ "https://vi.stackexchange.com/questions/7301", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6634/" ]
I'd like to delete all spaces on empty lines before saving files. I've figured out how to do that. ``` autocmd BufWritePre * silent! %s/\v^\s+$//e ``` But this moves my cursor to the line where the spaces have been removed. I know that not in autocmd I can just press `''` and that would do what I want, but I can't f...
You could achieve `''` on an autocmd using the following: ``` :call setpos('.', getpos("''")) ``` Check [`:help function-list`](http://vimhelp.appspot.com/usr_41.txt.html#function-list) for built-in functionality on VimL. --- **Edit** > > okay, how to combine it with search and replace? Another autocmd after > ...
7,308
<p>In insert-mode, I would like to extract the <em>current line number</em> I'm editing in a "variable"/memory/buffer, and to be able to paste it through a remapping.</p> <p>I know that <code>:echo line(".")</code> gives me the line number. I have found how to insert the line number at the beginning of each line, usi...
[ { "answer_id": 7302, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>You could achieve <code>''</code> on an autocmd using the following:</p>\n\n<pre><code>:call setpos('.', getpos(\"''\"))\...
2016/04/12
[ "https://vi.stackexchange.com/questions/7308", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7128/" ]
In insert-mode, I would like to extract the *current line number* I'm editing in a "variable"/memory/buffer, and to be able to paste it through a remapping. I know that `:echo line(".")` gives me the line number. I have found how to insert the line number at the beginning of each line, using `:s/^/\=line(".")`. But I...
You could achieve `''` on an autocmd using the following: ``` :call setpos('.', getpos("''")) ``` Check [`:help function-list`](http://vimhelp.appspot.com/usr_41.txt.html#function-list) for built-in functionality on VimL. --- **Edit** > > okay, how to combine it with search and replace? Another autocmd after > ...
7,324
<p>I can remove the last 10 lines like this:</p> <pre><code>ex -sc '-9,d|x' f.txt </code></pre> <p>However, I would like to invert the selection, or remove all lines except the last 10. Is this possible?</p>
[ { "answer_id": 7321, "author": "Ingo", "author_id": 3343, "author_profile": "https://vi.stackexchange.com/users/3343", "pm_score": 3, "selected": false, "text": "<p>You can define a new command like <code>:E</code> instead of <code>:!</code> and write a custom completion function for it ...
2016/04/13
[ "https://vi.stackexchange.com/questions/7324", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7184/" ]
I can remove the last 10 lines like this: ``` ex -sc '-9,d|x' f.txt ``` However, I would like to invert the selection, or remove all lines except the last 10. Is this possible?
Assuming that `Convection1D` is a file name, you can use the [`wildignorecase`](http://vimhelp.appspot.com/options.txt.html#%27wildignorecase%27) setting, which will Vim ignore case when completing file names and directories. This is available since Vim 7.3.075. Also note you can use [`:!!`](http://vimhelp.appspot.com...
7,336
<p>I have a file with the following pattern:</p> <pre><code>foo 111 baz foo 222 baz foo 333 baz </code></pre> <p>which needs to be turned into</p> <pre><code>foo 111 bar 111 baz foo 222 bar 222 baz foo 333 bar 333 baz </code></pre> <p>So, duplicate all the lines beginning with <code>foo</code>, and change only <cod...
[ { "answer_id": 7337, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 5, "selected": true, "text": "<p>Here you go: </p>\n\n<pre><code>:g/foo/t.|s//bar\n</code></pre>\n\n<p>Decomposing:</p>\n\n<pre><code>:g/foo/ \" start ...
2016/04/14
[ "https://vi.stackexchange.com/questions/7336", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4446/" ]
I have a file with the following pattern: ``` foo 111 baz foo 222 baz foo 333 baz ``` which needs to be turned into ``` foo 111 bar 111 baz foo 222 bar 222 baz foo 333 bar 333 baz ``` So, duplicate all the lines beginning with `foo`, and change only `foo` in the duplicate but leave the rest of the line (which dif...
Here you go: ``` :g/foo/t.|s//bar ``` Decomposing: ``` :g/foo/ " start a global command applied on all lines matching 'foo' t. " duplicate the current line (the cursor is now on the new line) | " chain a new command s//bar " substitute the last searched element with 'bar' ``` Because the ...
7,338
<p>I have a lot of projects of the form:</p> <pre><code>/home/karl/source/project-name/further/hierarchy/... </code></pre> <p>I would like to extract just the <code>project-name</code> to put into my statusline. I use <code>autochdir</code>, so I know I can create a function that calls <code>getcwd()</code> and extr...
[ { "answer_id": 7339, "author": "Karl Bielefeldt", "author_id": 780, "author_profile": "https://vi.stackexchange.com/users/780", "pm_score": 2, "selected": false, "text": "<p>Thanks to @romainl's comment for pointing me in the right direction. Here's my solution:</p>\n\n<pre><code>functi...
2016/04/14
[ "https://vi.stackexchange.com/questions/7338", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/780/" ]
I have a lot of projects of the form: ``` /home/karl/source/project-name/further/hierarchy/... ``` I would like to extract just the `project-name` to put into my statusline. I use `autochdir`, so I know I can create a function that calls `getcwd()` and extracts that part. However, I haven't been able to figure out h...
I think your solution might work, but I think this is a slightly cleaner and more readable version: ``` function ProjectName() let l:path = expand('%:p') return (l:path =~# '^/home/karl/source/.\+') \ ? substitute(l:path, '^/home/karl/source/\([^/]*\)/.*', '\1', '') \ : '...' endfunction ``` Also...
7,340
<p>I often have to write XML where text-width has been manually set by another editor:</p> <pre><code>&lt;context&gt; &lt;p&gt;Here is a paragraph about some stuff that happened and someone did a nice printing that makes the text break and stuff, which is nice unless you have to it it, and now...
[ { "answer_id": 7361, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>Here is a solution which is not perfect but not that bad:</p>\n\n<p>First add these lines to your <code>.vimrc</code>:</p>...
2016/04/14
[ "https://vi.stackexchange.com/questions/7340", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3264/" ]
I often have to write XML where text-width has been manually set by another editor: ``` <context> <p>Here is a paragraph about some stuff that happened and someone did a nice printing that makes the text break and stuff, which is nice unless you have to it it, and now its a PITA.</p> <p>He...
Here is a solution which is not perfect but not that bad: First add these lines to your `.vimrc`: ``` function! ReJoinTags() range set nowrapscan let @/='<\(\k\+\)>\([^<]\|\n\)\{-}<\/\1>' let initialLine = line(".") normal ngnJ if initialLine != line(".") call ReJoinTags() endif endf...
7,346
<p>I know that it is possible: I googled it some time ago, but now I can't find the solution.</p> <p>What do I need add to <code>.vimrc</code> to resize my current active window in full height automatically after window changing?</p>
[ { "answer_id": 7347, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 2, "selected": false, "text": "<p>You can do it with an auto command, filtering the <code>WinEnter</code> event:</p>\n\n<pre><code>autocmd WinEnter * resize...
2016/04/15
[ "https://vi.stackexchange.com/questions/7346", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7245/" ]
I know that it is possible: I googled it some time ago, but now I can't find the solution. What do I need add to `.vimrc` to resize my current active window in full height automatically after window changing?
You can do it with an auto command, filtering the `WinEnter` event: ``` autocmd WinEnter * resize ``` `resize` without argument expand the height to max. **Refs:** * `:h resize` * `:h autocmd-events`
7,351
<p>I have a C++ template class <code>С</code> and its member function <code>foo()</code>. I also have tags file generated with Exuberant Ctags.</p> <p>I want to access this function via the <code>:tag</code> command, something like this:</p> <pre><code>:tag C::foo </code></pre> <p>However it doesn't seem to work for...
[ { "answer_id": 7355, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 1, "selected": false, "text": "<p>For what it's worth, you can use <code>ts</code>:</p>\n\n<pre><code>:ts foo\n # pri kind tag file\n 1 F C f ...
2016/04/15
[ "https://vi.stackexchange.com/questions/7351", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7248/" ]
I have a C++ template class `С` and its member function `foo()`. I also have tags file generated with Exuberant Ctags. I want to access this function via the `:tag` command, something like this: ``` :tag C::foo ``` However it doesn't seem to work for me. Inspecting tags file for understanding what should I have pas...
There are (universal?) tags options that can request functions names to be prefixed by full scope (namespace + class). Unfortunately, I can't remember which one it is among: ``` --c++-kinds=+f --fields=+imaSftn --extra=+q ``` Any way, I highly recommend universal ctags instead of exuberant ctags for C++. And BTW, in...
7,368
<p>I want to type the subscript i as follows:</p> <p><a href="https://i.stack.imgur.com/b6uEz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/b6uEz.png" alt="subsript i"></a></p> <p>What I have tried:</p> <ol> <li>I got to know how to type numerial subscripts, by following <a href="http://vimdoc.sourceforg...
[ { "answer_id": 7372, "author": "Ingo", "author_id": 3343, "author_profile": "https://vi.stackexchange.com/users/3343", "pm_score": 4, "selected": true, "text": "<p>First off, <a href=\"https://stackoverflow.com/a/6614102/5274741\">this answer</a> suggests that there are no unicode subscr...
2016/04/16
[ "https://vi.stackexchange.com/questions/7368", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1788/" ]
I want to type the subscript i as follows: [![subsript i](https://i.stack.imgur.com/b6uEz.png)](https://i.stack.imgur.com/b6uEz.png) What I have tried: 1. I got to know how to type numerial subscripts, by following [this documentation](http://vimdoc.sourceforge.net/htmldoc/digraph.html). `<ctrl-k>[digit]s` 2. I s...
First off, [this answer](https://stackoverflow.com/a/6614102/5274741) suggests that there are no unicode subscript letters for all latin characters. However you can still get some of them (a list is provided by several answers in the linked answer) by using `:digraphs` with argumenst, e.g. ``` :digraphs as 8336 ``` ...
7,371
<p>I am looking for a way to easily compile whole latex projects, based in several files through the following set of folders:</p> <pre><code>. |- MyProjectsMainFile.tex |- img/ | |- image1.png | |- image2.jpg | `- etc.whatever `- tex/ |- part1.tex |- part2.tex `- conclusion.tex </code></pre> <p>The trick...
[ { "answer_id": 7373, "author": "Ingo", "author_id": 3343, "author_profile": "https://vi.stackexchange.com/users/3343", "pm_score": 2, "selected": false, "text": "<p>Under the additional assumptions that there is always exactly one <code>.tex</code> file in your project's root directory, ...
2016/04/16
[ "https://vi.stackexchange.com/questions/7371", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7258/" ]
I am looking for a way to easily compile whole latex projects, based in several files through the following set of folders: ``` . |- MyProjectsMainFile.tex |- img/ | |- image1.png | |- image2.jpg | `- etc.whatever `- tex/ |- part1.tex |- part2.tex `- conclusion.tex ``` The tricky bit is to do this even i...
I would say that you are approaching this the wrong way. If you want to use a very minimalistic solution without any plugins, I would claim that you should not have anything in your vimrc file for compiling. Instead, you should use [latexmk](https://www.ctan.org/pkg/latexmk/). This is a very good automatic compilation ...
7,377
<p>Sometimes my global substitutions don't substitute all matches in a line. It is confirmed by the fact that I can see it when I do substitutions with confirmation, a match is found in a line with multiple possible matches, but then it goes to another line.</p> <p>I use the <code>g</code> or <code>gc</code> parameters...
[ { "answer_id": 7392, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 5, "selected": true, "text": "<p>Maybe you, or a plugin, had enabled the option <code>'gdefault'</code>. This option adds the flag <code>g</code> auto...
2016/04/16
[ "https://vi.stackexchange.com/questions/7377", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6078/" ]
Sometimes my global substitutions don't substitute all matches in a line. It is confirmed by the fact that I can see it when I do substitutions with confirmation, a match is found in a line with multiple possible matches, but then it goes to another line. I use the `g` or `gc` parameters operating on the entire file w...
Maybe you, or a plugin, had enabled the option `'gdefault'`. This option adds the flag `g` automatically whenever you perform a substitution. So, when you manually add the flag `g` while `'gdefault'` is enabled, it's as if you had 2 `g` flags which has the same effect as none. Therefore, Vim only substitutes the first...
7,388
<p>Assuming I have a line in a file with <code>XXXX</code> being a placeholder I have selected via <code>v</code> as follows:</p> <pre><code>XXXX Some other text </code></pre> <p>How can I change <em>only</em> the <code>XXXX</code> with the output of an external command, such as <code>date +%Y%m%d</code>?</p> <p>I g...
[ { "answer_id": 7389, "author": "Jair López", "author_id": 6698, "author_profile": "https://vi.stackexchange.com/users/6698", "pm_score": 3, "selected": false, "text": "<p>If you put the cursor on such a line you can:</p>\n\n<ul>\n<li><code>0</code> to put the cursor in the first column.<...
2016/04/17
[ "https://vi.stackexchange.com/questions/7388", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2774/" ]
Assuming I have a line in a file with `XXXX` being a placeholder I have selected via `v` as follows: ``` XXXX Some other text ``` How can I change *only* the `XXXX` with the output of an external command, such as `date +%Y%m%d`? I got as far as ``` :'<,'>!date +\%Y\%m\%d ``` but that replaced the whole line.
You could delete the text and insert the output of a command using `Ctrl``R`-`=`: ``` CTRL-R {0-9a-z"%#*+:.-=} i_CTRL-R Insert the contents of a register. Between typing CTRL-R and the second character, '"' will be displayed to indicate that ...
7,398
<p>I am using two different keyboard layouts (depending on the computer I use) on the same server (one being AZERTY, the other QWERTY). </p> <p>I would like to have "conditional" mapping options in my .vimrc file, depending on my layout, something like : </p> <pre><code>if (keyboard_layout == QWERTY) nnoremap : ;...
[ { "answer_id": 7414, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>What I would recommend is the following: </p>\n\n<ul>\n<li><p>First on your local machine set an environment variable man...
2016/04/18
[ "https://vi.stackexchange.com/questions/7398", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7128/" ]
I am using two different keyboard layouts (depending on the computer I use) on the same server (one being AZERTY, the other QWERTY). I would like to have "conditional" mapping options in my .vimrc file, depending on my layout, something like : ``` if (keyboard_layout == QWERTY) nnoremap : ; nnoremap ; : els...
I did not use any "environment" variable, but I coded a function that I call in the .vimrc file : ``` " The function in my .vimrc file : function! Kbdmodes(lang) if a:lang=='en' imap <akey> <anotherkey> elseif a:lang=='fr' imap <yetanotherkey> <iamthefourthkey> endif endfunction let lang='en' cal...
7,399
<p>In my <code>.vimrc</code> file, I would like to store in a variable the result of an external command, in my case:</p> <pre><code>$ echo $LANG </code></pre> <p>So that my <code>.vimrc</code> file would have :</p> <pre><code>let language = output(!echo $LANG) if language == 'en' nnoremap &lt;somekey&gt; &lt;ohanot...
[ { "answer_id": 7400, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 6, "selected": true, "text": "<p>You can do this with the <code>system</code> function:</p>\n\n<pre><code>let language = system('echo $LANG')\n</code></pre>...
2016/04/18
[ "https://vi.stackexchange.com/questions/7399", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7128/" ]
In my `.vimrc` file, I would like to store in a variable the result of an external command, in my case: ``` $ echo $LANG ``` So that my `.vimrc` file would have : ``` let language = output(!echo $LANG) if language == 'en' nnoremap <somekey> <ohanotherkey!> end if ``` So far I couldn't find how to do it. I've f...
You can do this with the `system` function: ``` let language = system('echo $LANG') ``` Bonus point: if your output is a list, you can use the `systemlist` instead to get back a list. e.g. ``` let files = systemlist('ls') " ['bin', 'dev', ... ] ``` **ref:** [`:h system`](http://vimhelp.appspot.com/eval.txt.html#s...
7,406
<p>I cannot count the number of times I have tried to do this:</p> <pre><code>:set foldmethod=syn^I </code></pre> <p>It seems that completion doesn't work on option values!</p> <p>In some cases options are complex strings where completion might not make sense. (E.g. <code>'comments'</code>.)</p> <p>But have there ...
[ { "answer_id": 7408, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>AFAIK, we can't add cmdline-completion to builtin commands that don't provide it. Either we \"override\" the command ...
2016/04/19
[ "https://vi.stackexchange.com/questions/7406", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/630/" ]
I cannot count the number of times I have tried to do this: ``` :set foldmethod=syn^I ``` It seems that completion doesn't work on option values! In some cases options are complex strings where completion might not make sense. (E.g. `'comments'`.) But have there been any efforts to provide wildchar-completion for ...
You could try the following code: ``` let s:option_values = {'foldmethod' : ['manual', 'indent', 'expr', 'marker', 'syntax'], \ 'bufhidden' : ['hide', 'unload', 'delete', 'wipe'], \ 'virtualedit' : ['block', 'insert', 'all', 'onemore'] ,} set wildcharm=<c-z> cnoremap <exp...
7,413
<p>I want to create abbreviation for a large word, say <code>configuration</code>.</p> <p>Vim command works even if we type part of it. Example, <code>s[ubstitute]</code>.</p> <p>When you type <code>s</code>, <code>su</code>, <code>sub</code>, <code>subs</code>, <code>subst</code>, <code>substi</code>, <code>substit<...
[ { "answer_id": 7415, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": true, "text": "<p>If you really want to use abbreviations, I'm afraid you'll have to </p>\n\n<ul>\n<li>either define one abbreviation fo...
2016/04/19
[ "https://vi.stackexchange.com/questions/7413", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I want to create abbreviation for a large word, say `configuration`. Vim command works even if we type part of it. Example, `s[ubstitute]`. When you type `s`, `su`, `sub`, `subs`, `subst`, `substi`, `substit`, etc., all these keywords work for the same command `substitute`. Likewise, When I type `Conf` or `Confi` or...
If you really want to use abbreviations, I'm afraid you'll have to * either define one abbreviation for each leading part. * or to define a mapping on a trigger like `<tab>` (or whatever) that analyses what is before the cursor in order to expand the missing part. In the end, this is how snippets plugins are expanded...
7,421
<p>Here is my data:</p> <pre><code>{ team: 'NYY', result: 'L', rs: 1,6 }, { team: 'NYY', result: 'W', rs: 4,3 }, { team: 'NYY', result: 'L', rs: 3,6 }, { team: 'NYY', result: 'L', rs: 5,6 }, { team: 'NYY', result: 'L', rs: 4,8 }, { team: 'NYY', result: 'W', rs: 14,4 }, { team: 'NYY', result: 'W', rs: 6,5 }, { team: 'N...
[ { "answer_id": 7423, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 3, "selected": false, "text": "<p>Using <code>\\ze</code> makes this pretty easy. Just match the end of the line so digit followed by ending curly bra...
2016/04/19
[ "https://vi.stackexchange.com/questions/7421", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7298/" ]
Here is my data: ``` { team: 'NYY', result: 'L', rs: 1,6 }, { team: 'NYY', result: 'W', rs: 4,3 }, { team: 'NYY', result: 'L', rs: 3,6 }, { team: 'NYY', result: 'L', rs: 5,6 }, { team: 'NYY', result: 'L', rs: 4,8 }, { team: 'NYY', result: 'W', rs: 14,4 }, { team: 'NYY', result: 'W', rs: 6,5 }, { team: 'NYY', result: '...
Peter's answer achieves the result that you want, but not necessarily the question that you asked. This regular expression will match the Nth occurrence of your PATTERN: ``` \(.\{-}\zsPATTERN\)\{N} ``` To unpack that a little bit, it matches everything non-greedily (that's what the {-} is) though each PATTERN N tim...
7,427
<p>It seems that mappings with <code>@="^E"</code> or <code>@="&lt;c-e&gt;"</code> result in <code>@=""</code> and do nothing. </p> <p>For example if I use <code>nnoremap ^N @="^E"^M</code> then press <kbd>ctrl-n</kbd> I will get a <code>@=""</code> message and nothing happens. However, when I use <code>nnoremap ^N @=...
[ { "answer_id": 7434, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>I think you're not using the good way to do what you want:</p>\n\n<p>The expression register (<code>\"=</code>) is a way ...
2016/04/20
[ "https://vi.stackexchange.com/questions/7427", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7166/" ]
It seems that mappings with `@="^E"` or `@="<c-e>"` result in `@=""` and do nothing. For example if I use `nnoremap ^N @="^E"^M` then press `ctrl-n` I will get a `@=""` message and nothing happens. However, when I use `nnoremap ^N @="^Y"^M` then press `ctrl-n` I receive a `@="^Y"` message and the screen scrolls down....
From `:help c_ctrl-e`: ``` CTRL-E or <End> *c_CTRL-E* *c_<End>* *c_End* cursor to end of command-line ``` In command-line mode, `<C-e>` moves the cursor to the end of the line, and when you are inside the expression register `=`, you are on the command-line. So, when you hit `<C-N>` ...
7,433
<p>Tabnew works when the filename is given directly. I want to open a file using Its alias since the file is far away from the current file path and difficult to remember or type. I use alias command for files in .cshrc file. </p> <p>Example: </p> <pre><code># .cshrc Alias abs vim /project/userid/trees/soft/abs.pl <...
[ { "answer_id": 7435, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 2, "selected": false, "text": "<p>Using a pipeline solves the problem.</p>\n\n<pre><code>:tabnew | !abs\n</code></pre>\n\n<p>Opens the file through alia...
2016/04/20
[ "https://vi.stackexchange.com/questions/7433", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
Tabnew works when the filename is given directly. I want to open a file using Its alias since the file is far away from the current file path and difficult to remember or type. I use alias command for files in .cshrc file. Example: ``` # .cshrc Alias abs vim /project/userid/trees/soft/abs.pl ``` In shell command ...
From `:help backtick-expansion`: ``` *backtick-expansion* *`-expansion* On Unix and a few other systems you can also use backticks for the file name argument, for example: > :next `find . -name ver\\*.c -print` :view `ls -t *.patch \| head -n1` The backslashes before the star are required ...
7,438
<p>I am trying to debug the <a href="https://github.com/tpope/vim-fugitive" rel="nofollow"><code>vim-fugitive</code></a> plugin, to dig into how it works.</p> <p>When I develop a piece of vim script, I am used to testing a function with the <code>debug</code> command. Here it does not work because the function I try t...
[ { "answer_id": 7435, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 2, "selected": false, "text": "<p>Using a pipeline solves the problem.</p>\n\n<pre><code>:tabnew | !abs\n</code></pre>\n\n<p>Opens the file through alia...
2016/04/20
[ "https://vi.stackexchange.com/questions/7438", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
I am trying to debug the [`vim-fugitive`](https://github.com/tpope/vim-fugitive) plugin, to dig into how it works. When I develop a piece of vim script, I am used to testing a function with the `debug` command. Here it does not work because the function I try to access is not in the current scope. ``` debug execute <...
From `:help backtick-expansion`: ``` *backtick-expansion* *`-expansion* On Unix and a few other systems you can also use backticks for the file name argument, for example: > :next `find . -name ver\\*.c -print` :view `ls -t *.patch \| head -n1` The backslashes before the star are required ...
7,453
<p>I am using perl.</p> <p>When I press <code>gf</code> while having the cursor on Testcase, it shows</p> <pre><code>E447: Can't find file "Testcase.pm" in path. </code></pre> <p>So I added that path. </p> <p>It works for files under particular path which are set in <code>:set path</code>. I have several libraries...
[ { "answer_id": 7454, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>You can add <code>**</code> to your path:</p>\n\n<pre><code>set path+=**\n</code></pre>\n\n<p>This way it will find every f...
2016/04/21
[ "https://vi.stackexchange.com/questions/7453", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I am using perl. When I press `gf` while having the cursor on Testcase, it shows ``` E447: Can't find file "Testcase.pm" in path. ``` So I added that path. It works for files under particular path which are set in `:set path`. I have several libraries under subdirectories of lib folder. `/project/tester/userid/S...
You can add `**` to your path: ``` set path+=** ``` This way it will find every file recursively based on your current directory. But apparently [it's not recommended](https://twitter.com/tpope/status/612991667751264256). If you want to add other paths, you can just add them as follow: ``` set path+=/path/to/your/...
7,459
<p>When we execute any system command and get the output, it prints in next line. But I want it in current line, next to the cursor or in place of cursor (not at the start of the current line)</p> <p>Example: </p> <pre><code>:r! ls </code></pre> <p>Prints the list of files in the current folder.</p> <p>But this pri...
[ { "answer_id": 7460, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 4, "selected": true, "text": "<p>One can execute any external command in command line using the <a href=\"http://vimhelp.appspot.com/eval.txt.html#syste...
2016/04/22
[ "https://vi.stackexchange.com/questions/7459", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
When we execute any system command and get the output, it prints in next line. But I want it in current line, next to the cursor or in place of cursor (not at the start of the current line) Example: ``` :r! ls ``` Prints the list of files in the current folder. But this prints the output in next line. Is there an...
One can execute any external command in command line using the [`system`](http://vimhelp.appspot.com/eval.txt.html#system%28%29) function: ``` :let @a = system("ls -ltr") ``` And when you want to paste, press `Ctrl+R` and immediately `a` to paste the content next to cursor. `@a` is the register name. You can use wh...
7,464
<p>I'm on Ubuntu 16.04 (x86_64) and vim 7.4. In <a href="https://gist.github.com/ShabbyX/3691170" rel="nofollow">my config file</a>, I have:</p> <pre><code>set autochdir </code></pre> <p>And this was working for as long as I remember. Just after upgrading to Ubuntu 16.04, I see the following behavior (assume <code>pw...
[ { "answer_id": 7909, "author": "Cliff Stanford", "author_id": 7710, "author_profile": "https://vi.stackexchange.com/users/7710", "pm_score": 4, "selected": true, "text": "<p>This appears to be an issue that was introduced in a patch that was picked up by Ubuntu 16.04 and fixed in another...
2016/04/22
[ "https://vi.stackexchange.com/questions/7464", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/850/" ]
I'm on Ubuntu 16.04 (x86\_64) and vim 7.4. In [my config file](https://gist.github.com/ShabbyX/3691170), I have: ``` set autochdir ``` And this was working for as long as I remember. Just after upgrading to Ubuntu 16.04, I see the following behavior (assume `pwd` is `/path`): * The following commands (`z` is a file...
This appears to be an issue that was introduced in a patch that was picked up by Ubuntu 16.04 and fixed in another patch. Here's a link to the [bug report](https://github.com/vim/vim/issues/704). It was fixed in [patch 1716](https://github.com/vim/vim/commit/baec5c1768098f9dd867b465aaabfdfb294f10c2) but, unfortunately,...
7,470
<p>I have installed YouCompleteMe with Clang completer in OS X 10.10.4, and in my new OS X 10.11.4 I want to reinstall it.</p> <p>The previous installation process downloaded about 140MB at very low speed. I have used the main <a href="https://github.com/Valloric/YouCompleteMe/blob/master/README.md#mac-os-x" rel="nore...
[ { "answer_id": 7471, "author": "Hamid Rouhani", "author_id": 7357, "author_profile": "https://vi.stackexchange.com/users/7357", "pm_score": 5, "selected": true, "text": "<p>I did the following to install (Although I could copy the whole <code>~/.vim</code> directory to the new place inst...
2016/04/22
[ "https://vi.stackexchange.com/questions/7470", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7357/" ]
I have installed YouCompleteMe with Clang completer in OS X 10.10.4, and in my new OS X 10.11.4 I want to reinstall it. The previous installation process downloaded about 140MB at very low speed. I have used the main [tutorial](https://github.com/Valloric/YouCompleteMe/blob/master/README.md#mac-os-x) to install with t...
I did the following to install (Although I could copy the whole `~/.vim` directory to the new place instead of steps 3-6): 1. Install vim 7.4: ``` brew install vim ``` Note: If you are using mac operating system, make sure you create an alias in your bash\_profile pointing to macvim i.e. `which mvim` 2. Install [Vu...
7,480
<p>How can I run a command on all lines delimited, say by <code>\begin{otherlanguage}</code> and <code>\end{otherlanguage}</code>?</p> <p>For example,</p> <pre><code>1 This line should not be affected, 2 \begin{otherlanguage} 3 but this should; 4 \end{otherlanguage} 5 this should not. </code></pre> <...
[ { "answer_id": 7482, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>You can use pattern delimiter for this:</p>\n\n<pre><code>:/first/,/second/norm dd\n</code></pre>\n\n<p>You can use any sea...
2016/04/24
[ "https://vi.stackexchange.com/questions/7480", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4505/" ]
How can I run a command on all lines delimited, say by `\begin{otherlanguage}` and `\end{otherlanguage}`? For example, ``` 1 This line should not be affected, 2 \begin{otherlanguage} 3 but this should; 4 \end{otherlanguage} 5 this should not. ``` (The cmd could be `norm A test`.)
You can use pattern delimiter for this: ``` :/first/,/second/norm dd ``` You can use any search pattern around the `,`. If you want to use only the inside of the matched patterns, use + and - like so: ``` :/first/+1,/second/-1 norm dd ```
7,481
<p>I am root on the machine, and have my .vimrc at <code>/root/.vimrc</code>. Vim ignores this, even though </p> <pre><code># echo $HOME /root </code></pre> <p>If I do</p> <pre><code># vim -u /root/.vimrc some-file-to-edit </code></pre> <p>vim still ignores it. Setting <code>export MYVIMRC=root/.vimrc</code> has ...
[ { "answer_id": 7512, "author": "Alexander Batischev", "author_id": 7415, "author_profile": "https://vi.stackexchange.com/users/7415", "pm_score": 3, "selected": false, "text": "<p>You can see what Vim does on startup with <code>vim -V</code>. Does it touch the file? Is there any errors?<...
2016/04/24
[ "https://vi.stackexchange.com/questions/7481", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7380/" ]
I am root on the machine, and have my .vimrc at `/root/.vimrc`. Vim ignores this, even though ``` # echo $HOME /root ``` If I do ``` # vim -u /root/.vimrc some-file-to-edit ``` vim still ignores it. Setting `export MYVIMRC=root/.vimrc` has no effect. Vim sources my file without problems if I start vim and type ...
Here is what worked for me: First opening vim normally and doing `:scriptnames` showed that, in fact, my `~/.vimrc` *was* sourced. Other scripts were just overridding my indent settings. Moving just the lines pertaining to indentation from my `~/.vimrc` into a new file at `~/.vim/after/ftplugin/python.vim` solved the...
7,492
<p>I'm new to using vim and am currently using pathogen to manage my plugins. I've attempted to install autoclose my placing the <code>autoclose.vim</code> file in it's own directory in bundle. I've also added the line</p> <pre><code>execute pathogen#infect() </code></pre> <p>to the top of my vimrc file, but when I o...
[ { "answer_id": 7512, "author": "Alexander Batischev", "author_id": 7415, "author_profile": "https://vi.stackexchange.com/users/7415", "pm_score": 3, "selected": false, "text": "<p>You can see what Vim does on startup with <code>vim -V</code>. Does it touch the file? Is there any errors?<...
2016/04/25
[ "https://vi.stackexchange.com/questions/7492", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7399/" ]
I'm new to using vim and am currently using pathogen to manage my plugins. I've attempted to install autoclose my placing the `autoclose.vim` file in it's own directory in bundle. I've also added the line ``` execute pathogen#infect() ``` to the top of my vimrc file, but when I open a new vim file the plugin doesn't...
Here is what worked for me: First opening vim normally and doing `:scriptnames` showed that, in fact, my `~/.vimrc` *was* sourced. Other scripts were just overridding my indent settings. Moving just the lines pertaining to indentation from my `~/.vimrc` into a new file at `~/.vim/after/ftplugin/python.vim` solved the...
7,506
<p>In order to overcome my irritation with quoting and comma separating words in a list, I thought I would play with Vim's search and replace to allow myself to type lists like this:</p> <pre><code>daqs = [this is a test of some cool vim stuff for creating a comma separated list of strings] </code></pre> <p>and use a...
[ { "answer_id": 7507, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": true, "text": "<p>I made it work with a different regex:</p>\n\n<pre><code>:'&lt;,'&gt;s/\\%V[^] ]\\+/\\\"&amp;\\\",/g\n</code></pre>\n\n<p>d...
2016/04/26
[ "https://vi.stackexchange.com/questions/7506", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7405/" ]
In order to overcome my irritation with quoting and comma separating words in a list, I thought I would play with Vim's search and replace to allow myself to type lists like this: ``` daqs = [this is a test of some cool vim stuff for creating a comma separated list of strings] ``` and use a regular expression to con...
I made it work with a different regex: ``` :'<,'>s/\%V[^] ]\+/\"&\",/g ``` decomposing: ``` :'<,'>s/ " start a new substitution command \%V " match inside the visual selection [^] ]\+ " match everything but a space and a closing ] (1 or more time) / " replace with \"&\", ...
7,514
<p>I'm pretty new to vimscript, and I wrote this little function to map <code>H</code> so that the cursor will go to the first non-whitespace character of the line, or to the beginning of the line if the cursor is already at the first non-whitespace character. I just want to a) share this for anyone who might find this...
[ { "answer_id": 7516, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 4, "selected": true, "text": "<p>It can definitely be simplified with:</p>\n\n<pre><code>nnoremap &lt;silent&gt;&lt;expr&gt; H indent('.')+1 == col('.') ?...
2016/04/27
[ "https://vi.stackexchange.com/questions/7514", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5043/" ]
I'm pretty new to vimscript, and I wrote this little function to map `H` so that the cursor will go to the first non-whitespace character of the line, or to the beginning of the line if the cursor is already at the first non-whitespace character. I just want to a) share this for anyone who might find this useful, and b...
It can definitely be simplified with: ``` nnoremap <silent><expr> H indent('.')+1 == col('.') ? '0' : '^' ``` `<expr>` causes the map execute the expression on the `{rhs}`. `indent('.')` is the number of whitespace characters at the beginning of the line. The character right after that would be the beginning of the...
7,524
<p>I am trying to encapsulate variables with a method. For example, I am converting this:</p> <pre><code>return variable1; </code></pre> <p>To this:</p> <pre><code>return verify(variable1); </code></pre> <p>Is there a way to quickly repeat this action (ideally with the dot command or a macro of some sort) for other...
[ { "answer_id": 7525, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>If you already have the <a href=\"https://github.com/tpope/vim-surround\" rel=\"nofollow\">surround</a> plugin, you can do <c...
2016/04/27
[ "https://vi.stackexchange.com/questions/7524", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7409/" ]
I am trying to encapsulate variables with a method. For example, I am converting this: ``` return variable1; ``` To this: ``` return verify(variable1); ``` Is there a way to quickly repeat this action (ideally with the dot command or a macro of some sort) for other variables?
If you already have the [surround](https://github.com/tpope/vim-surround) plugin, you can do `ysiwfverify<CR>`. Tim Pope has another plugin called [repeat](https://github.com/tpope/vim-repeat) that lets you repeat surround commands with `.`. Without any plugin or setup, you can simply do `ciwverify(<C-r><C-o>")<Esc>` ...
7,559
<p>How do I search for pattern that is not at the beginning of a line?</p> <p>Ex:</p> <pre><code>Name1 Name2 Name3 Name4 Name5 Name6 </code></pre> <p>Something like:</p> <pre><code>/[^^]Name. </code></pre> <p>Obviously the second <code>^</code> symbol does not mean beginning of line inside <code>[]</code>. Is ther...
[ { "answer_id": 7560, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 2, "selected": false, "text": "<p>You could use a negative lookbehind:</p>\n\n<p><code>\\(^\\)\\@&lt;!Name\\d</code></p>\n\n<p><code>\\( \\)</code> Are ...
2016/04/30
[ "https://vi.stackexchange.com/questions/7559", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7457/" ]
How do I search for pattern that is not at the beginning of a line? Ex: ``` Name1 Name2 Name3 Name4 Name5 Name6 ``` Something like: ``` /[^^]Name. ``` Obviously the second `^` symbol does not mean beginning of line inside `[]`. Is there any symbol that means "not at the beginning of line"?
In original vi, and in tools with POSIX BRE or ERE, there's no way to look for strings not at the beginning of the line. However, in all of these, you can use regex groups to match any character before your actual target pattern, and then keep it unchanged in the replacement. In general, when you want to insert someth...
7,561
<p>Is there a way to make vim jump to the right matching definition <em>automatically</em> in case of multiple definitions. Our C++ code heavily uses function overloading and vim's handling of ctags does not seems to be ready for it.</p> <p>For example, </p> <pre><code>void abc(int a, int b) { } void abc(int a, int...
[ { "answer_id": 7567, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 2, "selected": false, "text": "<p>The documentation (<code>:help ctrl-]</code>) says:</p>\n\n<pre><code>When there are several matching tags for {ident}, jump...
2016/05/01
[ "https://vi.stackexchange.com/questions/7561", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7464/" ]
Is there a way to make vim jump to the right matching definition *automatically* in case of multiple definitions. Our C++ code heavily uses function overloading and vim's handling of ctags does not seems to be ready for it. For example, ``` void abc(int a, int b) { } void abc(int a, int b, int c) { } ``` Strang...
The documentation (`:help ctrl-]`) says: ``` When there are several matching tags for {ident}, jump to the [count] one. When no [count] is given the first one is jumped to. ``` `g]` may not be what you are looking for but that's the best you can get in Vim. Basically, you can't expect ctags and Vim to *understand*...
7,562
<p>Given a series of lines that look similar to this:</p> <pre><code>2001 "Some Kind of Title," Author's Name, Publication Name, 1 Mar. 2002 "Some Kind of Title," Author's Name, Publication Name, 12 Oct. 2003 "Some Kind of Title," Author's Name, Publication Name, 8 Apr. 2004 "Some Kind of Title," Author's Name, Public...
[ { "answer_id": 7563, "author": "Sundeep", "author_id": 1616, "author_profile": "https://vi.stackexchange.com/users/1616", "pm_score": 5, "selected": true, "text": "<pre><code>:% s/\\v^(\\d{4})(.*)$/\\1\\2 \\1/ \n</code></pre>\n\n<p>is one way to do it</p>\n\n<ul>\n<li><code>\\v</code> ma...
2016/05/01
[ "https://vi.stackexchange.com/questions/7562", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7465/" ]
Given a series of lines that look similar to this: ``` 2001 "Some Kind of Title," Author's Name, Publication Name, 1 Mar. 2002 "Some Kind of Title," Author's Name, Publication Name, 12 Oct. 2003 "Some Kind of Title," Author's Name, Publication Name, 8 Apr. 2004 "Some Kind of Title," Author's Name, Publication Name, 3 ...
``` :% s/\v^(\d{4})(.*)$/\1\2 \1/ ``` is one way to do it * `\v` magic option, to avoid having to escape grouping `()` * `^` start of line * `\d{4}` match exactly four digits * `.*` rest of line * `\1` `\2` has the matched pattern within `()` edit: @Jair Lopez mentions in comments, the regular expression can be fu...
7,581
<p>My use case is the following, but I think a general solution, working for as many plugins as possible would be preferable:</p> <p>I use the <a href="https://github.com/kana/vim-submode" rel="noreferrer">submodes plugin</a> to create a submode handling windows. In my <code>.vimrc</code> I have several lines containi...
[ { "answer_id": 7600, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>Normally <code>exists('*submode#enter_with')</code> can be used, however it was returning false in my case.</p>\n\n<p>So ...
2016/05/01
[ "https://vi.stackexchange.com/questions/7581", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
My use case is the following, but I think a general solution, working for as many plugins as possible would be preferable: I use the [submodes plugin](https://github.com/kana/vim-submode) to create a submode handling windows. In my `.vimrc` I have several lines containing calls to functions defined by this plugin (lik...
Normally `exists('*submode#enter_with')` can be used, however it was returning false in my case. So [@VanLaser](https://vi.stackexchange.com/questions/7581/in-my-vimrc-how-to-test-if-a-plugin-is-installed#comment12478_7581) suggested a pretty simple solution using the `try` and `catch` vimscript instruction to execute...
7,587
<p>I adopted the bracket notation, e.g., <code>x[i]</code>, for the discrete signal <code>x</code> where <code>i</code> is the time index. The problem occurs in a <code>pgfplots</code> figure but I figured, the syntax highlighting behavior is due to being math mode in a LaTeX command option, i.e., <code>\begin{command}...
[ { "answer_id": 7592, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 3, "selected": true, "text": "<p>To achieve what you ask is, I believe, quite difficult. I'm the author of <a href=\"https://github.com/lervag/vimte...
2016/05/01
[ "https://vi.stackexchange.com/questions/7587", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7472/" ]
I adopted the bracket notation, e.g., `x[i]`, for the discrete signal `x` where `i` is the time index. The problem occurs in a `pgfplots` figure but I figured, the syntax highlighting behavior is due to being math mode in a LaTeX command option, i.e., `\begin{command}[option] ... \end{command}`. Here is a MWE original...
To achieve what you ask is, I believe, quite difficult. I'm the author of [vimtex](https://github.com/lervag/vimtex/), and I've added some custom syntax highlighting, see [vimtex/after/syntax/tex.vim](https://github.com/lervag/vimtex/blob/master/after/syntax/tex.vim). As you might notice, the syntax highlighting syntax...
7,598
<p>I'm testing the new built-in package manager. From <a href="http://vimhelp.appspot.com/repeat.txt.html#packages" rel="nofollow"><code>:h packages</code></a>:</p> <pre><code>When Vim starts up, after processing your .vimrc, it scans all directories in 'packpath' for plugins under the "pack/*/start" directory. First...
[ { "answer_id": 7592, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 3, "selected": true, "text": "<p>To achieve what you ask is, I believe, quite difficult. I'm the author of <a href=\"https://github.com/lervag/vimte...
2016/05/02
[ "https://vi.stackexchange.com/questions/7598", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/911/" ]
I'm testing the new built-in package manager. From [`:h packages`](http://vimhelp.appspot.com/repeat.txt.html#packages): ``` When Vim starts up, after processing your .vimrc, it scans all directories in 'packpath' for plugins under the "pack/*/start" directory. First all those directories are added to 'runtimepath'. ...
To achieve what you ask is, I believe, quite difficult. I'm the author of [vimtex](https://github.com/lervag/vimtex/), and I've added some custom syntax highlighting, see [vimtex/after/syntax/tex.vim](https://github.com/lervag/vimtex/blob/master/after/syntax/tex.vim). As you might notice, the syntax highlighting syntax...
7,599
<p>I want to set some commands for specific filetypes. For example an abbreviation: </p> <pre><code>:iabbr Sb SameBatch </code></pre> <p>The files have extension like <code>.data</code>, <code>.pro</code>. Their grammar, syntax-highlighting are defined in the framework. I am unaware of those things. Those files conta...
[ { "answer_id": 7592, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 3, "selected": true, "text": "<p>To achieve what you ask is, I believe, quite difficult. I'm the author of <a href=\"https://github.com/lervag/vimte...
2016/05/02
[ "https://vi.stackexchange.com/questions/7599", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I want to set some commands for specific filetypes. For example an abbreviation: ``` :iabbr Sb SameBatch ``` The files have extension like `.data`, `.pro`. Their grammar, syntax-highlighting are defined in the framework. I am unaware of those things. Those files contain variables and their values for Perl scripts. ...
To achieve what you ask is, I believe, quite difficult. I'm the author of [vimtex](https://github.com/lervag/vimtex/), and I've added some custom syntax highlighting, see [vimtex/after/syntax/tex.vim](https://github.com/lervag/vimtex/blob/master/after/syntax/tex.vim). As you might notice, the syntax highlighting syntax...
7,624
<p>I have installed the terminal neovim which starts by <code>nvim</code>, and the graphical neovim. I cannot find the keybinding to start the graphical neovim in Terminal. </p> <p>I installed the neovim by following instructions in Github <a href="https://github.com/neovim/homebrew-neovim/blob/master/README.md" rel=...
[ { "answer_id": 7625, "author": "Alexander Batischev", "author_id": 7415, "author_profile": "https://vi.stackexchange.com/users/7415", "pm_score": 2, "selected": false, "text": "<p>Looks like the only NeoVim GUI for Mac OS X at the moment is <a href=\"https://github.com/rogual/neovim-dot-...
2016/05/04
[ "https://vi.stackexchange.com/questions/7624", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2923/" ]
I have installed the terminal neovim which starts by `nvim`, and the graphical neovim. I cannot find the keybinding to start the graphical neovim in Terminal. I installed the neovim by following instructions in Github [here](https://github.com/neovim/homebrew-neovim/blob/master/README.md), by Homebrew; still checkin...
There is a nice implementation of NeoVim GUI for macOS named [VimR](http://vimr.org) (R = Refined). It has a native file manager and works fine and fast with mouse gestures and macOS UI. VimR comes with a command line tool `vimr`. VimR [repository](https://github.com/qvacua/vimr) is more active and has more stars compa...
7,636
<p>I have several lines in my code. I am aware that Ctrl+x,Ctrl+l shows suggestions for completing a line, based on the similar lines available in the script.</p> <p>Now, I want only the part of a line, delimited by a character, to be shown as suggestions.</p> <p>Example:</p> <pre><code> Print "Verifying the conte...
[ { "answer_id": 7625, "author": "Alexander Batischev", "author_id": 7415, "author_profile": "https://vi.stackexchange.com/users/7415", "pm_score": 2, "selected": false, "text": "<p>Looks like the only NeoVim GUI for Mac OS X at the moment is <a href=\"https://github.com/rogual/neovim-dot-...
2016/05/05
[ "https://vi.stackexchange.com/questions/7636", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I have several lines in my code. I am aware that Ctrl+x,Ctrl+l shows suggestions for completing a line, based on the similar lines available in the script. Now, I want only the part of a line, delimited by a character, to be shown as suggestions. Example: ``` Print "Verifying the contents again"; . . . ...
There is a nice implementation of NeoVim GUI for macOS named [VimR](http://vimr.org) (R = Refined). It has a native file manager and works fine and fast with mouse gestures and macOS UI. VimR comes with a command line tool `vimr`. VimR [repository](https://github.com/qvacua/vimr) is more active and has more stars compa...
7,641
<p>Is it possible to edit a directory inside Vim? (Some commands are working for directories). </p> <p>I want to know what kind of operations can be done in a directory inside Vim. Vim can open the directories for editing, I believe it will have commands also to work with. But usual commands behave differently for dir...
[ { "answer_id": 7642, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>I'm assuming you are using <code>netrw</code> here, as it's the default action when you do <code>vim .</code> or <code>vim ...
2016/05/05
[ "https://vi.stackexchange.com/questions/7641", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
Is it possible to edit a directory inside Vim? (Some commands are working for directories). I want to know what kind of operations can be done in a directory inside Vim. Vim can open the directories for editing, I believe it will have commands also to work with. But usual commands behave differently for directories. ...
I'm assuming you are using `netrw` here, as it's the default action when you do `vim .` or `vim some/directory/`. You can create a file/directory from `netrw` with the following commands: ``` d : create a directory, you will be prompted to input the directory name % : create a file, same workflow ``` Have a look at...
7,644
<p>I do a lot of Python and I use almost all the time a <a href="https://virtualenv.pypa.io/en/latest/" rel="noreferrer">virtualenv</a> along with <a href="http://virtualenvwrapper.readthedocs.io/en/latest/" rel="noreferrer">virtualenvwrapper</a> to keep my modules organised.</p> <p>But when I want to use those plugin...
[ { "answer_id": 7654, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 5, "selected": true, "text": "<p>I actually fixed this myself a long time ago. The problem is that when you run <code>!python</code> you're starting up a...
2016/05/05
[ "https://vi.stackexchange.com/questions/7644", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
I do a lot of Python and I use almost all the time a [virtualenv](https://virtualenv.pypa.io/en/latest/) along with [virtualenvwrapper](http://virtualenvwrapper.readthedocs.io/en/latest/) to keep my modules organised. But when I want to use those plugin from inside vim, through an external command, it seems that the s...
I actually fixed this myself a long time ago. The problem is that when you run `!python` you're starting up a new shell with your existing environment. But, this means `workon xxxx` wasn't called to actually activate the virtualenv. This lead to a lot of confusion for me since `$VIRTUAL_ENV` was set. I got around it b...
7,645
<p>I'd like to be able to highlight the current line the cursor is at, but not for files from certain directories. That's because I noticed the rendering becomes slow if I highlight the lines within a Rails project - probably because I use rails.vim and its slowing down things.</p> <p>So, is there a way to highlight c...
[ { "answer_id": 7646, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 2, "selected": false, "text": "<p>I assume by \"Highlight current line\" that you're referring to the <code>set cursorline</code> option?</p>\n\n<p>Soun...
2016/05/05
[ "https://vi.stackexchange.com/questions/7645", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7521/" ]
I'd like to be able to highlight the current line the cursor is at, but not for files from certain directories. That's because I noticed the rendering becomes slow if I highlight the lines within a Rails project - probably because I use rails.vim and its slowing down things. So, is there a way to highlight current lin...
I assume by "Highlight current line" that you're referring to the `set cursorline` option? Sounds like a job for autocmd's I'd do something like: ``` autocmd BufEnter * call UnhighlightLine() function! UnhighlightLine() if (expand('%:p') =~ '/Work/my_rails_project_1\|/Work/my_rails_project_2') set nocursor...
7,647
<p>In Vim, <code>C-x C-l</code> performs line completion. However, it expects the prefix of the currently typed line to match the prefix of another line. For example, consider that <code>|</code> below denotes the cursor position:</p> <pre><code>; A sentence I would like to auto complete. ... A sentence| </code></pre>...
[ { "answer_id": 7650, "author": "jecxjo", "author_id": 895, "author_profile": "https://vi.stackexchange.com/users/895", "pm_score": 2, "selected": false, "text": "<p>Here is a single line solution.</p>\n\n<pre><code>:inoremap &lt;C-X&gt;&lt;C-L&gt; &lt;ESC&gt;mm:/&lt;C-R&gt;=substitute(ge...
2016/05/05
[ "https://vi.stackexchange.com/questions/7647", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6894/" ]
In Vim, `C-x C-l` performs line completion. However, it expects the prefix of the currently typed line to match the prefix of another line. For example, consider that `|` below denotes the cursor position: ``` ; A sentence I would like to auto complete. ... A sentence| ``` When I press `C-x C-l`, line completion obv...
It's ... built-in. It's just not line completion, because, you're saying it, it's not an entire line you want to complete. If we start from your example: ``` ; A sentence I would like to auto complete. ... A sentence| ``` If I now press `C-n`, followed by `C-x C-n` (secret sauce! - *context* completion) it will co...
7,656
<p>I want to work between two vimwiki directories: a private vimwiki and a public vimwiki.</p> <p>How do I get multiple vimwikis in the gvim <code>Vimwiki &gt; Open index &gt;</code> menu?</p> <p>In my ~/.vimrc I have the two wikis defined:</p> <pre><code>" vimwiki let wiki_1 = {} let wiki_1.path = '~/vimwiki' let...
[ { "answer_id": 7911, "author": "StandardEyre", "author_id": 6590, "author_profile": "https://vi.stackexchange.com/users/6590", "pm_score": 4, "selected": true, "text": "<p>I was missing a trailing slash on both <code>wiki_?.path</code> values.</p>\n\n<p>I corrected my ~/.vimrc as follows...
2016/05/06
[ "https://vi.stackexchange.com/questions/7656", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6590/" ]
I want to work between two vimwiki directories: a private vimwiki and a public vimwiki. How do I get multiple vimwikis in the gvim `Vimwiki > Open index >` menu? In my ~/.vimrc I have the two wikis defined: ``` " vimwiki let wiki_1 = {} let wiki_1.path = '~/vimwiki' let wiki_1.path_html = '~/vimwiki_html' let wiki_...
I was missing a trailing slash on both `wiki_?.path` values. I corrected my ~/.vimrc as follows: ``` " vimwiki let wiki_1 = {} let wiki_1.path = '~/vimwiki/' let wiki_1.path_html = '~/vimwiki_html/' let wiki_2 = {} let wiki_2.path = '~/private/' let wiki_2.path_html = '~/private_html/' let g:vimwiki_list = [wiki_1...
7,658
<p>I use the same versioned .vimrc on several machines. </p> <p>Is there a way of customise that file to enable/disable a plugin based on machine name or something like that?</p> <p>As example, I have something like that in my .bash_profile:</p> <pre class="lang-bash prettyprint-override"><code># common things ... ...
[ { "answer_id": 7659, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 3, "selected": false, "text": "<p>Provided that you (or your system) can export the environmental variables that you need, you can do something like this...
2016/05/06
[ "https://vi.stackexchange.com/questions/7658", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6754/" ]
I use the same versioned .vimrc on several machines. Is there a way of customise that file to enable/disable a plugin based on machine name or something like that? As example, I have something like that in my .bash\_profile: ```bash # common things ... if [[ $(uname) == "Darwin" ]] then # mac settings else ...
You can access your environment variable and external command from vim, so you can do: ``` if system('uname') =~ "Darwin" echo 'mac' else echo 'other' endif ``` Note that you can use `=~` instead of `==` to match the regex instead of the exact string (on my machine, `uname` gives me a newline). or ``` if...
7,662
<p>How to put at end of line with vim?</p> <p>I would like to use <code>p</code> to put some text at the end of the current line without moving the cursor.</p> <p>Edit:</p> <p>For example I would like to copy a word to the end of the line so I use <code>yw</code> to copy the word and then how can I put it to the end...
[ { "answer_id": 7663, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 2, "selected": false, "text": "<p>If I understand correctly, you want to <strong>put</strong> a word at the end of the line.</p>\n\n<p>You can do that with:...
2016/05/06
[ "https://vi.stackexchange.com/questions/7662", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5154/" ]
How to put at end of line with vim? I would like to use `p` to put some text at the end of the current line without moving the cursor. Edit: For example I would like to copy a word to the end of the line so I use `yw` to copy the word and then how can I put it to the end of the current line?
If you want your cursor back to its previous position after putting the text at the end of the line you could use marks: ``` ma$p`a ``` * `ma` sets the mark `a` to the current position * `$p` As explained is the other answers put the text at the end of the line * `(backtick)a` go back to the position marked by `ma`
7,665
<p>I want to open another file in the same directory or any file with its path relative to the current directory in command line.</p> <p>My path is <code>/home/sibich/</code></p> <pre><code> /home/sibich&gt; vim a.pl </code></pre> <p>In vim, I want to open b.pl in same directory, so I use :</p> <pre><code>:vim b....
[ { "answer_id": 7666, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 5, "selected": true, "text": "<p>Have you tried the edit command?</p>\n\n<pre><code>:edit b.pl\n</code></pre>\n\n<p>Edit: Not sure if you edited in the ...
2016/05/06
[ "https://vi.stackexchange.com/questions/7665", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I want to open another file in the same directory or any file with its path relative to the current directory in command line. My path is `/home/sibich/` ``` /home/sibich> vim a.pl ``` In vim, I want to open b.pl in same directory, so I use : ``` :vim b.pl ``` Bit I receive this message `Invalid pattern or file...
Have you tried the edit command? ``` :edit b.pl ``` Edit: Not sure if you edited in the last question, or I just missed it the first time. But the only reason you wouldn't be able to use relative paths on `:split` or `:tabnew` is if your current working directory isn't the same as the file you're currently editing. ...
7,672
<p>I have an XML file with this format (there could be some leading spaces):</p> <pre><code> &lt;Latitude&gt;23.1138&lt;/Latitude&gt; &lt;Longitude&gt;8.2898&lt;/Longitude&gt; ... &lt;Latitude&gt;19.6247&lt;/Latitude&gt; &lt;Longitude&gt;-7.3267&lt;/Longitude&gt; ... &lt;Latitude&gt;49.4141&...
[ { "answer_id": 7673, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": true, "text": "<p>I've come up with a search and replace function that should work for you:</p>\n\n<pre><code>:%s/\\(\\s*\\)&lt;Latitude&...
2016/05/06
[ "https://vi.stackexchange.com/questions/7672", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7298/" ]
I have an XML file with this format (there could be some leading spaces): ``` <Latitude>23.1138</Latitude> <Longitude>8.2898</Longitude> ... <Latitude>19.6247</Latitude> <Longitude>-7.3267</Longitude> ... <Latitude>49.4141</Latitude> <Longitude>15.374</Longitude> ``` Using Vim, I woul...
I've come up with a search and replace function that should work for you: ``` :%s/\(\s*\)<Latitude>\(-\=\d\+\.\d\+\)<\/Latitude>\_.\s*<Longitude>\(-\=\d\+\.\d\+\)<\/Longitude>/\1<Point><coordinates>\3,\2<\/coordinates><\/Point>/ ``` Make sure to save your work as this command is destructive. `:%s` Does a search and...
7,684
<p>When I try and trigger PHPUnit tests within MacVim, I can't see coloured outputs in my command line:</p> <p><a href="https://i.stack.imgur.com/ntJRx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ntJRx.png" alt="enter image description here"></a></p>
[ { "answer_id": 7692, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 2, "selected": true, "text": "<p>The GUI version of Vim (MacVim on Mac OS X, GVim everywhere else) comes with a \"dumb\" terminal emulator that doesn't unders...
2016/05/07
[ "https://vi.stackexchange.com/questions/7684", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5991/" ]
When I try and trigger PHPUnit tests within MacVim, I can't see coloured outputs in my command line: [![enter image description here](https://i.stack.imgur.com/ntJRx.png)](https://i.stack.imgur.com/ntJRx.png)
The GUI version of Vim (MacVim on Mac OS X, GVim everywhere else) comes with a "dumb" terminal emulator that doesn't understand color at all. If you want to run command-line programs without the ugly escape codes you'll need to either configure those programs to not use color when not possible or call them with dedica...
7,699
<p>In Vim, I don't like how when you reach end of file it puts the last line at the bottom of the screen.</p> <p>Is there anyway to make the last line be something like 10 lines above the bottom of the screen and just make blank lines under it?</p>
[ { "answer_id": 7700, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>You can use <kbd>ctrl</kbd><kbd>E</kbd> to scroll down your file, when you are at the end of the file it will add \"virtua...
2016/05/09
[ "https://vi.stackexchange.com/questions/7699", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7571/" ]
In Vim, I don't like how when you reach end of file it puts the last line at the bottom of the screen. Is there anyway to make the last line be something like 10 lines above the bottom of the screen and just make blank lines under it?
You can use `ctrl``E` to scroll down your file, when you are at the end of the file it will add "virtual" line so the last line of the file is not at the bottom of the windows. Additionally you can use the option `scrolloff` to always let some lines after your cursor, add this to your `.vimrc`: ``` set scrolloff=10 ...
7,713
<p>We can retrieve search and replace history on IDEs and text editors. Likewise is there a search history or a way to retrieve previously searched expression in vim?</p>
[ { "answer_id": 7714, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 6, "selected": true, "text": "<p>Yes, you have the <code>history</code> command:</p>\n\n<pre><code>:history /\n</code></pre>\n\n<p>Note that it can be used ...
2016/05/10
[ "https://vi.stackexchange.com/questions/7713", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7501/" ]
We can retrieve search and replace history on IDEs and text editors. Likewise is there a search history or a way to retrieve previously searched expression in vim?
Yes, you have the `history` command: ``` :history / ``` Note that it can be used for `/`, `:`, `=`, `>`, `?`, `@`, `all`, `cmd`, `debug`, `expr`, `input` and `search`. Alternatively you can use the `q:`, `q/` and `q?` commands to see previously entered commands and searches on a sepearate buffer. You can then modif...
7,719
<p>Sometimes, when I edit a large file, I like to focus only on a part of the document and not all of it.</p> <p>Is it possible to create a sort of fold that wrap a part of the document (e.g. the current function/paragraph) so the focus is narrowed on that ?</p> <p>The idea would be to produce something like this:</p...
[ { "answer_id": 7720, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>A very basic solution would be to use the following macro:</p>\n\n<pre><code>qqggzf'&lt;'&gt;zfGq\n</code></pre>\n\n<p>Fir...
2016/05/10
[ "https://vi.stackexchange.com/questions/7719", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
Sometimes, when I edit a large file, I like to focus only on a part of the document and not all of it. Is it possible to create a sort of fold that wrap a part of the document (e.g. the current function/paragraph) so the focus is narrowed on that ? The idea would be to produce something like this: ``` + --- the fold...
A very basic solution would be to use the following macro: ``` qqggzf'<'>zfGq ``` First visually select the text you want to focus on and use the macro with `@q`. To detail: * `qq` start recording the macro * `gg` go to the top of the buffer * `zf` start a folding from your position (the first line) * `'<` fold to...
7,726
<p>We can use the <code>u</code>, <code>&lt;C-R&gt;</code> to undo/redo in Vim and it provides a lot of features to manage the undo tree.</p> <p>But sometimes, I make a change (let say on line 1) and I go do some other changes on another line.</p> <p>When I come back to line 1, I may think that the previous value of ...
[ { "answer_id": 7720, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>A very basic solution would be to use the following macro:</p>\n\n<pre><code>qqggzf'&lt;'&gt;zfGq\n</code></pre>\n\n<p>Fir...
2016/05/10
[ "https://vi.stackexchange.com/questions/7726", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
We can use the `u`, `<C-R>` to undo/redo in Vim and it provides a lot of features to manage the undo tree. But sometimes, I make a change (let say on line 1) and I go do some other changes on another line. When I come back to line 1, I may think that the previous value of this line was better. My current workflow is...
A very basic solution would be to use the following macro: ``` qqggzf'<'>zfGq ``` First visually select the text you want to focus on and use the macro with `@q`. To detail: * `qq` start recording the macro * `gg` go to the top of the buffer * `zf` start a folding from your position (the first line) * `'<` fold to...
7,732
<p>I never made any plugins but I would like to get some advice for a specific case. </p> <p>I'm writing a lot of ruby. Sometimes I have very long lines that I want to split.</p> <p>Example: </p> <pre><code>MyModel.first_method.second_method(arg).third_method(arg.method) </code></pre> <p>to</p> <pre><code>MyModel ...
[ { "answer_id": 7720, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>A very basic solution would be to use the following macro:</p>\n\n<pre><code>qqggzf'&lt;'&gt;zfGq\n</code></pre>\n\n<p>Fir...
2016/05/11
[ "https://vi.stackexchange.com/questions/7732", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3357/" ]
I never made any plugins but I would like to get some advice for a specific case. I'm writing a lot of ruby. Sometimes I have very long lines that I want to split. Example: ``` MyModel.first_method.second_method(arg).third_method(arg.method) ``` to ``` MyModel .first_method .second_method(arg) .third_meth...
A very basic solution would be to use the following macro: ``` qqggzf'<'>zfGq ``` First visually select the text you want to focus on and use the macro with `@q`. To detail: * `qq` start recording the macro * `gg` go to the top of the buffer * `zf` start a folding from your position (the first line) * `'<` fold to...
7,734
<p>I am developing a plugin for Vim and I would like to define a mapping which would be available only while the "execution of the plugin".</p> <p>So far the (simplified) workflow of the plugin is the following:</p> <ol> <li>The user call a command of the plugin</li> <li><p>The command calls the pre-treatment functio...
[ { "answer_id": 7735, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 6, "selected": true, "text": "<p>You could use the <code>maparg()</code> function.</p>\n\n<p>To test if the user mapped something to <code>&lt;C-c&gt;...
2016/05/11
[ "https://vi.stackexchange.com/questions/7734", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
I am developing a plugin for Vim and I would like to define a mapping which would be available only while the "execution of the plugin". So far the (simplified) workflow of the plugin is the following: 1. The user call a command of the plugin 2. The command calls the pre-treatment function: ``` function! s:PreTreatm...
You could use the `maparg()` function. To test if the user mapped something to `<C-c>` in normal mode, you would write: ``` if !empty(maparg('<C-c>', 'n')) ``` If the user mapped something, to store the `{rhs}` in a variable, you would write: ``` let rhs_save = maparg('<C-c>', 'n') ``` If you want more informati...
7,741
<p>I have a common usecase when I transform some python expression the following way:</p> <pre><code>value 1 value 2 value 3 </code></pre> <p>into</p> <pre><code>['value 1', 'value 2', 'value 3'] </code></pre> <p>The easiest way may be to use a mapping, but I wanted to use a substitution for this task.</p> <p>So f...
[ { "answer_id": 7746, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 4, "selected": true, "text": "<p><strong>Edit</strong> </p>\n\n<p>It is possible to do this in one expression if we use a \"sub-replace-expression.\" Se...
2016/05/11
[ "https://vi.stackexchange.com/questions/7741", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
I have a common usecase when I transform some python expression the following way: ``` value 1 value 2 value 3 ``` into ``` ['value 1', 'value 2', 'value 3'] ``` The easiest way may be to use a mapping, but I wanted to use a substitution for this task. So far I got: ``` s/\(.*\n\)\+/[&]/g ``` Which result in ...
**Edit** It is possible to do this in one expression if we use a "sub-replace-expression." See bottom for info on that. **/Edit** The problem here is that you want to do two different things. 1. Operate on the match as a whole (i.e. surround it with `[]`) 2. Operate on each item in the match (i.e. surround them wi...
7,750
<p>I have over 500 abbreviations(<code>iabbr</code>, <code>abbr</code>) and some mappings in my vimrc file from Java, PHP, C/C++ and Latex.</p> <p>It is not easy to remember right away when I don't use the languages for some time.</p> <p>I'm wondering whether I can do completion on abbreviation name. Is there any bet...
[ { "answer_id": 7751, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>A wikia <a href=\"http://vim.wikia.com/wiki/VimTip267\">tip</a> suggest a method to selectively display your abbreviation...
2016/05/12
[ "https://vi.stackexchange.com/questions/7750", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7597/" ]
I have over 500 abbreviations(`iabbr`, `abbr`) and some mappings in my vimrc file from Java, PHP, C/C++ and Latex. It is not easy to remember right away when I don't use the languages for some time. I'm wondering whether I can do completion on abbreviation name. Is there any better way to access/manage all these abbr...
I don't know what's the best way to manage over 500 abbreviations. Maybe in the long term, as @statox explained, you could have a look at snippets to reduce this number. And if you want to auto-complete abbreviations, you could try the following code: ``` augroup GetAbbrev autocmd! autocmd VimEnter * let s:ab...
7,754
<p>If I have the following:</p> <pre><code>function foo(bar) { return bar + 1; } </code></pre> <p>And I use <code>cw</code> to change the first <code>bar</code> to <code>baz</code>, how do I jump to the next matching <code>bar</code>, so that I can use <code>.</code> to make the same change?</p> <p>I can't use <...
[ { "answer_id": 7755, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": true, "text": "<p>The text you just changed with <code>cw</code> was cut into the unnamed register so you can reuse it with:</p>\n\n<pre><code>...
2016/05/12
[ "https://vi.stackexchange.com/questions/7754", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5339/" ]
If I have the following: ``` function foo(bar) { return bar + 1; } ``` And I use `cw` to change the first `bar` to `baz`, how do I jump to the next matching `bar`, so that I can use `.` to make the same change? I can't use `*`, because that searches for the *current* word under the cursor, and I foolishly didn'...
The text you just changed with `cw` was cut into the unnamed register so you can reuse it with: ``` /<C-r>"<CR> ``` to jump to the next occurrence of the text covered by your last change.
7,761
<p>I am trying to code a function that replaces the character in the sixth column of my current line with a dollar symbol (<code>$</code>), but I would like my cursor to remain at the position it was before calling the function. </p> <p>So I tried to store the current column, execute my changes, and then come back wit...
[ { "answer_id": 7762, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>You should use <code>getpos()</code>:</p>\n\n<p>To save you position in a variable:</p>\n\n<pre><code>let save_pos = getpo...
2016/05/12
[ "https://vi.stackexchange.com/questions/7761", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7128/" ]
I am trying to code a function that replaces the character in the sixth column of my current line with a dollar symbol (`$`), but I would like my cursor to remain at the position it was before calling the function. So I tried to store the current column, execute my changes, and then come back with the following funct...
You should use `getpos()`: To save you position in a variable: ``` let save_pos = getpos(".") ``` `getpos()` takes as argument a mark, here `"."` represents the current position of your cursor. And to restore it: ``` call setpos('.', save_pos) ``` Here the first argument indicate that you will move the mark of ...
7,767
<p>I use Vim to write my Python source and use the debugging library <code>pdb</code>.</p> <p>Let's say I have this code with break points commented out:</p> <pre><code>import pdb #pdb.set_trace() def func1(): #pdb.set_trace() foo_bar </code></pre> <p>I then want to globally un-comment all the <code>pdb.se...
[ { "answer_id": 7768, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 2, "selected": false, "text": "<p>You should be able to do a search and replace.</p>\n\n<pre><code>:%s/^\\(\\s*\\)#\\(\\s*pdb.set_trace()\\)/\\1\\2/\n</...
2016/05/12
[ "https://vi.stackexchange.com/questions/7767", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7607/" ]
I use Vim to write my Python source and use the debugging library `pdb`. Let's say I have this code with break points commented out: ``` import pdb #pdb.set_trace() def func1(): #pdb.set_trace() foo_bar ``` I then want to globally un-comment all the `pdb.set_trace()` commands. Also, I'll want to re-commen...
Alternatively, you could use the `:g` command. I would do: ``` :g/\s*#pdb.set_trace()/normal ^x ``` to uncomment and ``` :g/\s*pdb.set_trace()/normal I# ``` to comment. This is nice because it's more readable (and shorter) than a search and replace command. Explanation: ``` :g/\s*#pdb.set_trace()/ "...
7,775
<p>For example, to replace current line with all lines starting with '# ' , I use</p> <pre><code>:.! grep '^\# ' % </code></pre> <p>I know about the <code>:g</code> command that can filter lines to perform operations like</p> <pre><code>:g/call/d :g/cat/ s/animal/mammal/g :.,+20 g/^# / normal &gt;&gt; </code></pre> ...
[ { "answer_id": 7776, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 1, "selected": false, "text": "<p>You can redirect the ex command output to any register and then paste the register's content in a line.</p>\n\n<pre><c...
2016/05/13
[ "https://vi.stackexchange.com/questions/7775", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1616/" ]
For example, to replace current line with all lines starting with '# ' , I use ``` :.! grep '^\# ' % ``` I know about the `:g` command that can filter lines to perform operations like ``` :g/call/d :g/cat/ s/animal/mammal/g :.,+20 g/^# / normal >> ``` But I am not able to figure out a way to just paste the filter...
Here is a way to do so, it gives nearly what you want, so you may be able to build your proper solution on that. tl;dr ===== set a mark on the line to copy to with `ma` and run ``` :g/C/t'a- ``` decomposition ============= First of you can use the `g` command here, it filters lines matching a pattern. Then you ca...
7,795
<p>Is there a way to make a function in vim that takes the difference between two time stamps under highlight?</p> <p>For example:</p> <pre><code>1 20:37:00 2 20:42:30 </code></pre> <p>Supposing you highlight lines <code>1</code> and <code>2</code> and run the command, say, <code>:TimeDifference</code>, you get the...
[ { "answer_id": 7796, "author": "Jair López", "author_id": 6698, "author_profile": "https://vi.stackexchange.com/users/6698", "pm_score": 4, "selected": true, "text": "<p>You could try the following code:</p>\n\n<pre><code>\" line1 is the line number the first timestamp is on.\n\" line2 i...
2016/05/14
[ "https://vi.stackexchange.com/questions/7795", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6499/" ]
Is there a way to make a function in vim that takes the difference between two time stamps under highlight? For example: ``` 1 20:37:00 2 20:42:30 ``` Supposing you highlight lines `1` and `2` and run the command, say, `:TimeDifference`, you get the output `5.5` (i.e., `5.5` minutes) which replaces lines `1` and `...
You could try the following code: ``` " line1 is the line number the first timestamp is on. " line2 is the line number the second timestamp is on. function! GetTimeDifference(line1,line2) " Get line content and split it where ":" matches. let l:t1List = split( getline(a:line1), ":" ) let l:t2List = split( ...
7,803
<p>I am trying to come up with a way to handle C++ projects with Vim. I have sorted out syntax and code completion etc. to some extend. Now, I am curios to hear about how people handle their Build > Make > Run cycles for their projects.</p> <p>This is what I have so far:</p> <p>1) For the <code>build</code> stage I u...
[ { "answer_id": 7796, "author": "Jair López", "author_id": 6698, "author_profile": "https://vi.stackexchange.com/users/6698", "pm_score": 4, "selected": true, "text": "<p>You could try the following code:</p>\n\n<pre><code>\" line1 is the line number the first timestamp is on.\n\" line2 i...
2016/05/14
[ "https://vi.stackexchange.com/questions/7803", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5328/" ]
I am trying to come up with a way to handle C++ projects with Vim. I have sorted out syntax and code completion etc. to some extend. Now, I am curios to hear about how people handle their Build > Make > Run cycles for their projects. This is what I have so far: 1) For the `build` stage I use CMake. I am invoking CMak...
You could try the following code: ``` " line1 is the line number the first timestamp is on. " line2 is the line number the second timestamp is on. function! GetTimeDifference(line1,line2) " Get line content and split it where ":" matches. let l:t1List = split( getline(a:line1), ":" ) let l:t2List = split( ...
7,816
<p>I have a <a href="https://vi.stackexchange.com/questions/7761/how-to-restore-the-position-of-the-cursor-after-executing-a-normal-command">function</a> that changes the 6th caracter of a line to a dollar symbol (<code>$</code>). </p> <p>I want it to be performed on several lines, so I naively did a "while" loop usin...
[ { "answer_id": 7820, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 2, "selected": false, "text": "<p>You can use the following replace:</p>\n\n<pre><code>function! DollarSplit(nlines)\n let current_pos = getpos(\".\")\n\n...
2016/05/17
[ "https://vi.stackexchange.com/questions/7816", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7128/" ]
I have a [function](https://vi.stackexchange.com/questions/7761/how-to-restore-the-position-of-the-cursor-after-executing-a-normal-command) that changes the 6th caracter of a line to a dollar symbol (`$`). I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under). ...
``` function! DollarSplit() range let current_pos = getpos(".") execute a:firstline . "," . a:lastline . "normal! 6|r$" call setpos(".", current_pos) endfunction ``` See `:help function-range-example`.
7,832
<p>A lot of operator like <code>delete</code>, <code>change</code>, <code>indent</code>, <code>switch-case</code> accept a motion to apply on.</p> <p>For example, let say I want to replace the current word with all letter <code>a</code>, I do:</p> <pre><code>viwra </code></pre> <p>Compared to the imagined:</p> <pre...
[ { "answer_id": 7833, "author": "jecxjo", "author_id": 895, "author_profile": "https://vi.stackexchange.com/users/895", "pm_score": 2, "selected": false, "text": "<p><code>Replace</code> is a specific type of situation, that I don't believe is equivalent to the others you listed that take...
2016/05/17
[ "https://vi.stackexchange.com/questions/7832", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
A lot of operator like `delete`, `change`, `indent`, `switch-case` accept a motion to apply on. For example, let say I want to replace the current word with all letter `a`, I do: ``` viwra ``` Compared to the imagined: ``` riwa ``` Why isn't it the same for the `replace` command? It's obviously by design, do yo...
Actually. There is **no** reason, apart from things being as they are, that would be against an `r` operator. The simple fact that `viwra` works means that `riwa` *could* work. The reason is simply a historical one, but there is nothing against an alternative implementation. It can help 'filling' some area defined by a...
7,834
<p>I recently switched to Neovim and was trying to install the code checking plugin 'Neomake'. I followed the instructions for the setup in my vimrc. The plugin seems to run fine but the error list was not populated with errors even when I put in intentional errors.</p> <p>A section of my vimrc:</p> <pre><code>let g:...
[ { "answer_id": 9136, "author": "arsenbonbon", "author_id": 8751, "author_profile": "https://vi.stackexchange.com/users/8751", "pm_score": 2, "selected": false, "text": "<p>I just had the same problem as soon as I started adding options, I had to copy the error format from the plugin code...
2016/05/17
[ "https://vi.stackexchange.com/questions/7834", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7563/" ]
I recently switched to Neovim and was trying to install the code checking plugin 'Neomake'. I followed the instructions for the setup in my vimrc. The plugin seems to run fine but the error list was not populated with errors even when I put in intentional errors. A section of my vimrc: ``` let g:neomake_python_flake8...
I just had the same problem as soon as I started adding options, I had to copy the error format from the plugin code to my options: ``` let g:neomake_python_flake8_maker = { \ 'args': ['--ignore=E221,E241,E272,E251,W702,E203,E201,E202', '--format=default'], \ 'errorformat': \ '%E%f:%l: could not compi...
7,835
<p>In vim when searching or replacing an exact word you need to type: </p> <pre><code>\&lt;word\&gt; </code></pre> <p>to match it exactly, this is cumbersome to type, and I find myself wanting to search/replace exact words a lot more often by default than part of a word. Is there a way to let vim use exact words by d...
[ { "answer_id": 7837, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 3, "selected": false, "text": "<p>There isn't an option to treat the whole pattern as word bounded as far as I know. Since you want to <em>replace</em>, ...
2016/05/17
[ "https://vi.stackexchange.com/questions/7835", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1305/" ]
In vim when searching or replacing an exact word you need to type: ``` \<word\> ``` to match it exactly, this is cumbersome to type, and I find myself wanting to search/replace exact words a lot more often by default than part of a word. Is there a way to let vim use exact words by default, and then turn this optio...
There isn't an option to treat the whole pattern as word bounded as far as I know. Since you want to *replace*, that means the text is already in the buffer. You could use `*` or `#` on the word in normal mode which performs the `\<word\>` search for you. Then, `cgn` to replace the next occurrence, and `.` to repeat it...
7,842
<p>I have some 30 characters in a line. When I press <code>80|</code>, it should move 50 character to the right, thus move the cursor to 80th character. (30, 50, 80 are for examples)</p> <p>How to achieve this using mapping or commands? I tried </p> <pre><code> :nmap &lt;Bar&gt; a&lt;Space&gt; </code></pre> <p>It ...
[ { "answer_id": 7843, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": false, "text": "<p>There you go, a neat one-liner:</p>\n\n<pre><code>inoremap &lt;bar&gt; &lt;esc&gt;:execute \"normal!\".(input('Fill &gt; '...
2016/05/18
[ "https://vi.stackexchange.com/questions/7842", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I have some 30 characters in a line. When I press `80|`, it should move 50 character to the right, thus move the cursor to 80th character. (30, 50, 80 are for examples) How to achieve this using mapping or commands? I tried ``` :nmap <Bar> a<Space> ``` It doesn't work.
You can use [`'virtualedit'`](https://vimhelp.appspot.com/options.txt.html#%27virtualedit%27) to allow moving to columns that don't contain text. If you `set virtualedit=all`, then `80|` will place the cursor on column 80. No spaces will be inserted until you actually perform some text editing there, though. If your s...
7,851
<p>Vim builtin indentation seems to get confused with the following script. I cannot get Vim to indent properly the while-loop after the pipe.</p> <pre class="lang-bash prettyprint-override"><code>#!/bin/bash while true do # while loop is indented correctly while read line do echo $line done &...
[ { "answer_id": 7852, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 2, "selected": false, "text": "<p>I made the indentation works by splitting the <code>cat</code>/<code>while</code> like so:</p>\n\n<pre><code>while true\nd...
2016/05/18
[ "https://vi.stackexchange.com/questions/7851", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7670/" ]
Vim builtin indentation seems to get confused with the following script. I cannot get Vim to indent properly the while-loop after the pipe. ```bash #!/bin/bash while true do # while loop is indented correctly while read line do echo $line done < myfile # while loop after a pipe is NOT ind...
You can't get what you want in this case without writing your own indent script or breaking up the lines like in Nobe4's answer. Take a look at `GetShIndent()` in `$VIMRUNTIME/indent/sh.vim` It looks for the **previous** non-blank line that starts with `while` and increases the indent level. However, it checks if the ...
7,853
<p>I do </p> <pre><code>find $HOME -type f -name "*.tex" -exec grep -il "$1" {} + | vim - </code></pre> <p>I cannot exit vim with <code>q</code> only because it gives the error which I do not understand why</p> <pre><code>E37: No write since last change (add ! to override) </code></pre> <p>So you have to do <code>q...
[ { "answer_id": 7854, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 3, "selected": false, "text": "<p>You are piping content into Vim, so it's starting a new <em>unsaved</em> buffer. If you don't need to save the content,...
2016/05/18
[ "https://vi.stackexchange.com/questions/7853", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2923/" ]
I do ``` find $HOME -type f -name "*.tex" -exec grep -il "$1" {} + | vim - ``` I cannot exit vim with `q` only because it gives the error which I do not understand why ``` E37: No write since last change (add ! to override) ``` So you have to do `q!` instead. However, I would like to let Vim know that there is ...
You can change `vim -` to `vim -R -`. From the manual: > > Read-only mode. The 'readonly' option will be set. You can still > edit the buffer, but will be prevented from accidently overwriting > a file. If you do want to overwrite a file, add an exclamation mark > to the Ex command, as in ":w!". The -R option als...
7,859
<p>When typing fast, sometimes the <code>:q</code> is taken as <code>:Q</code> and it is annoying when you have to repeat that for twice or thrice before actually quitting the Vim session. </p> <p>Is there a way to make <code>:Q</code> to <code>:q</code> to overcome the above said problem ?</p>
[ { "answer_id": 7860, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": -1, "selected": false, "text": "<p>You can use command abbreviation for it. </p>\n\n<pre><code> :cabbr Q q\n</code></pre>\n\n<p>Put this in ~/.vimrc fil...
2016/05/19
[ "https://vi.stackexchange.com/questions/7859", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7667/" ]
When typing fast, sometimes the `:q` is taken as `:Q` and it is annoying when you have to repeat that for twice or thrice before actually quitting the Vim session. Is there a way to make `:Q` to `:q` to overcome the above said problem ?
Instead of mapping or abbreviating, I would use a custom command to actually create a new behavior for this edge-case: ``` command! Q :q ``` Now you can use `:Q` to have the same effect as `:q`, without any risk of overriding any function name/other mapping. You can then define other command depending on your usag...
7,874
<p>I have a file (around 1.6 million lines) which formatted like this: </p> <pre><code>-0.00697468 0 -1.95966e-49 101325 -3.06381 -0.00697468 0 -1.95966e-49 101325 -3.06381 -0.00697468 0 -1.95966e-49 101325 -3.06381 . . . </code></pre> <p>After some thousand lines, the format will be changed (no minus sign o...
[ { "answer_id": 7875, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 3, "selected": false, "text": "<p>If you wanted to delete entire line starting with a space, This pattern will be useful.</p>\n\n<pre><code>:g/^\\s.*/d\...
2016/05/20
[ "https://vi.stackexchange.com/questions/7874", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7575/" ]
I have a file (around 1.6 million lines) which formatted like this: ``` -0.00697468 0 -1.95966e-49 101325 -3.06381 -0.00697468 0 -1.95966e-49 101325 -3.06381 -0.00697468 0 -1.95966e-49 101325 -3.06381 . . . ``` After some thousand lines, the format will be changed (no minus sign on the first character), lik...
The two commands below will reduce every line to the first sequence of non-whitespace character followed by a space: ``` from 0.453945 -2.14126e-54 3.40152e-49 101325 214.355 to 0.453945 <-- space ``` But your question is a little confusing so I'm not sure I understood what you want. With a substitution: ``` :%s/...
7,877
<p>I have created the following mapping:</p> <pre><code>:map &lt;F8&gt; 3w </code></pre> <p>When I pressed <code>2&lt;F8&gt;</code>, I thought it would move six words (<code>2*3w</code>), but it moves 23 words. (This has been mentioned in help section of vim editor)</p> <p>How to map it to work for 6 moves instead o...
[ { "answer_id": 7878, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": false, "text": "<p>You can use the expression register for this:</p>\n\n<pre><code> :nnoremap &lt;F8&gt; @='3w'&lt;CR&gt;\n</code></pre>\n\n...
2016/05/20
[ "https://vi.stackexchange.com/questions/7877", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7161/" ]
I have created the following mapping: ``` :map <F8> 3w ``` When I pressed `2<F8>`, I thought it would move six words (`2*3w`), but it moves 23 words. (This has been mentioned in help section of vim editor) How to map it to work for 6 moves instead of 23? Also, please let me know if this feature is intentionally mad...
Another solution is to use the variable `v:count` like this: ``` nnoremap <F8> :<C-u>execute "normal! " . v:count1 * 3 . "w"<CR> ``` See [`:h v:count`](http://vimdoc.sourceforge.net/htmldoc/eval.html#v:count): The variable contains the count given for the last normal mode command and can thus be used to get a count ...
7,879
<p>I want to ask how to delete repeated lines in vim. For now, I have a file which contained 12740 lines. There are only 98 unique lines, and each line is duplicated 129 times.</p> <p>I have tried:</p> <pre><code>g/^\(.*\)$\n\1$/d </code></pre> <p>But my problem is, some unique lines are the same to each other, I do...
[ { "answer_id": 7881, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 2, "selected": false, "text": "<p>Let's get the exact number of unique lines first.</p>\n\n<pre><code> :sort u | echo line('$')\n</code></pre>\n\n<p>Thi...
2016/05/20
[ "https://vi.stackexchange.com/questions/7879", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7575/" ]
I want to ask how to delete repeated lines in vim. For now, I have a file which contained 12740 lines. There are only 98 unique lines, and each line is duplicated 129 times. I have tried: ``` g/^\(.*\)$\n\1$/d ``` But my problem is, some unique lines are the same to each other, I don't know which lines are those. ...
To delete *n* lines starting from every line, you can do: ``` :%norm ndd ``` For example, if I started with the numbers 1 to 10 repeated 5 times: ``` 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 10 10 10 10 10 ``` And I do: ``` :%norm 4dd ``` I get: ``` 1 2 3 4 5 6...
7,889
<p>I cannot exit vim even when I type <code>:q!</code>. I get the error </p> <pre><code>E37: No write since last change (add ! to override) E162: No write since last change for buffer... </code></pre> <p>I think the buffer is a NetrwTreeListing readonly.</p>
[ { "answer_id": 7891, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 3, "selected": false, "text": "<p>Try</p>\n\n<pre><code>:bdelete!\n</code></pre>\n\n<p>or </p>\n\n<pre><code>:bd!\n</code></pre>\n\n<p>for short. This ...
2016/05/20
[ "https://vi.stackexchange.com/questions/7889", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6952/" ]
I cannot exit vim even when I type `:q!`. I get the error ``` E37: No write since last change (add ! to override) E162: No write since last change for buffer... ``` I think the buffer is a NetrwTreeListing readonly.
To solve this nuisance with netrw permanently, I added this to my `.vimrc`: ``` " Per default, netrw leaves unmodified buffers open. This autocommand " deletes netrw's buffer once it's hidden (using ':q', for example) autocmd FileType netrw setl bufhidden=delete ``` From [Tim Pope](https://github.com/tpope/vim-vineg...
7,898
<p>Neovim has a very handy terminal emulator.</p> <p>In normal mode, I can use all the read-only vim commands on the output, like scrolling or going to the file under the cursor.</p> <p>But more often than not, I want to delete some lines. Is it possible?</p>
[ { "answer_id": 7912, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": true, "text": "<p>You can use this mapping to copy the content of the terminal buffer into a new buffer:</p>\n\n<pre><code>tnoremap &lt;C-U&g...
2016/05/20
[ "https://vi.stackexchange.com/questions/7898", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7318/" ]
Neovim has a very handy terminal emulator. In normal mode, I can use all the read-only vim commands on the output, like scrolling or going to the file under the cursor. But more often than not, I want to delete some lines. Is it possible?
You can use this mapping to copy the content of the terminal buffer into a new buffer: ``` tnoremap <C-U> <C-\><C-N>:%y \| vertical new \| normal! P<CR> ``` `<C-\><C-N>` goes back to normal mode so you can use any normal mode command you want. `:%y` copy the content of the buffer. `vertical new` create a new verti...
7,902
<p>I'm writing a debugger and when hitting a breakpoint or stepping through code I'm making a system call that instructs a gVim server to jump to the current line of the file being debugged, like this:</p> <pre><code>system_call("gvim --remote-send +\"%dG" --servername DEBUG --remote-tab-silent %s", line_...
[ { "answer_id": 22958, "author": "Trevor", "author_id": 16602, "author_profile": "https://vi.stackexchange.com/users/16602", "pm_score": 0, "selected": false, "text": "<p>If you are using Linux, here is a bit of a hacky solution. You can augment your <code>gvim</code> command with a shell...
2016/05/21
[ "https://vi.stackexchange.com/questions/7902", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7701/" ]
I'm writing a debugger and when hitting a breakpoint or stepping through code I'm making a system call that instructs a gVim server to jump to the current line of the file being debugged, like this: ``` system_call("gvim --remote-send +\"%dG" --servername DEBUG --remote-tab-silent %s", line_number, file_n...
A solution to this problem is mentioned in Vim's documentation (`:h --remote`). The following command should open *filename* to *line\_number*: ```bash gvim --servername DEBUG --remote-send "<C-\><C-N>:tab drop *filename*<CR>*line\_number*G" ``` Note that this seems to neither raise nor focus Vim. And I believe that ...
7,914
<p>I want to remove repeated spaces, but not if they occur at the start of a line (indendation).</p> <p>Before:</p> <pre><code>line 1 hi there i have spaces </code></pre> <p>After:</p> <pre><code>line 1 hi there i have spaces </code></pre> <p>I've gotten as far as <code>s/^\s\+/ /g</code>, but th...
[ { "answer_id": 7915, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 5, "selected": true, "text": "<p>You don't need to match the start of the line. Instead, match any non-whitespace character. This should work:</p>\n...
2016/05/23
[ "https://vi.stackexchange.com/questions/7914", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7702/" ]
I want to remove repeated spaces, but not if they occur at the start of a line (indendation). Before: ``` line 1 hi there i have spaces ``` After: ``` line 1 hi there i have spaces ``` I've gotten as far as `s/^\s\+/ /g`, but that deletes only duplicate spaces that *are* at the start of the lin...
You don't need to match the start of the line. Instead, match any non-whitespace character. This should work: ``` s/\S\zs\s\{2,}/ /g ``` Explanation: * `\S\zs` match any non-whitespace character and set start of pattern match after the character * `\s\{2,}` match at two or more spaces
7,924
<p>In <a href="https://stackoverflow.com/questions/9869057/vim-linenr-and-cursorline-colour-configuration-change">this Q&amp;A</a>, it's observed that there is a highlight group for <code>CursorLineNr</code>, which applies to the line number for the cursor line when <code>set cursorline</code> is on.</p> <p>I notice t...
[ { "answer_id": 7926, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>I've been struggling with that behavior for a <em>long</em> time.</p>\n\n<p>Basically, the foreground color of <code>SpecialK...
2016/05/24
[ "https://vi.stackexchange.com/questions/7924", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4913/" ]
In [this Q&A](https://stackoverflow.com/questions/9869057/vim-linenr-and-cursorline-colour-configuration-change), it's observed that there is a highlight group for `CursorLineNr`, which applies to the line number for the cursor line when `set cursorline` is on. I notice that using cursorline also changes the color for...
I've been struggling with that behavior for a *long* time. Basically, the foreground color of `SpecialKey` on the current line is changed to the foreground color of `Normal` if: * the `cursorline` option is enabled, * the `CursorLine` highlight group has a background color set. I've never been able to fix that behav...
7,925
<p>I work on a rather large C++ project. One of the more frustrating aspects of its organization is very large functions placed inside ridiculously large files.</p> <p>I often want to search for any instance of a particular global variable or function call, restricted to the current function. Is there a reasonably sim...
[ { "answer_id": 7927, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 3, "selected": false, "text": "<p>Here's how I would do it. Add this to your <code>.vimrc</code></p>\n\n<pre><code>vnoremap if [[O][\n</code></pre>\n\n...
2016/05/24
[ "https://vi.stackexchange.com/questions/7925", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6659/" ]
I work on a rather large C++ project. One of the more frustrating aspects of its organization is very large functions placed inside ridiculously large files. I often want to search for any instance of a particular global variable or function call, restricted to the current function. Is there a reasonably simple formul...
Here's how I would do it. Add this to your `.vimrc` ``` vnoremap if [[O][ ``` Explanation: vnoremap means map the left hand side `if` to the right hand side `[[mO][` while you're in visual mode. `if` means *In Function*, although you can rename this if you like. `[[` jumps to the beginning of the function. `O` moves...
7,936
<p>in normal mode <kbd>Ctrl</kbd>+<kbd>e</kbd> scrolls the buffer itself. from <code>:h CTRL-E</code></p> <blockquote> <p>CTRL-E ...........................................* Scroll window *<br> [count] lines downwards in the buffer.</p> </blockquote> <p>I would like to remap that so when I press <kbd>Ctrl</kbd>+<...
[ { "answer_id": 7937, "author": "the_velour_fog", "author_id": 4603, "author_profile": "https://vi.stackexchange.com/users/4603", "pm_score": 1, "selected": false, "text": "<p>in the end this worked</p>\n\n<ul>\n<li>hit <code>:nnoremap</code>\n\n<ul>\n<li>enter command line mode</li>\n</u...
2016/05/25
[ "https://vi.stackexchange.com/questions/7936", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
in normal mode `Ctrl`+`e` scrolls the buffer itself. from `:h CTRL-E` > > CTRL-E ...........................................\* Scroll window \* > > [count] lines downwards in the buffer. > > > I would like to remap that so when I press `Ctrl`+`e` vim performs 3 x `Ctrl`+`e`. I've tried * `map <Ctrl-e> 3<C...
The reason why ``` :nnoreamp ^E 3^E ``` Doesn't work is because `^E` is *two* separate characters. You can tell because you have to hit the arrow keys twice to move backwards past it. So you are really remapping `^` `E` to `3` `^` `E`, which is probably not what you want to do, especially since `^` doesn't take a n...
7,939
<p>Converting odt to markdown produces <code>\</code> around special characters. So I need to change <code>\\</code> to <code>\</code> and remove if <code>\</code> is standalone.</p> <p>Sample text:</p> <pre><code>* \[\] match any of the character specified within \[\], use \[^\] to invert the selection * \\W opposit...
[ { "answer_id": 7941, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 4, "selected": true, "text": "<p>This should work:</p>\n\n<pre><code>:%s/\\\\\\?\\zs\\\\//g\n</code></pre>\n\n<p>Here the first <code>\\\\\\?\\zs</c...
2016/05/25
[ "https://vi.stackexchange.com/questions/7939", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1616/" ]
Converting odt to markdown produces `\` around special characters. So I need to change `\\` to `\` and remove if `\` is standalone. Sample text: ``` * \[\] match any of the character specified within \[\], use \[^\] to invert the selection * \\W opposite of \\w i.e short cut for \[^a-zA-Z0-9\_\] * \\w match alphabets...
This should work: ``` :%s/\\\?\zs\\//g ``` Here the first `\\\?\zs` is used to ignore the first `\` if there are two of them. See `:h \?` and `:h \zs` for more information.
7,944
<p>I regularly find myself in the situation that I am reading a help topic and see an identifier (the blue underlined words) that I want to follow with <code>&lt;C-]&gt;</code>. However, most of the time the identifier is not (yet) under my cursor.</p> <p>Instead of searching for the identifier with <code>/part_of_ide...
[ { "answer_id": 7945, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 4, "selected": true, "text": "<p>In the help files the identifiers are actually marked as <code>|identifier|</code> (but you don't see the <code>|</code> b...
2016/05/25
[ "https://vi.stackexchange.com/questions/7944", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3282/" ]
I regularly find myself in the situation that I am reading a help topic and see an identifier (the blue underlined words) that I want to follow with `<C-]>`. However, most of the time the identifier is not (yet) under my cursor. Instead of searching for the identifier with `/part_of_identifier<CR>` I would like to use...
In the help files the identifiers are actually marked as `|identifier|` (but you don't see the `|` because of the syntax file, use `set ft=txt` in an help buffer to check what I'm talking about). You could then create a mapping which would look for the next pattern `\|\W*\|` and you should be good. Something like: `...
7,948
<p>When I have to type a lot of text I often tend to keep my finger pressed on <kbd>shift</kbd> when I write the first letter of a sentence which often give:</p> <pre><code>[...]end of sentence. NEw sentence[...] </code></pre> <p>Here the <code>E</code> of <code>NEw</code> should be lower case. I am then trying to cr...
[ { "answer_id": 7949, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": false, "text": "<p>Here's a little something a cooked up really fast. It's less robust I think, but it's also much lighter. Maybe you cou...
2016/05/25
[ "https://vi.stackexchange.com/questions/7948", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
When I have to type a lot of text I often tend to keep my finger pressed on `shift` when I write the first letter of a sentence which often give: ``` [...]end of sentence. NEw sentence[...] ``` Here the `E` of `NEw` should be lower case. I am then trying to create a function which would detect if the second letter o...
Here's a little something a cooked up really fast. It's less robust I think, but it's also much lighter. Maybe you could incorporate it into yours to make it faster? I'll probably revise this a bit when I have time. ``` inoremap <Space> <C-o>:call CheckCase()<CR><Space> function! CheckCase() normal! may2b let l...
8,011
<p>I was told when add a line like <code># vim: filetype=r</code> in a file, vim can recognizes the file type. It seems that for some files like <code>*.cpp</code>,<code>*.java</code>, vim can recognize the file while for files like <code>*.CPP</code>, <code>*.JAVA</code>, it needs the first line information.</p> <p>I...
[ { "answer_id": 8013, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 5, "selected": true, "text": "<p>The reason Vim detects the filetype for <code>*.cpp</code> and not for <code>*.CPP</code> files is that Vim has auto-commands ...
2016/05/28
[ "https://vi.stackexchange.com/questions/8011", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1080/" ]
I was told when add a line like `# vim: filetype=r` in a file, vim can recognizes the file type. It seems that for some files like `*.cpp`,`*.java`, vim can recognize the file while for files like `*.CPP`, `*.JAVA`, it needs the first line information. I have two questions. The first is that what should I type in the ...
The reason Vim detects the filetype for `*.cpp` and not for `*.CPP` files is that Vim has auto-commands for `*.cpp` setting the filetype, but nothing for `*.CPP`: ```vim :au BufRead *.cpp --- Auto-Commands --- filetypedetect BufRead *.cpp if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif :au...
8,020
<p>My colour scheme (morning) doesn't play nice with the quickfix window: I cannot read the selected item's location, because the foreground and background colours are the same. Because of this I want to redefine some highlighting styles, e.g. for <code>Search</code> and <code>LineNr</code>. However, I only want to do ...
[ { "answer_id": 8022, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 0, "selected": false, "text": "<p>You can use auto commands and put them in <code>~/.vimrc</code>.</p>\n\n<pre><code>au QuickFixCmdPre * hi Search cterm...
2016/05/30
[ "https://vi.stackexchange.com/questions/8020", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
My colour scheme (morning) doesn't play nice with the quickfix window: I cannot read the selected item's location, because the foreground and background colours are the same. Because of this I want to redefine some highlighting styles, e.g. for `Search` and `LineNr`. However, I only want to do this in the quickfix wind...
I'm afraid the solution you suggest isn't possible. Vim's highlighting and colorscheme commands are global: any colours you set are set *everywhere*. The best you could do is to change the colours everywhere when the quickfix window opens and then change them back when it closes, (or perhaps change them when entering ...
8,029
<h2>Problem</h2> <p>I am trying to implement "trimming trailing whitespace in changed lines only". For this purpose, I intercept <code>TextChanged</code> and <code>TextChangedI</code> autocmd events and record the current line (<code>line(.)</code>) in the handler. The changed lines are then trimmed in a <code>BufWrit...
[ { "answer_id": 8031, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 4, "selected": true, "text": "<p>Is your concern about performance? Calling out to Python code will add unneeded overhead that would make an attempt at p...
2016/05/31
[ "https://vi.stackexchange.com/questions/8029", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7826/" ]
Problem ------- I am trying to implement "trimming trailing whitespace in changed lines only". For this purpose, I intercept `TextChanged` and `TextChangedI` autocmd events and record the current line (`line(.)`) in the handler. The changed lines are then trimmed in a `BufWritePre` autocmd event handler. It works OK,...
Is your concern about performance? Calling out to Python code will add unneeded overhead that would make an attempt at performance optimization moot. In any case, you can get the boundaries with `getpos()` using the marks `'[` and `']` ``` let start = getpos("'[")[1:2] let end = getpos("']")[1:2] ``` However, I thin...
8,034
<p>I found a vim tip a while back recommending swapping visual and visual block mode (<a href="http://howivim.com/2016/damian-conway/" rel="nofollow">http://howivim.com/2016/damian-conway/</a>)</p> <p>For the most part this is really useful. I frequently find myself wanting to only capture a part of a block containing...
[ { "answer_id": 8038, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 2, "selected": false, "text": "<p>Well, this isn't the perfect solution, since it requires using an extra register, but it works. Try this:</p>\n\n<pre...
2016/05/31
[ "https://vi.stackexchange.com/questions/8034", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6420/" ]
I found a vim tip a while back recommending swapping visual and visual block mode (<http://howivim.com/2016/damian-conway/>) For the most part this is really useful. I frequently find myself wanting to only capture a part of a block containing similar text or to delete or insert a bunch of text at the beginning of the...
Maybe this? ``` xnoremap Y :yank<cr> ``` Being an ex command, `:yank` will automatically copy whole lines.
8,036
<p>The following will replace the first comma on each line with a pipe:</p> <pre><code>:%s/,/|/ </code></pre> <p>How can I do the same for the last comma?</p>
[ { "answer_id": 8037, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 3, "selected": false, "text": "<p>The best way to do this is to allow any character except for a newline, <code>.</code> any number of times, <code>*</...
2016/05/31
[ "https://vi.stackexchange.com/questions/8036", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7832/" ]
The following will replace the first comma on each line with a pipe: ``` :%s/,/|/ ``` How can I do the same for the last comma?
The best way to do this is to allow any character except for a newline, `.` any number of times, `*` followed by a comma `,`. This gives us the following regex: ``` :%s/\(.*\),/\1| ``` Or, the more readable way: ``` :%s/\v(.*),/\1| ``` This works because `*` is [*"greedy"*](http://vimregex.com/#Non-Greedy) by def...
8,045
<p>I need to create a list containing a predefined number of zeros.</p> <p>I know that I can create an empty one with <code>let foo = []</code> but I would need to initialize it with a number of zeros contained in a variable.</p> <p><a href="http://vimdoc.sourceforge.net/htmldoc/eval.html#List" rel="noreferrer"><code...
[ { "answer_id": 8047, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>You can combine the <code>map</code> and <code>range</code> function for that:</p>\n\n<pre><code>:echo map(range(4), 0)\n[0...
2016/06/01
[ "https://vi.stackexchange.com/questions/8045", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
I need to create a list containing a predefined number of zeros. I know that I can create an empty one with `let foo = []` but I would need to initialize it with a number of zeros contained in a variable. [`:h List`](http://vimdoc.sourceforge.net/htmldoc/eval.html#List) doesn't seem to mention this use case, what's t...
You can combine the `map` and `range` function for that: ``` :echo map(range(4), 0) [0, 0, 0, 0] ``` `range(4)` returns a list of number defined by the arguments: ``` [0, 1, 2, 3] ``` `map([0, 1, 2, 3], 0)` replace every element in the array with `0` You can use the following function: ``` function! Fill(len, c...
8,059
<p>This is something that has bugged me for a long time, but I've never gotten around to asking about. Say the text in your buffer looks like this:</p> <pre><code>Hello World </code></pre> <p>If I put my cursor somewhere in line 2, and do <kbd>yk</kbd>, my cursor will end on line 1. This seems to imply an operator pl...
[ { "answer_id": 8061, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 5, "selected": true, "text": "<p>From <code>:h operator</code></p>\n<blockquote>\n<p>After applying the operator the cursor is mostly left at the start of...
2016/06/02
[ "https://vi.stackexchange.com/questions/8059", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
This is something that has bugged me for a long time, but I've never gotten around to asking about. Say the text in your buffer looks like this: ``` Hello World ``` If I put my cursor somewhere in line 2, and do `yk`, my cursor will end on line 1. This seems to imply an operator plus a motion also moves the cursor. ...
From `:h operator` > > After applying the operator the cursor is mostly left at the start of the text > that was operated upon. For example, "yfe" doesn't move the cursor, but "yFe" > moves the cursor leftwards to the "e" where the yank started. > > > What's happening is that the cursor is being moved to the *beg...