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
10,744
<p>I am writing python 3 code from within vim.</p> <p>There is a function within my file like this:</p> <pre><code>def seconds_to_text(seconds): return str(datetime.timedelta(seconds=seconds)) </code></pre> <p>Is there a way for me to see what it outputs for certain input values from within vim?</p> <p>How can ...
[ { "answer_id": 10746, "author": "user41805", "author_id": 10378, "author_profile": "https://vi.stackexchange.com/users/10378", "pm_score": 0, "selected": false, "text": "<p>I'm not sure if this is the intended solution, because you technically don't leave vim, ie you are still in the vim...
2016/12/25
[ "https://vi.stackexchange.com/questions/10744", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
I am writing python 3 code from within vim. There is a function within my file like this: ``` def seconds_to_text(seconds): return str(datetime.timedelta(seconds=seconds)) ``` Is there a way for me to see what it outputs for certain input values from within vim? How can I see what `seconds_to_text(30)` would o...
Not really a "Vim answer", but writing a unit test and running the unit test(s) for the current file is probably the best way to do this. Specifically for Python you can use [doctests](https://docs.python.org/3/library/doctest.html): ``` import datetime def seconds_to_text(seconds): """Convert number of seconds ...
10,755
<p>When I scroll a whole page up by <code>ctrl-f</code>, and down by <code>ctrl-b</code>, vim reserves 2 lines, and repeats them both in the previous GUI window and the present one. But I expect it not to repeat lines, because now that the "turning" of pages is not a really "turning" but with a small shift, this makes...
[ { "answer_id": 10759, "author": "Violapterin", "author_id": 10241, "author_profile": "https://vi.stackexchange.com/users/10241", "pm_score": 3, "selected": true, "text": "<p>It dawned on me that why do I not move page down and further scroll two lines, and same can be said on page up.</p...
2016/12/26
[ "https://vi.stackexchange.com/questions/10755", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10241/" ]
When I scroll a whole page up by `ctrl-f`, and down by `ctrl-b`, vim reserves 2 lines, and repeats them both in the previous GUI window and the present one. But I expect it not to repeat lines, because now that the "turning" of pages is not a really "turning" but with a small shift, this makes me harder to visualize t...
It dawned on me that why do I not move page down and further scroll two lines, and same can be said on page up. ``` " Scroll a page with no repeated lines, " while default shows two lines in both present and next window nnoremap <C-f> <C-f><C-e><C-e> nnoremap <C-b> <C-b><C-y><C-y> ``` I am finding myself on the righ...
10,761
<p>I frequently want to temporarily maximize a buffer in a tab page and then go back to the old buffer configuration that I was looking at. My current workflow for doing something like this is either to close all the other buffers using <code>&lt;c-w&gt;o</code> or to move the buffer I am currently looking at to its ow...
[ { "answer_id": 10762, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 5, "selected": true, "text": "<p>I'm not sure but you could try <code>:tab split</code> (or the shorter version <code>:tab sp</code>).</p>\n\n<p>The ...
2016/12/26
[ "https://vi.stackexchange.com/questions/10761", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6420/" ]
I frequently want to temporarily maximize a buffer in a tab page and then go back to the old buffer configuration that I was looking at. My current workflow for doing something like this is either to close all the other buffers using `<c-w>o` or to move the buffer I am currently looking at to its own tab `<c-w>T`. The ...
I'm not sure but you could try `:tab split` (or the shorter version `:tab sp`). The `:split` command should duplicate the viewport displaying `a.txt`, while the `:tab` modifier should move this viewport into a dedicated tab page. --- If you want to change the behavior of `C-w T`, you could remap it like this: ``` n...
10,775
<p>I want to have the very first search result centered on the screen. I know about <code>:nnoremap n nzz</code> mapping, but it only works for centering <em>next</em> matches, not the first.</p> <p>I thought that maybe I could use some AutoCmd, but I haven't found an appropriate event.</p>
[ { "answer_id": 10776, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 5, "selected": true, "text": "<p>You can use the following mapping:</p>\n\n<pre><code>cnoremap &lt;expr&gt; &lt;CR&gt; getcmdtype() == '/' ? '&lt;CR&gt;zz...
2016/12/28
[ "https://vi.stackexchange.com/questions/10775", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/836/" ]
I want to have the very first search result centered on the screen. I know about `:nnoremap n nzz` mapping, but it only works for centering *next* matches, not the first. I thought that maybe I could use some AutoCmd, but I haven't found an appropriate event.
You can use the following mapping: ``` cnoremap <expr> <CR> getcmdtype() == '/' ? '<CR>zz' : '<CR>' ``` Which can be explained like this: * `cnoremap` Create a mapping in the command line mode * `<expr>` The mapping will evaluate an expression (allowing to use conditions) * `<CR>` The key to remap (`Enter`) * `getc...
10,779
<p>I use vim to edit a lot of latex files using vim 7.4. Some trick of the syntax indenting annoys me and interferes with my intentions. Particularly, the automatic indentation during the addition of a line. I tried to remove this by </p> <pre><code>:set noautoindent </code></pre> <p>but it produces no effect. Which ...
[ { "answer_id": 10780, "author": "Víctor Luaña", "author_id": 7868, "author_profile": "https://vi.stackexchange.com/users/7868", "pm_score": 2, "selected": false, "text": "<p>After examining similar questions, I've found the solution is to <code>:set nosmartindent</code>.</p>\n" }, { ...
2016/12/28
[ "https://vi.stackexchange.com/questions/10779", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7868/" ]
I use vim to edit a lot of latex files using vim 7.4. Some trick of the syntax indenting annoys me and interferes with my intentions. Particularly, the automatic indentation during the addition of a line. I tried to remove this by ``` :set noautoindent ``` but it produces no effect. Which of the many options is wor...
After examining similar questions, I've found the solution is to `:set nosmartindent`.
10,814
<p>I use a <code>autocmd</code> to display current tag via <code>Tabgar</code> plugin like this:</p> <pre><code>autocmd CursorHold * call TagbarCurrentTag </code></pre> <p>However, after I open <code>CtrlP</code> with <code>:CtrlP</code> for a while, the <code>Tagbar</code>'s output <code>No current tag</code> will o...
[ { "answer_id": 16375, "author": "Luke Davis", "author_id": 8084, "author_profile": "https://vi.stackexchange.com/users/8084", "pm_score": 0, "selected": false, "text": "<p>I figured out how to solve this problem, more or less. I had a similar issue with some <code>CursorMoved</code> auto...
2017/01/02
[ "https://vi.stackexchange.com/questions/10814", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4754/" ]
I use a `autocmd` to display current tag via `Tabgar` plugin like this: ``` autocmd CursorHold * call TagbarCurrentTag ``` However, after I open `CtrlP` with `:CtrlP` for a while, the `Tagbar`'s output `No current tag` will overwrite the input area of `CtrlP`. So I need to identify if I am in a `CtrlP` buffer to av...
The CtrlP buffer has the name `ControlP`, so you should just be able to check this: ``` autocmd CursorHold * if bufname("%") != 'ControlP' | call TagbarCurrentTag() | endif ```
10,817
<p>Ubuntu's packages can be pretty old, but for some desktop programs (like Vim) I'd much rather have the latest version, as newer versions often fix various bugs.</p> <p>How can I get a reasonably recent Vim version on Ubuntu?</p>
[ { "answer_id": 10827, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 7, "selected": true, "text": "<p>You have three different options:</p>\n\n<ul>\n<li>Wait for the newest versions to be added to the distribution packages....
2017/01/02
[ "https://vi.stackexchange.com/questions/10817", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/51/" ]
Ubuntu's packages can be pretty old, but for some desktop programs (like Vim) I'd much rather have the latest version, as newer versions often fix various bugs. How can I get a reasonably recent Vim version on Ubuntu?
You have three different options: * Wait for the newest versions to be added to the distribution packages. Note that you might want to learn a new language or build a ship with your bare hands while you wait. If waiting several years is not good for you then you have the following two options: * Use a PPA containing...
10,824
<p>I don't understand the <code>findfile()</code> function in Vim-Script, what am i doing wrong?</p> <pre><code>set encoding = utf-8 cd %:p:h let b:gitiginorfiles = findfile('.gitignore', system('git rev-parse --show-toplevel'), -1) </code></pre> <p>My variable <code>b:gitignorefiles</code> is always empty.</p>
[ { "answer_id": 10825, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>Vim documentation is the best point to start. <a href=\"http://vimhelp.appspot.com/eval.txt.html#findfile%28%29\" rel=\"...
2017/01/03
[ "https://vi.stackexchange.com/questions/10824", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9527/" ]
I don't understand the `findfile()` function in Vim-Script, what am i doing wrong? ``` set encoding = utf-8 cd %:p:h let b:gitiginorfiles = findfile('.gitignore', system('git rev-parse --show-toplevel'), -1) ``` My variable `b:gitignorefiles` is always empty.
I need to chomp the trailing newline to see the line work: ``` :echo findfile('.gitignore', system('git rev-parse --show-toplevel')[:-2], -1) ``` This is a recurring problem with `system()`. I did rapidly end-up with a first version of `system()` in my library plugin that always chomps these unwanted characters. ED...
10,834
<p>I'm thinking about exchanging some keys while in non insert-mode so that the bindings that I use most are easier to reach (i.e. on the home row).</p> <p>How can I swap two keys without breaking the behaviors of my plugins' bindings ?</p> <p>For instance, <a href="https://github.com/tpope/vim-surround" rel="nofollo...
[ { "answer_id": 10829, "author": "marderh", "author_id": 10693, "author_profile": "https://vi.stackexchange.com/users/10693", "pm_score": 4, "selected": false, "text": "<p>A shortcut for next empty line is <kbd>}</kbd>.\nSo you just might want to use <kbd>SHIFT</kbd>+<kbd>v</kbd><kbd>}</k...
2017/01/03
[ "https://vi.stackexchange.com/questions/10834", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10700/" ]
I'm thinking about exchanging some keys while in non insert-mode so that the bindings that I use most are easier to reach (i.e. on the home row). How can I swap two keys without breaking the behaviors of my plugins' bindings ? For instance, [Tim Pope's surround plugin](https://github.com/tpope/vim-surround) uses the ...
Vim understands the concept of a "paragraph". Vim's definition of a paragraph is a block of text surrounded by blank lines\*. There are several motions and text objects to work with this. * `[count]}` – Move `[count]` paragraphs forward. You can use `<S-v>}` to select all lines from the current line to the next blank ...
10,845
<p>I have </p> <pre><code>"012-0738-32"],[ "4", "Beacon </code></pre> <p>I want</p> <pre><code>"012-0738-32" "4", "Beacon </code></pre> <p><code>],[</code>+ <code>space</code> replaced with <code>\r</code></p>
[ { "answer_id": 10846, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 3, "selected": false, "text": "<p>You need to escape the opening square bracket: <code>:s/],\\[ /\\r</code></p>\n" }, { "answer_id": 10847, ...
2017/01/04
[ "https://vi.stackexchange.com/questions/10845", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9498/" ]
I have ``` "012-0738-32"],[ "4", "Beacon ``` I want ``` "012-0738-32" "4", "Beacon ``` `],[`+ `space` replaced with `\r`
You need to escape the opening square bracket: `:s/],\[ /\r`
10,851
<p>In my <a href="https://vi.stackexchange.com/questions/10837/concatination-of-arguments-in-vimscript-when-reading-the-output-of-a-command-to">previous question</a>, I passed an argument into a Vimscript function and concatenated it into the command line. This works great, but when you pass a string that contains the...
[ { "answer_id": 10852, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": true, "text": "<p>The problem is that some characters are considered special by the Vim commandline. In your case, <code>#</code> refe...
2017/01/04
[ "https://vi.stackexchange.com/questions/10851", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
In my [previous question](https://vi.stackexchange.com/questions/10837/concatination-of-arguments-in-vimscript-when-reading-the-output-of-a-command-to), I passed an argument into a Vimscript function and concatenated it into the command line. This works great, but when you pass a string that contains the `#` character,...
The problem is that some characters are considered special by the Vim commandline. In your case, `#` refers to the alternate file name. You can find the documentation with a full list at [`:help cmdline-special`](http://vimhelp.appspot.com/cmdline.txt.html#cmdline%2dspecial). This also includes the two possible ways t...
10,855
<p>I think there is a distinct possibility this question has already been asked, but I can't find it.</p> <p>If I am doing something like <code>:s/foo/bar/g</code> and then I want to call that again on the next line but with <code>baz</code> instead of <code>bar</code>, is there a faster way to do that? I feel like <c...
[ { "answer_id": 10856, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 5, "selected": true, "text": "<p>Not exactly what you ask for, but you can do that:</p>\n\n<pre><code>:s/foo/bar/g\n</code></pre>\n\n<p>And then:</p>\n\n<p...
2017/01/04
[ "https://vi.stackexchange.com/questions/10855", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9841/" ]
I think there is a distinct possibility this question has already been asked, but I can't find it. If I am doing something like `:s/foo/bar/g` and then I want to call that again on the next line but with `baz` instead of `bar`, is there a faster way to do that? I feel like `&baz` should work, but it does not.
Not exactly what you ask for, but you can do that: ``` :s/foo/bar/g ``` And then: ``` :s//baz/g ``` You can use that because when you use `:s` the searched pattern is saved in the search register. Which you can see with `:reg /`. --- Work in progress: You can speed up your workflow with: ``` nnoremap && :s<UP>...
10,857
<p>Given the document</p> <pre><code>a ^ a </code></pre> <p>(where <code>^</code> denotes the cursor position), the forward search <code>/a\?</code> succeeds, but the backward search <code>?a\?</code> fails. Why?</p>
[ { "answer_id": 10858, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": true, "text": "<p>This is documented:</p>\n\n<pre><code>\\? Just like \\=. Cannot be used when searching backwards with the \"?\"\n ...
2017/01/04
[ "https://vi.stackexchange.com/questions/10857", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2108/" ]
Given the document ``` a ^ a ``` (where `^` denotes the cursor position), the forward search `/a\?` succeeds, but the backward search `?a\?` fails. Why?
This is documented: ``` \? Just like \=. Cannot be used when searching backwards with the "?" command. {not in Vi} ``` Note that `\?` is "Just like \=", so you can ``` ?a\= ``` instead.
10,860
<p>I have a log file full of arbitrary lines, interspersed with some lines which are a proper xml sequence, with all the tags on a single line (for each sequence). I want to simply process this so that all the xml lines become broken out in easy to read format. There is a utility in linux called xmllint that looks us...
[ { "answer_id": 10867, "author": "Starman", "author_id": 10155, "author_profile": "https://vi.stackexchange.com/users/10155", "pm_score": 0, "selected": false, "text": "<p>I have something that works in O(1) time, but I don't think it's the best solution, and it especially bothers me that...
2017/01/05
[ "https://vi.stackexchange.com/questions/10860", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10155/" ]
I have a log file full of arbitrary lines, interspersed with some lines which are a proper xml sequence, with all the tags on a single line (for each sequence). I want to simply process this so that all the xml lines become broken out in easy to read format. There is a utility in linux called xmllint that looks useful ...
I do not have xmllint or your file handy, but the following works for me. My VIM buffer is filled with ``` foo bar test foo bar test ``` I then run the command `:g/foo/.! cat -n` which produces ``` 1 foo bar test 1 foo bar test ``` as expected.
10,863
<p>I would like to modify the behavior of one of my mapping but only when Vim is reading data which were piped to it by <code>$ vipe</code>.</p> <p>The mapping closes/quits the current window/session depending on certain conditions. When Vim is reading data which were piped to it, I would like the mapping to execute <...
[ { "answer_id": 10867, "author": "Starman", "author_id": 10155, "author_profile": "https://vi.stackexchange.com/users/10155", "pm_score": 0, "selected": false, "text": "<p>I have something that works in O(1) time, but I don't think it's the best solution, and it especially bothers me that...
2017/01/05
[ "https://vi.stackexchange.com/questions/10863", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6960/" ]
I would like to modify the behavior of one of my mapping but only when Vim is reading data which were piped to it by `$ vipe`. The mapping closes/quits the current window/session depending on certain conditions. When Vim is reading data which were piped to it, I would like the mapping to execute `:cquit`, so that it r...
I do not have xmllint or your file handy, but the following works for me. My VIM buffer is filled with ``` foo bar test foo bar test ``` I then run the command `:g/foo/.! cat -n` which produces ``` 1 foo bar test 1 foo bar test ``` as expected.
10,869
<p>I'm using the latest vim/gvim (8.0.118), but have noticed this problem in the past, with other versions. </p> <p>I created a file named <code>fizzbuzz.java</code> (outside of gvim), and opened it in a new tab in gvim on my Windows 7 PC at work, using the context menu of my file manager. After closing the tab, using...
[ { "answer_id": 15689, "author": "TankorSmash", "author_id": 488, "author_profile": "https://vi.stackexchange.com/users/488", "pm_score": 0, "selected": false, "text": "<p>Close vim completely, and reopen the file manually (ie <code>:edit FileName.ext</code> instead of <code>:MRU</code>),...
2017/01/06
[ "https://vi.stackexchange.com/questions/10869", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5298/" ]
I'm using the latest vim/gvim (8.0.118), but have noticed this problem in the past, with other versions. I created a file named `fizzbuzz.java` (outside of gvim), and opened it in a new tab in gvim on my Windows 7 PC at work, using the context menu of my file manager. After closing the tab, using `:x`, I discovered t...
Why this happens ---------------- When you close the file with `:x`, it saves the buffer and closes the window/tab, but Vim does *not* forget about the file. If you execute the `:ls` command after doing so, you will see the buffer is still there. Then, when you re-open the file, Vim will notice that it already has a ...
10,882
<p>Let's get directly to it.</p> <p>I was working with some python code and realized I had written a bunch of <code>elif</code> blocks as <code>else if</code> after working too much in Javascript.</p> <p>My natural thought was "cool, I can make an abbreviation to fix those for me so I don't have to think much about i...
[ { "answer_id": 10883, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>You'll have to analyse the context of the text you've typed to know what you want to insert. For instance, you could...
2017/01/07
[ "https://vi.stackexchange.com/questions/10882", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9182/" ]
Let's get directly to it. I was working with some python code and realized I had written a bunch of `elif` blocks as `else if` after working too much in Javascript. My natural thought was "cool, I can make an abbreviation to fix those for me so I don't have to think much about it". Then I realized {lhs} of abbreviati...
You'll have to analyse the context of the text you've typed to know what you want to insert. For instance, you could have a `if` abbreviation that detects there is a `else` just before. BTW: don't remove abbreviations/mappings for a specific filetype context. Instead define your abbreviations only in a given context w...
10,885
<p>You are probably wondering what I could possibly need this for? </p> <p>Well, my program will sometimes deal with erroneous strings that need to be manually fixed. So what I do, is I create a process which opens up a Vim, and suspends my program until a signal is emitted in which the file is changed (i.e. saved). I...
[ { "answer_id": 10886, "author": "Wolfie", "author_id": 9182, "author_profile": "https://vi.stackexchange.com/users/9182", "pm_score": 2, "selected": false, "text": "<p>You could key an event to an <a href=\"http://vimdoc.sourceforge.net/htmldoc/autocmd.html\" rel=\"nofollow noreferrer\">...
2017/01/08
[ "https://vi.stackexchange.com/questions/10885", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7960/" ]
You are probably wondering what I could possibly need this for? Well, my program will sometimes deal with erroneous strings that need to be manually fixed. So what I do, is I create a process which opens up a Vim, and suspends my program until a signal is emitted in which the file is changed (i.e. saved). I don't wan...
You could play with the `write` option. From [`:h 'write'`](http://vimhelp.appspot.com/options.txt.html#%27write%27): ``` 'write' boolean (default on) global {not in Vi} Allows writing files. When not set, writing a file is not allowed. Can be used for a view-only mode, where m...
10,888
<p>Without being in insert mode, from a certain line, I'd like to create a blank line above and below that line in staying on the same line. Could anyone have an idea how to do it?</p> <p>To clarify what I'm looking for, if I have three glued lines and I'm on the second line, I want to insert a blank line between the ...
[ { "answer_id": 10889, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 2, "selected": false, "text": "<p>To create blank line below current one use <kbd>o</kbd>, for line above <kbd>O</kbd>.</p>\n" }, { "answer_id": ...
2017/01/08
[ "https://vi.stackexchange.com/questions/10888", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
Without being in insert mode, from a certain line, I'd like to create a blank line above and below that line in staying on the same line. Could anyone have an idea how to do it? To clarify what I'm looking for, if I have three glued lines and I'm on the second line, I want to insert a blank line between the first and ...
Use marks. For example put this into your .vimrc: ``` nnoremap <silent><A-j> :set paste<CR>m`o<Esc>``:set nopaste<CR> nnoremap <silent><A-k> :set paste<CR>m`O<Esc>``:set nopaste<CR> ``` `Alt`+`j` and `Alt`+`k` **inserts blank line above and below current line in normal mode** respectively. Here a nice addition for ...
10,897
<p>I am trying to use vimdiff as my git merge tool, but the colors used are making it unbearable (at least on Windows/Mingw): the background color and the foreground color is the same for some of the conflicting lines, making it needlessly hard to figure out what is going on (see the lines below containing <code>includ...
[ { "answer_id": 10898, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 6, "selected": true, "text": "<p>The colors are controlled by these four highlight groups (<code>:help hl-DiffAdd</code>):</p>\n\n<pre><code>DiffAdd ...
2017/01/09
[ "https://vi.stackexchange.com/questions/10897", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1087/" ]
I am trying to use vimdiff as my git merge tool, but the colors used are making it unbearable (at least on Windows/Mingw): the background color and the foreground color is the same for some of the conflicting lines, making it needlessly hard to figure out what is going on (see the lines below containing `include=`). [...
The colors are controlled by these four highlight groups (`:help hl-DiffAdd`): ``` DiffAdd diff mode: Added line DiffChange diff mode: Changed line DiffDelete diff mode: Deleted line DiffText diff mode: Changed text within a changed line ``` These are typically defined by a *color scheme*, but you can custo...
10,901
<p>When I run <code>shopt -s globstar; ls -1 tests/**/Helpers/**/*.php</code> in <code>bash</code> I get:</p> <pre><code>tests/Helpers/Layout.php tests/Helpers/Link.php tests/Helpers/LinksPage.php tests/Helpers/LiqpayRedirect.php tests/Helpers/LoginPage.php tests/Helpers/Project.php tests/Helpers/ProjectsPage.php test...
[ { "answer_id": 10904, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 3, "selected": false, "text": "<p>You can check with <code>echo glob2regpat('tests/**/Helpers/**/*.php')</code> to what regular expression this wi...
2017/01/10
[ "https://vi.stackexchange.com/questions/10901", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1553/" ]
When I run `shopt -s globstar; ls -1 tests/**/Helpers/**/*.php` in `bash` I get: ``` tests/Helpers/Layout.php tests/Helpers/Link.php tests/Helpers/LinksPage.php tests/Helpers/LiqpayRedirect.php tests/Helpers/LoginPage.php tests/Helpers/Project.php tests/Helpers/ProjectsPage.php tests/Helpers/QueriesPage.php tests/Help...
### tl;dr a bug in `vim` ### how to reproduce/inspect 1. Build `vim` from sources with the following patch: ``` diff --git a/src/misc1.c b/src/misc1.c index 2d635d677..44ccf4a7a 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -10171,8 +10171,18 @@ unix_expandpath( char_u *path, int wildoff, int ...
10,905
<p>I have a file that looks as follows:</p> <pre><code>aa,bb,cc,dd,ee,ff,gg aa,bb,cc,dd,hh aa,bb,cc,dd,ii,jj etc. </code></pre> <p>I would like to (preferably using one command) change occurrences of a <code>,</code> by a <code>:</code> from the 5th <code>,</code> until the last one.</p> <p>I would thus get: </p> <...
[ { "answer_id": 10906, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>You'll have to play with <code>/\\=</code>+<code>submatch()</code> and <code>substitute()</code>. First <code>:s</co...
2017/01/10
[ "https://vi.stackexchange.com/questions/10905", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10786/" ]
I have a file that looks as follows: ``` aa,bb,cc,dd,ee,ff,gg aa,bb,cc,dd,hh aa,bb,cc,dd,ii,jj etc. ``` I would like to (preferably using one command) change occurrences of a `,` by a `:` from the 5th `,` until the last one. I would thus get: ``` aa,bb,cc,dd,ee:ff:gg aa,bb,cc,dd,hh aa,bb,cc,dd,ii:jj etc. ``` In...
You could also try the following substitution command: ``` %s/\v(^(.{-},){4}.*)@<=,/:/g ``` The pattern is: ``` \v(^(.{-},){4}.*)@<=, ``` Which can be broken down like this: ``` \v(^(.{-},){4}.*)@<=, | ||| | | | | | | ||| | | | | +--- a comma | ||| | | | +--- the previous subpattern must be matc...
10,913
<p>I recently received a pull request to change my vim plugin to make it support python3. But these changes break the plugin for the vim on my Mac which seems to listen to python.</p> <pre><code>python import sys </code></pre> <p>versus</p> <pre><code>python3 import sys </code></pre> <p>Is there an elegant method t...
[ { "answer_id": 10915, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 3, "selected": false, "text": "<p>If you want to avoid rewriting the Python script, put it in a separate file and use <code>:pyfile</code> or <code>:py3f...
2017/01/10
[ "https://vi.stackexchange.com/questions/10913", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2165/" ]
I recently received a pull request to change my vim plugin to make it support python3. But these changes break the plugin for the vim on my Mac which seems to listen to python. ``` python import sys ``` versus ``` python3 import sys ``` Is there an elegant method to make the script in my plugin detect which state...
If you want to avoid rewriting the Python script, put it in a separate file and use `:pyfile` or `:py3file` instead. ``` let script_path = expand('<sfile>:p:h') . '/script.py' if !has('python') and !has('python3') finish endif execute (has('python3') ? 'py3file' : 'pyfile') script_path ``` This will load `scrip...
10,916
<p>Running <code>execute g:xx</code> doesn't work.</p> <pre><code>let g:str="move to right win\t&lt;C-w&gt;h" let g:temp=escape(matchstr(g:str,'\(\t\)\@&lt;=.*$'),'&lt;') let g:xx= "normal ".g:temp execute g:xx </code></pre> <p>Can anyone explain why?</p>
[ { "answer_id": 10918, "author": "Herb", "author_id": 5298, "author_profile": "https://vi.stackexchange.com/users/5298", "pm_score": -1, "selected": false, "text": "<p>In your first line, the <code>&lt;C-w&gt;</code> is not escaped, so it appears to be matched as a literal string, and the...
2017/01/11
[ "https://vi.stackexchange.com/questions/10916", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10798/" ]
Running `execute g:xx` doesn't work. ``` let g:str="move to right win\t<C-w>h" let g:temp=escape(matchstr(g:str,'\(\t\)\@<=.*$'),'<') let g:xx= "normal ".g:temp execute g:xx ``` Can anyone explain why?
``` let g:temp=eval('"'. g:temp .'"') ``` after > > > ``` > let g:temp=escape(matchstr(g:str,'\(\t\)\@<=.*$'),'<') > > ``` > > --- Extracting this into a `:function`: ``` function! Literalize(string) " get already properly escaped sequences out of the way, so we don't double-escape them let s = eval(...
10,929
<p>I've tried this</p> <pre><code>au BufWinEnter * if &amp;l:buftype != 'nofile' | map &lt;buffer&gt; &lt;CR&gt; &lt;Plug&gt;(easymotion-prefix) | endif </code></pre> <p>but somehow this isn't working (easymotion isn't working). While this works</p> <pre><code>au BufWinEnter * map &lt;buffer&gt; &lt;CR&gt; &lt;Plug&...
[ { "answer_id": 10930, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 3, "selected": true, "text": "<p>I'm not sure, but I think that <code>| endif</code> is in the <code>{rhs}</code> of the mapping command <code>:map</...
2017/01/11
[ "https://vi.stackexchange.com/questions/10929", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6634/" ]
I've tried this ``` au BufWinEnter * if &l:buftype != 'nofile' | map <buffer> <CR> <Plug>(easymotion-prefix) | endif ``` but somehow this isn't working (easymotion isn't working). While this works ``` au BufWinEnter * map <buffer> <CR> <Plug>(easymotion-prefix) ```
I'm not sure, but I think that `| endif` is in the `{rhs}` of the mapping command `:map`. To remove it, you could wrap the mapping in a chain and execute it, maybe like this: ``` au BufWinEnter * if &l:buftype != 'nofile' | exe "map <buffer> \<CR> \<Plug>(easymotion-prefix)" | endif ```
10,937
<p>I'm programming mostly in Python/Cython and use <code>foldmethod=syntax</code> (and <code>foldclose=</code>). Overall, this works fairly well, i.e. functions/classes/methods are folded reliably mostly. However, I have one problem: folds are often opend/closed while I'm typing. Specifically,</p> <ul> <li>While work...
[ { "answer_id": 19187, "author": "GGJON", "author_id": 16789, "author_profile": "https://vi.stackexchange.com/users/16789", "pm_score": 0, "selected": false, "text": "<p>Since Python is an Indented language, The easier solution is to set <code>foldmethod=indent</code>. The crux of this so...
2017/01/12
[ "https://vi.stackexchange.com/questions/10937", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2100/" ]
I'm programming mostly in Python/Cython and use `foldmethod=syntax` (and `foldclose=`). Overall, this works fairly well, i.e. functions/classes/methods are folded reliably mostly. However, I have one problem: folds are often opend/closed while I'm typing. Specifically, * While working on an indented block (usually a l...
Sure, just disable folding in insert mode, and restore it when you leave: ``` augroup folds au! au InsertEnter * let w:oldfen = &l:foldenable \| set nofoldenable au InsertLeave * \ if exists('w:oldfen') \ let &l:foldenable = w:oldfen \ unlet w:oldfen \ endif augroup END ```
10,939
<p>How can I determine if a filetype plugin (such as <code>vim-latexsuite</code>) has been installed and activated when I open the appropriate file? Another popular editor would indicate that the relevant "minor mode" is active. What's the vim equivalent?</p>
[ { "answer_id": 10944, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 3, "selected": false, "text": "<p>Vim plugins don't come with any activation indication, and in a proper setup, this isn't necessary.</p>\n\n<p>You can...
2017/01/12
[ "https://vi.stackexchange.com/questions/10939", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2932/" ]
How can I determine if a filetype plugin (such as `vim-latexsuite`) has been installed and activated when I open the appropriate file? Another popular editor would indicate that the relevant "minor mode" is active. What's the vim equivalent?
> > How can I determine if a filetype plugin (such as vim-latexsuite) has been installed > > > You could use [`:scriptnames`](http://vimhelp.appspot.com/repeat.txt.html#%3ascriptnames) which list all sourced files. Another option is to check for the variable indicating if the plugin was loaded, as it is [`recomme...
10,952
<p>When I open a new buffer I usually just do <code>:vsp something</code> which allows me to open a new buffer with a vertical split. However, when I don't control how the buffer should be opened (e.g. when typing <code>:help</code>) the new buffer is always opened with a horizontal split, which really annoys me. Is th...
[ { "answer_id": 10944, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 3, "selected": false, "text": "<p>Vim plugins don't come with any activation indication, and in a proper setup, this isn't necessary.</p>\n\n<p>You can...
2017/01/12
[ "https://vi.stackexchange.com/questions/10952", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10823/" ]
When I open a new buffer I usually just do `:vsp something` which allows me to open a new buffer with a vertical split. However, when I don't control how the buffer should be opened (e.g. when typing `:help`) the new buffer is always opened with a horizontal split, which really annoys me. Is there anyway to change the ...
> > How can I determine if a filetype plugin (such as vim-latexsuite) has been installed > > > You could use [`:scriptnames`](http://vimhelp.appspot.com/repeat.txt.html#%3ascriptnames) which list all sourced files. Another option is to check for the variable indicating if the plugin was loaded, as it is [`recomme...
10,962
<p>Here is what my tab-bar in GVim looks like:</p> <p><a href="https://i.stack.imgur.com/xz9On.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xz9On.png" alt="enter image description here"></a></p> <p>I'm having a hard time to identify which of the tabs is the active one. </p> <p>How can I configu...
[ { "answer_id": 10944, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 3, "selected": false, "text": "<p>Vim plugins don't come with any activation indication, and in a proper setup, this isn't necessary.</p>\n\n<p>You can...
2017/01/13
[ "https://vi.stackexchange.com/questions/10962", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1542/" ]
Here is what my tab-bar in GVim looks like: [![enter image description here](https://i.stack.imgur.com/xz9On.png)](https://i.stack.imgur.com/xz9On.png) I'm having a hard time to identify which of the tabs is the active one. How can I configure the color of the tab-bar, for example I'd like to use a different color ...
> > How can I determine if a filetype plugin (such as vim-latexsuite) has been installed > > > You could use [`:scriptnames`](http://vimhelp.appspot.com/repeat.txt.html#%3ascriptnames) which list all sourced files. Another option is to check for the variable indicating if the plugin was loaded, as it is [`recomme...
10,969
<p>I've added this script to my vimrc file</p> <pre><code>command! EnableMouse :call EnableMouseFunction() function! EnableMouseFunction() let command = ":set mouse=a" exe command endfunction </code></pre> <p>So, ... what is the method to unset mouse in vim?</p>
[ { "answer_id": 10970, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 1, "selected": false, "text": "<p>The use of the mouse is controlled (as you find out) with the <code>mouse</code> setting. It is activated only if <code>m...
2017/01/13
[ "https://vi.stackexchange.com/questions/10969", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2965/" ]
I've added this script to my vimrc file ``` command! EnableMouse :call EnableMouseFunction() function! EnableMouseFunction() let command = ":set mouse=a" exe command endfunction ``` So, ... what is the method to unset mouse in vim?
You don't need anything that complex ``` set mouse=a " and set mouse= ``` are enough. You can even define your command to be ``` :command! ToggleMouse exe 'set mouse='.(empty(&mouse)?'a':'') " Here I use `:exe` because I didn't want to use `:if` in a command definition which would look like: :command! ToggleMouse...
10,976
<p>I'm at a loss at how to get rid of this jarring purple background surrounding any text that isn't visible when vim initially loads the file and displays the text. It appears when I scroll past the initially displayed text, but not when I jump to an entirely different area or resize the window. This happens for all...
[ { "answer_id": 10994, "author": "Gr1nch", "author_id": 10731, "author_profile": "https://vi.stackexchange.com/users/10731", "pm_score": -1, "selected": false, "text": "<p>You need to add to your .vimrc file <code>set t_Co=256</code> that allow the terminal to use colors solarized.</p>\n"...
2017/01/13
[ "https://vi.stackexchange.com/questions/10976", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4940/" ]
I'm at a loss at how to get rid of this jarring purple background surrounding any text that isn't visible when vim initially loads the file and displays the text. It appears when I scroll past the initially displayed text, but not when I jump to an entirely different area or resize the window. This happens for all file...
The following configuration fixed OP's issue: ``` set t_ut= ``` This says to Vim to use the current background's color to clear the screen. Related answer: <https://stackoverflow.com/a/15095377/2558252>
10,985
<pre><code>OSX - sierra iterm2 3.0.13 tmux 2.3 vim 8.0.176 </code></pre> <p>colors work fine in bare iterm2:</p> <p><a href="https://i.stack.imgur.com/O586h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O586h.png" alt="enter image description here"></a></p> <p>but under tmux:</p> <p><a href="ht...
[ { "answer_id": 10994, "author": "Gr1nch", "author_id": 10731, "author_profile": "https://vi.stackexchange.com/users/10731", "pm_score": -1, "selected": false, "text": "<p>You need to add to your .vimrc file <code>set t_Co=256</code> that allow the terminal to use colors solarized.</p>\n"...
2017/01/14
[ "https://vi.stackexchange.com/questions/10985", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
``` OSX - sierra iterm2 3.0.13 tmux 2.3 vim 8.0.176 ``` colors work fine in bare iterm2: [![enter image description here](https://i.stack.imgur.com/O586h.png)](https://i.stack.imgur.com/O586h.png) but under tmux: [![enter image description here](https://i.stack.imgur.com/076xs.png)](https://i.stack.imgur.com/076xs...
The following configuration fixed OP's issue: ``` set t_ut= ``` This says to Vim to use the current background's color to clear the screen. Related answer: <https://stackoverflow.com/a/15095377/2558252>
10,986
<p>We have few modes in vim. The most common used are: <code>Normal</code> (=Command), <code>Insert</code>, <code>Command-line</code>, but also some <em>sub-modes</em>, like: <code>Replace</code>,<code>Visual-line</code> (<kbd>V</kbd>) or <code>Visual-block</code> (<kbd>Ctrl</kbd>+<kbd>v</kbd>).</p> <p>Does vim suppor...
[ { "answer_id": 10987, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>The best you can do is something like:</p>\n\n<pre><code>fun! ToggleW00tMode()\n if !exists('b:w00t')\n le...
2017/01/14
[ "https://vi.stackexchange.com/questions/10986", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8444/" ]
We have few modes in vim. The most common used are: `Normal` (=Command), `Insert`, `Command-line`, but also some *sub-modes*, like: `Replace`,`Visual-line` (`V`) or `Visual-block` (`Ctrl`+`v`). Does vim support creation of some kind of user-defined *submode*? How to make simple mode that inherits from the existing one...
The best you can do is something like: ``` fun! ToggleW00tMode() if !exists('b:w00t') let b:w00t=1 else unlet b:w00t endif return "" endfun inoremap <C-w> <C-r>=ToggleW00tMode()<Cr> " Do something different depending on the value of b:w00t inoremap <expr> o exists('b:w00t') ? '0' : '...
10,988
<p>neovim 0.2-dev</p> <p><code>:Lexplore</code> opens up explorer window and entering <code>:Lexplore</code> again toggles it. However, if I interact with the explorer window(i.e. expand a directory), then typing <code>:Lexplore</code> opens up another explorer window instead of closing the existing one.</p> <p><a hr...
[ { "answer_id": 10993, "author": "Philia Fan", "author_id": 6731, "author_profile": "https://vi.stackexchange.com/users/6731", "pm_score": 2, "selected": false, "text": "<p>I tried several times and it seems once you have interacted with the content, it opens a new window when <code>:Lexp...
2017/01/14
[ "https://vi.stackexchange.com/questions/10988", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10853/" ]
neovim 0.2-dev `:Lexplore` opens up explorer window and entering `:Lexplore` again toggles it. However, if I interact with the explorer window(i.e. expand a directory), then typing `:Lexplore` opens up another explorer window instead of closing the existing one. [![Lexplore opens up a new explorer](https://i.stack.im...
I followed this script (<https://www.reddit.com/r/vim/comments/6jcyfj/toggle_lexplore_properly/djdmsal/>) and it works as expected. ``` let g:NetrwIsOpen=0 function! ToggleNetrw() if g:NetrwIsOpen let i = bufnr("$") while (i >= 1) if (getbufvar(i, "&filetype") == "netrw") ...
11,005
<p>I have a number of files with a syntax almost identical to C, though the files have suffixes such as <code>.t</code>, <code>.sc</code></p> <p>I would like to have the same syntax highlighting that I have for standard C files ending with the suffix <code>.c</code>.</p> <p>For any one file I know I can execute:</p> ...
[ { "answer_id": 11006, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 2, "selected": false, "text": "<p>You can put this in your ~/.vimrc, or in a file in ~/.vim/ftdetect:</p>\n\n<pre><code>au BufNewFile,BufRead *.t,*.sc s...
2017/01/15
[ "https://vi.stackexchange.com/questions/11005", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10865/" ]
I have a number of files with a syntax almost identical to C, though the files have suffixes such as `.t`, `.sc` I would like to have the same syntax highlighting that I have for standard C files ending with the suffix `.c`. For any one file I know I can execute: ``` :set filetype=c ``` but it is cumbersome to hav...
Yes, you can add the following: ``` augroup filetypedetect au! BufRead,BufNewFile *.t, *.sc setfiletype c augroup END ``` However, to help keep your .vimrc tidy, you could also put that in a separate file called filetypes.vim in your .vim directory.
11,017
<p>I wrote the following in my .vimrc file in order to automate getting an HTML file set up.</p> <pre><code>:imap html&lt;tab&gt; \&lt;html&gt;&lt;enter&gt; \&lt;tab&gt;&lt;head&gt;&lt;enter&gt; .... </code></pre> <p>and so on. However, when I use this in an .html file the tabs are very off, seemingly because ta...
[ { "answer_id": 11022, "author": "Octaviour", "author_id": 8061, "author_profile": "https://vi.stackexchange.com/users/8061", "pm_score": 2, "selected": false, "text": "<p>I think this has to do with the way indenting is handled. If this is true <code>expandtab</code> should be set in you...
2017/01/17
[ "https://vi.stackexchange.com/questions/11017", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6225/" ]
I wrote the following in my .vimrc file in order to automate getting an HTML file set up. ``` :imap html<tab> \<html><enter> \<tab><head><enter> .... ``` and so on. However, when I use this in an .html file the tabs are very off, seemingly because tabs in HTML files are treated like sequences of spaces rather th...
So it turns out that, for whatever reason, the settings I used caused the delete command to only delete four spaces at a time, while the file-type-specific settings cause the tab command to produce eight--thus, a mis-match in how things get tabbed and un-tabbed. The resolution I now use that seems to be working is, in ...
11,018
<p>I installed the powerline patched fonts by following the wiki at <a href="https://powerline.readthedocs.io/en/master/installation/linux.html#patched-font-installation" rel="nofollow noreferrer">https://powerline.readthedocs.io/en/master/installation/linux.html#patched-font-installation</a></p> <p>I selected the pat...
[ { "answer_id": 11021, "author": "Octaviour", "author_id": 8061, "author_profile": "https://vi.stackexchange.com/users/8061", "pm_score": 2, "selected": false, "text": "<p>I remember having a similar problem. I never really solved it but worked my way around it by installing the <a href=\...
2017/01/17
[ "https://vi.stackexchange.com/questions/11018", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6766/" ]
I installed the powerline patched fonts by following the wiki at <https://powerline.readthedocs.io/en/master/installation/linux.html#patched-font-installation> I selected the patched font and added: ``` let g:airline_powerline_fonts = 1 ``` to my .vimrc But I still see wrong symbols. How can I fix this? [![enter i...
I remember having a similar problem. I never really solved it but worked my way around it by installing the [Hack](http://sourcefoundry.org/hack/) font and by putting the following in my `.vimrc`: ``` set guifont=Hack:h10:cANSI " Airline let g:airline_powerline_fonts = 1 if !exists('g:airline_symbols') let g:air...
11,023
<p>I don't get it, my vimrc has <code>set ai</code>, but when editing project files (php), <code>:set ai?</code> always returns <code>noautoindent</code></p> <p>inside .vimrc <code>:set ai?</code> returns true. </p> <p>my rc:</p> <pre><code>" vim-plug (https://github.com/junegunn/vim-plug) " Automatically install vi...
[ { "answer_id": 11024, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 4, "selected": true, "text": "<p>This is because of vim's internal php settings. If you look in <code>vim##/indent/php.vim</code>, there's the followin...
2017/01/17
[ "https://vi.stackexchange.com/questions/11023", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I don't get it, my vimrc has `set ai`, but when editing project files (php), `:set ai?` always returns `noautoindent` inside .vimrc `:set ai?` returns true. my rc: ``` " vim-plug (https://github.com/junegunn/vim-plug) " Automatically install vim-plug and run PlugInstall if vim-plug not found if empty(glob('~/.vim/...
This is because of vim's internal php settings. If you look in `vim##/indent/php.vim`, there's the following line: ``` setlocal noautoindent ``` If you want to override this feature, you'll need to use an autocmd in your `vimrc`. Try this: ``` autocmd FileType php setlocal autoindent ``` This will turn on auto in...
11,025
<p>I have a command:</p> <pre><code>command! -nargs=1 TmuxSession !tmux.session "&lt;args&gt;" </code></pre> <p>and I want to run it in visual mode so that selected text will be passed as argument.<br> By selected text I mean selected in visual mode in vim.</p> <p>How can I achieve that?</p> <p>I tried running </p>...
[ { "answer_id": 11028, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 5, "selected": true, "text": "<p>See <a href=\"https://stackoverflow.com/a/10573044\">this answer on stackoverflow</a>.</p>\n\n<p>The example given is:</p...
2017/01/18
[ "https://vi.stackexchange.com/questions/11025", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3254/" ]
I have a command: ``` command! -nargs=1 TmuxSession !tmux.session "<args>" ``` and I want to run it in visual mode so that selected text will be passed as argument. By selected text I mean selected in visual mode in vim. How can I achieve that? I tried running ``` command -nargs=1 -range -register TmuxSession...
See [this answer on stackoverflow](https://stackoverflow.com/a/10573044). The example given is: ``` function! PrintGivenRange() range echo "firstline ".a:firstline." lastline ".a:lastline " Do some more things endfunction command! -range PassRange <line1>,<line2>call PrintGivenRange() ``` Thus you mig...
11,029
<p>I have a number of multi million line sets of data to edit before using a program to analyse them.</p> <p>I have a set of regexp (23 of them) which do the work. Things like <code>:%s/\n\n/\r</code> to get rid of multiple blank lines</p> <p>How can I turn this set of commands into a script?</p>
[ { "answer_id": 11028, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 5, "selected": true, "text": "<p>See <a href=\"https://stackoverflow.com/a/10573044\">this answer on stackoverflow</a>.</p>\n\n<p>The example given is:</p...
2017/01/18
[ "https://vi.stackexchange.com/questions/11029", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10843/" ]
I have a number of multi million line sets of data to edit before using a program to analyse them. I have a set of regexp (23 of them) which do the work. Things like `:%s/\n\n/\r` to get rid of multiple blank lines How can I turn this set of commands into a script?
See [this answer on stackoverflow](https://stackoverflow.com/a/10573044). The example given is: ``` function! PrintGivenRange() range echo "firstline ".a:firstline." lastline ".a:lastline " Do some more things endfunction command! -range PassRange <line1>,<line2>call PrintGivenRange() ``` Thus you mig...
11,058
<p>I have recently upgraded to Vim 8 using Homebrew, but my <code>vi</code> commands still load the OS-provided version 7.4 of Vim. I could add an alias to <code>vi</code>, but is there another way?</p>
[ { "answer_id": 11059, "author": "Warren Young", "author_id": 6852, "author_profile": "https://vi.stackexchange.com/users/6852", "pm_score": 5, "selected": true, "text": "<p>This is happening because the OS's <code>vi</code> is ahead of Homebrew <code>vi</code> in the <code>PATH</code>.</...
2017/01/21
[ "https://vi.stackexchange.com/questions/11058", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10836/" ]
I have recently upgraded to Vim 8 using Homebrew, but my `vi` commands still load the OS-provided version 7.4 of Vim. I could add an alias to `vi`, but is there another way?
This is happening because the OS's `vi` is ahead of Homebrew `vi` in the `PATH`. While you could fix it by putting `/usr/local/bin` ahead of `/usr/bin` in the `PATH`, that would be a security hole since Homebrew gives ownership of that directory to your user. That permission change from the macOS default means that ev...
11,061
<p>Installing plugins through vim-plug involves putting the following code inside the vimrc file.</p> <pre><code>call plug#begin('~/.vim/plugged') Plug 'user/repository' call plug#end() </code></pre> <p>I install a lot of plugins, and I don't want to put all the code inside the main configuration file. I'd instead li...
[ { "answer_id": 12152, "author": "mike", "author_id": 7267, "author_profile": "https://vi.stackexchange.com/users/7267", "pm_score": 0, "selected": false, "text": "<p>I think, you have to call <code>call plug#begin('~/.vim/plugged')</code>, only then you can source the plugin file. It is ...
2017/01/21
[ "https://vi.stackexchange.com/questions/11061", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
Installing plugins through vim-plug involves putting the following code inside the vimrc file. ``` call plug#begin('~/.vim/plugged') Plug 'user/repository' call plug#end() ``` I install a lot of plugins, and I don't want to put all the code inside the main configuration file. I'd instead like to source it from a s...
I would go with either ``` " load Plugins.vim, searching it in "all vim places" runtime Plugins.vim ``` or ``` " load Plugins.vim from the relative path of your vimrc source <sfile>:h/.vim/Plugins.vim ```
11,068
<p>To make functions local, you prefix it with 's:'. But then it can't be called with mappings. Given this function:</p> <pre><code>function! ScriptFunction() ... endfunction </code></pre> <p>What convention or keywords do I add to precent name conflicts while still allowing the user to add a mapping?</p>
[ { "answer_id": 11069, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 0, "selected": false, "text": "<p>One way is to make a command. I did that in my plugin like so:</p>\n\n<pre><code>execute \"command! -buffer -nargs=0 Pi...
2017/01/23
[ "https://vi.stackexchange.com/questions/11068", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10905/" ]
To make functions local, you prefix it with 's:'. But then it can't be called with mappings. Given this function: ``` function! ScriptFunction() ... endfunction ``` What convention or keywords do I add to precent name conflicts while still allowing the user to add a mapping?
In mappings, script-local functions are called with `<sid>` instead of `s:`. But as indirectly suggested in the other answer, you'd better have the mapping in a plugin and the function in an autoload plugin. It's much better for starting times. BTW, There is an extensive documentation in 2 parts about mappings on vim...
11,087
<p>I am currently using <a href="https://github.com/kana/vim-altr" rel="nofollow noreferrer">vim-altr</a> to switch between head and source file in c++. I use </p> <pre><code>nmap &lt;F2&gt; &lt;Plug&gt;(altr-forward) nmap &lt;F3&gt; &lt;Plug&gt;(altr-back) </code></pre> <p>to move between buffer. However, this opens...
[ { "answer_id": 11088, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 0, "selected": false, "text": "<p>The venerable alternate plugin (<a href=\"http://www.vim.org/scripts/script.php?script_id=31\" rel=\"nofollow norefe...
2017/01/24
[ "https://vi.stackexchange.com/questions/11087", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/622/" ]
I am currently using [vim-altr](https://github.com/kana/vim-altr) to switch between head and source file in c++. I use ``` nmap <F2> <Plug>(altr-forward) nmap <F3> <Plug>(altr-back) ``` to move between buffer. However, this opens two buffers. I would like it to be in one (and only one) buffer. If this cannot be d...
I think you're misunderstanding the terminology slightly, here. Essentially, a Vim buffer *is* a file, so loading two files into a single buffer isn't a concept that really makes sense. It seems from your comments that the real issue is that you don't want to have both files in the *buffer list* (as displayed by vim-a...
11,092
<p>In a fortran code for example, there are lines like</p> <pre><code>c write(6,*) "some text" write(6,*) "some other text" </code></pre> <p>How would I search for lines having a <code>write</code> but exclude all lines starting with <code>c</code> or <code>C.</code></p>
[ { "answer_id": 11093, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>You can use the regular expression:</p>\n\n<pre><code>^\\([^cC].*\\)\\?write\n</code></pre>\n\n<p>Or, using \"very magic\" to...
2017/01/24
[ "https://vi.stackexchange.com/questions/11092", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10566/" ]
In a fortran code for example, there are lines like ``` c write(6,*) "some text" write(6,*) "some other text" ``` How would I search for lines having a `write` but exclude all lines starting with `c` or `C.`
You can use the regular expression: ``` ^\([^cC].*\)\?write ``` Or, using "very magic" to simplify a little: ``` \v^([^cC].*)?write ``` 1. `\v`: turns on "very magic" so we don't have to use as many escape characters, 2. `^`: matches a start of the line, 3. `([^cC].*)?`: matches either nothing, or any character t...
11,096
<p>I want to copy different strings from different lines of the file and then paste them together at once. In other words, I want to collect different words in a basket and then paste them at once. How can I do this?</p>
[ { "answer_id": 11097, "author": "8bittree", "author_id": 2736, "author_profile": "https://vi.stackexchange.com/users/2736", "pm_score": 5, "selected": true, "text": "<p>Use an uppercase register when yanking (copying):</p>\n\n<pre><code>\"Ay\n</code></pre>\n\n<p><code>\"A</code> says to ...
2017/01/24
[ "https://vi.stackexchange.com/questions/11096", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10987/" ]
I want to copy different strings from different lines of the file and then paste them together at once. In other words, I want to collect different words in a basket and then paste them at once. How can I do this?
Use an uppercase register when yanking (copying): ``` "Ay ``` `"A` says to *append* to the `a` register, as opposed to `"a` which would *replace* the contents of the `a` register. Once you've copied everything into the register, you can then paste it all at once with: ``` "ap ```
11,107
<p>Is there a way to set Negate in the substitution command? In other words how to substitute any character except <code>|</code> to <code>-</code> and all <code>|</code> to <code>+</code>. Example:</p> <pre><code>| some text | other text | </code></pre> <p>to </p> <pre><code>+-----------+------------+ </code></pre>...
[ { "answer_id": 11109, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>You can use the replace special substitution:</p>\n\n<pre><code>:s/./\\= submatch(0) == '|' ? '+' : '-'/g\n</code></pre>\n...
2017/01/25
[ "https://vi.stackexchange.com/questions/11107", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9633/" ]
Is there a way to set Negate in the substitution command? In other words how to substitute any character except `|` to `-` and all `|` to `+`. Example: ``` | some text | other text | ``` to ``` +-----------+------------+ ``` Is there a shortest way than `:s/[^|]/-/g | s/|/+/g` ?
You can use the replace special substitution: ``` :s/./\= submatch(0) == '|' ? '+' : '-'/g ``` Here `\=` says to use the following expression to use as the result string. And it's checking for `submatch(0)` (the char matched by the `/./` pattern) and do a condition on that. Have a look at: * `:h sub-replace-speci...
11,122
<p>I found the following description of a command which sets up which items must appear in the status line, <a href="https://www.vi-improved.org/recommendations/" rel="nofollow noreferrer">here</a>:</p> <pre><code>set statusline=%F%m%r%h%w[%L][%{&amp;ff}]%y[%p%%][%04l,%04v] " | | | | | | | | | ...
[ { "answer_id": 11123, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 3, "selected": false, "text": "<p>Here's what I'm currently using to do it:</p>\n\n<pre><code>nno &lt;silent&gt; m&lt;cr&gt; :&lt;c-u&gt;call &lt;s...
2017/01/26
[ "https://vi.stackexchange.com/questions/11122", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6960/" ]
I found the following description of a command which sets up which items must appear in the status line, [here](https://www.vi-improved.org/recommendations/): ``` set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v] " | | | | | | | | | | | " | | | | | | | | | ...
Here's what I'm currently using to do it: ``` nno <silent> m<cr> :<c-u>call <sid>break_down_mark()<cr> nno <silent> m<bs> :<c-u>call <sid>break_down_clear()<cr> nno <silent> m<tab> :<c-u>call <sid>break_down_draw()<cr> fu! s:break_down_clear() abort if exists('s:bd_marks') call matchdelete(s:bd_marks...
11,126
<p>I frequently use gvim on a windows 7 computer with a touch screen. If I flick up or down with the touch screen, it creates a selection (in <em>S</em> mode, not <em>V</em> mode).</p> <p>I'm not really a fan of this default behavior. It's seems pointless and unintuitive to me. Can I configure flicking to vertically s...
[ { "answer_id": 11128, "author": "user41805", "author_id": 10378, "author_profile": "https://vi.stackexchange.com/users/10378", "pm_score": 4, "selected": true, "text": "<p><em>Note: I have not tested this with gvim, only with normal vim</em></p>\n<p>This piece of code allows me to scroll...
2017/01/26
[ "https://vi.stackexchange.com/questions/11126", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
I frequently use gvim on a windows 7 computer with a touch screen. If I flick up or down with the touch screen, it creates a selection (in *S* mode, not *V* mode). I'm not really a fan of this default behavior. It's seems pointless and unintuitive to me. Can I configure flicking to vertically scroll instead of creatin...
*Note: I have not tested this with gvim, only with normal vim* This piece of code allows me to scroll instead of selecting text when I drag using my mouse. ```vim function! MouseScroll() "mark b is the current cursor position "mark a is the previous cursor position norm mb let currPos=line('.') norm `a le...
11,137
<p>This is for C coding, but would apply to editing many languages. I often use ctags or lately cscope to jump around, and find I often need to quickly check or learn what function I am in.</p> <p>A great tool that seems well suited to this is <code>[[</code> (which goes to next <code>{</code> in column 1) Then you in...
[ { "answer_id": 11138, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>Here are some ideas to explore as I don't see any simple and perfect solution.</p>\n\n<ul>\n<li>If you're already us...
2017/01/26
[ "https://vi.stackexchange.com/questions/11137", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10155/" ]
This is for C coding, but would apply to editing many languages. I often use ctags or lately cscope to jump around, and find I often need to quickly check or learn what function I am in. A great tool that seems well suited to this is `[[` (which goes to next `{` in column 1) Then you instantly jump back to where you w...
Here are some ideas to explore as I don't see any simple and perfect solution. * If you're already using ctags, you could use it on-the-fly on the current file to obtain the line numbers where functions start. From there, knowing the name of the current function will be quite easy -- I've already written the related l...
11,148
<p>How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period? </p> <p>The commands <code>df.</code>, <code>d)</code>, and <code>D</code> all truncate the sentence but don't keep the period. Manually, I can type <code>d/\.&lt;ENTER&gt;:noh&lt;ENTER&gt;</code>.</p> ...
[ { "answer_id": 11149, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 3, "selected": false, "text": "<p>You had the right idea with <code>df.</code>. Of course, <code>f</code> goes up to the period like you noticed. If y...
2017/01/27
[ "https://vi.stackexchange.com/questions/11148", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11041/" ]
How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period? The commands `df.`, `d)`, and `D` all truncate the sentence but don't keep the period. Manually, I can type `d/\.<ENTER>:noh<ENTER>`. For example: I have this sentence and the cursor is at the position m...
With no extra configuration involved, I would just use: ``` c).<Esc> ``` Bonus: It's repeatable with the dot command. Also bonus: It works on [any POSIX `vi`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html) and is not Vim-specific. And actually, I would use `<C-[>` (or "Ctrl+[" if you speak Wind...
11,155
<p>I like the functionality of <code>gf</code> but for certain files I would like to run some (non-Vim) code on the file prior to displaying it in my window. Is there a way to capture the filename under the cursor so it can be used in a shortcut?</p> <p>For example, I want to create a shortcut that would run <code>&l...
[ { "answer_id": 11156, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>The filename under the cursor can be obtained with <code>expand(&lt;cfile&gt;)</code>. From there you can do whateve...
2017/01/27
[ "https://vi.stackexchange.com/questions/11155", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11053/" ]
I like the functionality of `gf` but for certain files I would like to run some (non-Vim) code on the file prior to displaying it in my window. Is there a way to capture the filename under the cursor so it can be used in a shortcut? For example, I want to create a shortcut that would run `<custom_unix_script> <file>` ...
In addition to @Luc Hermitte's answer of using `expand(<cfile>)`, you can also use the `:!` command to run a shell command. You could do something like the following: ``` nnoremap gf :execute "!<custom_unix_script> " . expand(<cfile>) ``` * `nnoremap`: Creates a normal mode non-recursive mapping * `:execute`: Allows...
11,163
<pre><code>:set lcs=precedes:^,eol:# </code></pre> <p>I want to insert a character <strong>^</strong> at the beginning of each line.<br> Here is the result of <strong>:set lcs=precedes:^,eol:#</strong>.</p> <p><a href="https://i.stack.imgur.com/4AbO0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com...
[ { "answer_id": 11164, "author": "Ashok Arora", "author_id": 9004, "author_profile": "https://vi.stackexchange.com/users/9004", "pm_score": 2, "selected": false, "text": "<p>To add <code>^</code> at the beginning of each line use </p>\n\n<p><code>:%s/^/^ /</code> </p>\n\n<p>For a range of...
2017/01/28
[ "https://vi.stackexchange.com/questions/11163", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5181/" ]
``` :set lcs=precedes:^,eol:# ``` I want to insert a character **^** at the beginning of each line. Here is the result of **:set lcs=precedes:^,eol:#**. [![enter image description here](https://i.stack.imgur.com/4AbO0.png)](https://i.stack.imgur.com/4AbO0.png) Why **lcs=precedes:^** can't add a character **^** i...
To add `^` at the beginning of each line use `:%s/^/^ /` For a range of lines use: Ex. Lines 10-20 - `:10,20s/^/^ /`
11,167
<p>E.g., it I do:</p> <pre><code>!echo a </code></pre> <p>or any other <code>!</code>, it first prints:</p> <pre><code>syntax error near unexpected token ( ls() ( /* my alias */ ) </code></pre> <p>and then the actual command.</p> <p>The problem only happens in GVIM, not in Vim.</p> <p>Ubuntu 16.10, vim 7.4.1829...
[ { "answer_id": 11168, "author": "Ciro Santilli OurBigBook.com", "author_id": 2038, "author_profile": "https://vi.stackexchange.com/users/2038", "pm_score": 1, "selected": false, "text": "<p>The default bashrc for Ubuntu, contains the following lines at the beginning:</p>\n\n<pre><code>if...
2017/01/28
[ "https://vi.stackexchange.com/questions/11167", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2038/" ]
E.g., it I do: ``` !echo a ``` or any other `!`, it first prints: ``` syntax error near unexpected token ( ls() ( /* my alias */ ) ``` and then the actual command. The problem only happens in GVIM, not in Vim. Ubuntu 16.10, vim 7.4.1829.
Instead of adding `-i` to `shellcmdflags` and reading your entire `.bashrc` just for loading aliases, keep your aliases in a separate file, like `~/.bash_aliases` for Ubuntu, and add to your vimrc: ``` let $BASH_ENV = "~/.bash_aliases" ``` From [the bash manual](https://www.gnu.org/software/bash/manual/html_node/Bas...
11,179
<p>I want to comment out a piece of code. For instance this snippet:</p> <pre><code>foo bar foo </code></pre> <p>Should become this:</p> <pre><code>&lt;!--foo bar foo--&gt; </code></pre> <p>So I type the following sequence:</p> <p><code>vap:norm '&lt;i&lt;!--&lt;C-v&gt;&lt;Esc&gt;'&gt;A--&gt;</code></p> <p>This g...
[ { "answer_id": 11180, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>When surrounding with this trick, always start by appending, then you can insert the head.</p>\n\n<p>Moreover, I'd p...
2017/01/30
[ "https://vi.stackexchange.com/questions/11179", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11077/" ]
I want to comment out a piece of code. For instance this snippet: ``` foo bar foo ``` Should become this: ``` <!--foo bar foo--> ``` So I type the following sequence: `vap:norm '<i<!--<C-v><Esc>'>A-->` This give me the following result, which is unexpected for me: ``` <!--<!--<!--foo bar foo-->-->--> ``` I u...
As I said in the comments I strongly recommend a plugin like [nerdcommenter](https://github.com/scrooloose/nerdcommenter) or [vim-commentary](https://github.com/tpope/vim-commentary) to do stuff like this because they are well tested and handle a lot of corner cases. Now if you want to do it by yourself a solution cou...
11,183
<p>I have a set of 10 line numbers, n1, n2 ,..., n10 in a code of 1000+ lines. I need to jump from one line to another. My normal practice is to do <code>n1G</code>, <code>n2G</code>... till the set is complete. It takes about 5 seconds to see if the specific line is error free.</p> <p>I would like to automate this by...
[ { "answer_id": 11185, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 4, "selected": true, "text": "<p>There is <code>:sleep</code> command (<code>:h sleep</code> or <code>:h gs</code>). Using that command it's possible to ...
2017/01/30
[ "https://vi.stackexchange.com/questions/11183", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10566/" ]
I have a set of 10 line numbers, n1, n2 ,..., n10 in a code of 1000+ lines. I need to jump from one line to another. My normal practice is to do `n1G`, `n2G`... till the set is complete. It takes about 5 seconds to see if the specific line is error free. I would like to automate this by jumping into the lines one afte...
There is `:sleep` command (`:h sleep` or `:h gs`). Using that command it's possible to loop over given array of line numbers: ``` let g:line_list = [ 5, 10, 15 ] let g:line_list_sleep = 5 " in seconds, add m suffix to go miliseconds function LinePlaylist() for x in g:line_list execute "normal " . x . "G" re...
11,200
<p>I'm having a problem with pasting on MacOS Sierra. When I copy text with newlines, I can paste it in a terminal without issue. e.g.: Text to be copied:</p> <pre><code>echo 'Foo' echo 'Bar' </code></pre> <p>result from terminal (same in iTerm, Term using both bash and zsh):</p> <pre><code>[23:38:29] ~ $ echo 'Foo'...
[ { "answer_id": 11208, "author": "hgiesel", "author_id": 6300, "author_profile": "https://vi.stackexchange.com/users/6300", "pm_score": 3, "selected": true, "text": "<p>Basically when you paste using <kbd>cmd</kbd> + <kbd>V</kbd>, it is just <em>throwing</em> the content of the macOS clip...
2017/01/31
[ "https://vi.stackexchange.com/questions/11200", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5653/" ]
I'm having a problem with pasting on MacOS Sierra. When I copy text with newlines, I can paste it in a terminal without issue. e.g.: Text to be copied: ``` echo 'Foo' echo 'Bar' ``` result from terminal (same in iTerm, Term using both bash and zsh): ``` [23:38:29] ~ $ echo 'Foo' echo 'Bar' Foo Bar ``` result from...
Basically when you paste using `cmd` + `V`, it is just *throwing* the content of the macOS clipboard at vim. It is just like typing each character that is in the clipboard literally into vim. That sometimes works, but often it doesn't. So the use is discouraged. For this purpose there is the `"*` and `"+` registers wh...
11,210
<p>Can I repeat a macro with the <code>.</code> command? For example, I'd like to be able to type:</p> <pre><code>@q... </code></pre> <p>and have it effectively call <code>@q</code> 4 times. With the default behavior, this works only if 'q' holds a single command, for example <code>dw</code>, <code>x</code>, or <code...
[ { "answer_id": 11219, "author": "Shadoath", "author_id": 8493, "author_profile": "https://vi.stackexchange.com/users/8493", "pm_score": 3, "selected": false, "text": "<p>To repeat your last macro you can use <code>@@</code> so <code>3@@</code> would essentially run @q 3 times. However th...
2017/01/31
[ "https://vi.stackexchange.com/questions/11210", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
Can I repeat a macro with the `.` command? For example, I'd like to be able to type: ``` @q... ``` and have it effectively call `@q` 4 times. With the default behavior, this works only if 'q' holds a single command, for example `dw`, `x`, or `iHello<esc>`. (This makes sense though, since '.' repeats the last *change...
Give this a try. It remaps `@` so that `g@` (plus a dummy motion `l`) is used afterwards, thus becoming the last operator and subject to repeating with `.`. ``` " When . repeats g@, repeat the last macro. fun! AtRepeat(_) " If no count is supplied use the one saved in s:atcount. " Otherwise save the new count ...
11,231
<p>Is it possible to create several functions with the same name whose implementation depends on the file type?</p> <p>For example, I could imagine a function named <code>CurrentFunctionName</code> that returns the name of the function in which the cursor of the current buffer is. Since the determination of a function...
[ { "answer_id": 11234, "author": "Nate Bosch", "author_id": 11135, "author_profile": "https://vi.stackexchange.com/users/11135", "pm_score": 4, "selected": true, "text": "<p>Inside <code>ftplugin/&lt;filetype&gt;.vim</code> you could set a buffer local variable to point to the correct fun...
2017/02/02
[ "https://vi.stackexchange.com/questions/11231", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/985/" ]
Is it possible to create several functions with the same name whose implementation depends on the file type? For example, I could imagine a function named `CurrentFunctionName` that returns the name of the function in which the cursor of the current buffer is. Since the determination of a function name depends on the ...
Inside `ftplugin/<filetype>.vim` you could set a buffer local variable to point to the correct function: ``` function s:CurrentFunctionName() abort " Implement the function here endfunction let b:CurrentFunctionName = function('<SID>CurrentFunctionName') ``` In other scripts you can `call b:CurrentFunctionName()`...
11,245
<p>In a fortran code, I have lines like</p> <pre><code>c write(6,*) "something" write(6,*) "something_else" </code></pre> <p>I would like to insert the first character of the previous line when I open a new line with <kbd>o</kbd> in normal mode or <kbd>enter</kbd> in insert mode.<br> In the example given, if ...
[ { "answer_id": 11246, "author": "user41805", "author_id": 10378, "author_profile": "https://vi.stackexchange.com/users/10378", "pm_score": 1, "selected": false, "text": "<p>Try adding this to your vimrc:</p>\n\n\n\n<pre class=\"lang-vim prettyprint-override\"><code>nnoremap o 0ylo^OP\n</...
2017/02/03
[ "https://vi.stackexchange.com/questions/11245", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10566/" ]
In a fortran code, I have lines like ``` c write(6,*) "something" write(6,*) "something_else" ``` I would like to insert the first character of the previous line when I open a new line with `o` in normal mode or `enter` in insert mode. In the example given, if I open a new line under the `1st` line, the l...
One possible approach is to use custom function: ``` function! MyFunction() let curline = getline(line('.')) let char = " " if len(curline) let char = curline[0] endif let l:r = append(line('.'), char) let l:r = setpos('.', [0, line('.')+1, 3, 1]) endfunction nnoremap o :call MyFunction()<CR>A inorema...
11,252
<p>I've switched from NeoComplete to YouCompleteMe because it has much better intellisense, though I had NeoComplete working much better with Omnicompletion. </p> <p>NeoComplete was able to automatically provide a popup with the right completions without me having to enter a specific mapping (<code>&lt;C-x&gt;&lt;C-v&...
[ { "answer_id": 11253, "author": "tracyone", "author_id": 10798, "author_profile": "https://vi.stackexchange.com/users/10798", "pm_score": 2, "selected": true, "text": "<p>Ycm can cooperate with <a href=\"https://github.com/Shougo/neco-vim\" rel=\"nofollow noreferrer\">Shougo/neco-vim</a>...
2017/02/04
[ "https://vi.stackexchange.com/questions/11252", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4901/" ]
I've switched from NeoComplete to YouCompleteMe because it has much better intellisense, though I had NeoComplete working much better with Omnicompletion. NeoComplete was able to automatically provide a popup with the right completions without me having to enter a specific mapping (`<C-x><C-v>` for Vim commands, `<C-...
Ycm can cooperate with [Shougo/neco-vim](https://github.com/Shougo/neco-vim) ``` autocmd FileType vim setlocal omnifunc=te#complete#vim_complete function! te#complete#vim_complete( findstart, base ) abort let line_prefix = s:get_input() if a:findstart let ret = necovim#get_complete_position( line_prefix ) ...
11,257
<p>This may seem a little nit-picky, but I like using the wildmenu to switch between buffers: I do :b and then hit tab until I get to the file I want. The problem is that sometimes, vim shows the entire file path instead of just the file. So instead of getting something nice like</p> <pre><code>foo.cpp bar.cpp foobar....
[ { "answer_id": 11258, "author": "Raziman T V", "author_id": 11171, "author_profile": "https://vi.stackexchange.com/users/11171", "pm_score": 1, "selected": false, "text": "<p>The files in the current working folder will be shortened whereas the rest will show the full path. <code>:cd %:p...
2017/02/04
[ "https://vi.stackexchange.com/questions/11257", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9483/" ]
This may seem a little nit-picky, but I like using the wildmenu to switch between buffers: I do :b and then hit tab until I get to the file I want. The problem is that sometimes, vim shows the entire file path instead of just the file. So instead of getting something nice like ``` foo.cpp bar.cpp foobar.cpp ``` I ge...
That's not a nitpicky concern. You should expect an editor to behave consistently. As @Raziman points out, buffer names are relative to the current working directory, unless the associated file is NOT even a descendant of the current working directory. If this is not your problem, read on... If the associated file is...
11,270
<p>I have 5000 text files in a folder with different names. I just need to add one more line to the end in all files.</p> <p>Example:</p> <pre><code>HELLO HELLO HELLO HELLO </code></pre> <p>I need make it</p> <pre><code>HELLO HELLO HELLO HELLO abc </code></pre> <p>I just need to add "abc" to the last line.</p>...
[ { "answer_id": 11271, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 2, "selected": false, "text": "<p>I would probably use the <code>argument-list</code> for this.</p>\n\n<p>First you have to add all files to the argume...
2017/02/05
[ "https://vi.stackexchange.com/questions/11270", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11183/" ]
I have 5000 text files in a folder with different names. I just need to add one more line to the end in all files. Example: ``` HELLO HELLO HELLO HELLO ``` I need make it ``` HELLO HELLO HELLO HELLO abc ``` I just need to add "abc" to the last line.
I would probably use the `argument-list` for this. First you have to add all files to the argument list and then you can use `argdo` to operate on all of them. So first let's populate the argument list. There's two ways to do this. The first is to go to your directory and open vim with `vim *`. This will open vim wit...
11,301
<p>I have installed a tiny vim version without the clipboard feature. Can I load this feature for the current version or do I have to install another version of vim?</p> <pre><code>$ vi --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48) Included patches: 1-1689 Extra patches: 8.0.0056 Modifie...
[ { "answer_id": 11303, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": true, "text": "<p>I'm pretty sure that the only way to change which features are enabled is to recompile vim. So, yes; you need to re-in...
2017/02/07
[ "https://vi.stackexchange.com/questions/11301", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10706/" ]
I have installed a tiny vim version without the clipboard feature. Can I load this feature for the current version or do I have to install another version of vim? ``` $ vi --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48) Included patches: 1-1689 Extra patches: 8.0.0056 Modified by pkg-vim-m...
I'm pretty sure that the only way to change which features are enabled is to recompile vim. So, yes; you need to re-install.
11,310
<p>Sometimes I see a window open with name <code>scratch</code>.</p> <p>I know it is some kind of temporary buffer/window.</p> <p>How can I create one?</p> <p><code>:h scratch</code> returns nothing.</p>
[ { "answer_id": 11311, "author": "wbogacz", "author_id": 10509, "author_profile": "https://vi.stackexchange.com/users/10509", "pm_score": 5, "selected": true, "text": "<p>It is probably a scratch buffer, which can be named. From the help:</p>\n<blockquote>\n<p>scratch</p>\n<p>Contains tex...
2017/02/08
[ "https://vi.stackexchange.com/questions/11310", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7247/" ]
Sometimes I see a window open with name `scratch`. I know it is some kind of temporary buffer/window. How can I create one? `:h scratch` returns nothing.
It is probably a scratch buffer, which can be named. From the help: > > scratch > > > Contains text that can be discarded at any time. It is kept when closing the window, it must be deleted explicitly. Settings: > > > > ``` > :setlocal buftype=nofile > :setlocal bufhidden=hide > :setlocal noswa...
11,324
<p>I need to annotate a text file, so I would like to add a <code>|</code> pipe character to the end of each line to put my annotations relatively close to the original text. Each line is <em>up to</em> 72 characters in length. How might I move to the 74th character of the line, even if the line itself is shorter (i.e....
[ { "answer_id": 11325, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": true, "text": "<p>You could also enable <code>'virtualedit'</code> option and directly jump to the column you're interested in.</p>\n\n...
2017/02/09
[ "https://vi.stackexchange.com/questions/11324", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/989/" ]
I need to annotate a text file, so I would like to add a `|` pipe character to the end of each line to put my annotations relatively close to the original text. Each line is *up to* 72 characters in length. How might I move to the 74th character of the line, even if the line itself is shorter (i.e. add spaces if needed...
You could also enable `'virtualedit'` option and directly jump to the column you're interested in. A very similar question as been asked lately on SO: <https://stackoverflow.com/questions/41964261/how-do-i-put-the-character-in-6th-column-and-80th-column-in-vi/41964372#41964372>
11,336
<p>I've just installed neovim and I have problem with RubyGem. </p> <p>Output of <code>:CheckHealth</code> indicates missing neovim RubyGem:</p> <pre><code>## Ruby provider - ERROR: Missing Neovim RubyGem - SUGGESTIONS: - Install or upgrade the neovim RubyGem using `gem install neovim`. - INFO: Rub...
[ { "answer_id": 12553, "author": "Aaron Shang", "author_id": 12877, "author_profile": "https://vi.stackexchange.com/users/12877", "pm_score": 1, "selected": false, "text": "<p>You may need to add the PATH of installed gems into your PATH.</p>\n\n<p>You can do it like below in your <code>....
2017/02/10
[ "https://vi.stackexchange.com/questions/11336", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11271/" ]
I've just installed neovim and I have problem with RubyGem. Output of `:CheckHealth` indicates missing neovim RubyGem: ``` ## Ruby provider - ERROR: Missing Neovim RubyGem - SUGGESTIONS: - Install or upgrade the neovim RubyGem using `gem install neovim`. - INFO: Ruby Version: ruby 2.2.6p396 (2016-1...
You may need to add the PATH of installed gems into your PATH. You can do it like below in your `.bashrc` or `.bash_profile` or other shells' rc/profile files. ``` [ -d $HOME/.gem/ruby/2.4.0/bin ] && PATH=$HOME/.gem/ruby/2.4.0/bin:$PATH ``` `export PATH` together with all other PATH values.
11,338
<p>Starting <code>vim</code> (8.0) with an empty <code>.vimrc</code>, or as <code>vim -u /dev/null</code>. Executing:</p> <pre><code>:set nocompatible :set wildmode=list </code></pre> <p>On the screen:</p> <pre><code>:e .config/█ </code></pre> <p>I always thought that what happens when you press <code>Tab</code> is...
[ { "answer_id": 12553, "author": "Aaron Shang", "author_id": 12877, "author_profile": "https://vi.stackexchange.com/users/12877", "pm_score": 1, "selected": false, "text": "<p>You may need to add the PATH of installed gems into your PATH.</p>\n\n<p>You can do it like below in your <code>....
2017/02/10
[ "https://vi.stackexchange.com/questions/11338", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8699/" ]
Starting `vim` (8.0) with an empty `.vimrc`, or as `vim -u /dev/null`. Executing: ``` :set nocompatible :set wildmode=list ``` On the screen: ``` :e .config/█ ``` I always thought that what happens when you press `Tab` is the result of my `statusline` or `laststatus`, but changing those do not affect the result: ...
You may need to add the PATH of installed gems into your PATH. You can do it like below in your `.bashrc` or `.bash_profile` or other shells' rc/profile files. ``` [ -d $HOME/.gem/ruby/2.4.0/bin ] && PATH=$HOME/.gem/ruby/2.4.0/bin:$PATH ``` `export PATH` together with all other PATH values.
11,356
<p>I'm looking at a file that has this in the .vimrc file:</p> <p><code>set iskeyword+=@-@</code></p> <p>I assumed it would let me delete a word with a hypen surrounded by two letters such as <code>this-word</code> with a <code>dw</code> command but it doesn't seem to work.</p>
[ { "answer_id": 11358, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 5, "selected": true, "text": "<p>From <code>:h 'isk</code>:</p>\n\n<pre><code>See 'isfname' for a description of the format of this option.\n</code><...
2017/02/11
[ "https://vi.stackexchange.com/questions/11356", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I'm looking at a file that has this in the .vimrc file: `set iskeyword+=@-@` I assumed it would let me delete a word with a hypen surrounded by two letters such as `this-word` with a `dw` command but it doesn't seem to work.
From `:h 'isk`: ``` See 'isfname' for a description of the format of this option. ``` Then from `:h 'isf`: ``` If the character is '@', all characters where isalpha() returns TRUE are included. Normally these are the characters a to z and A to Z, plus accented characters. To include '@' itself use "@-@". ``` So...
11,373
<p>Like most programmers, I perform a lot of repetitive tasks. In optimising my workflow, I'm taking some of those repetitive tasks, and refactoring them into shell scripts.</p> <p>One thing that I'm trying to automate is the recreation of PostgreSQL views. I have the following view.</p> <pre><code>create or replace ...
[ { "answer_id": 11460, "author": "Rolf", "author_id": 6357, "author_profile": "https://vi.stackexchange.com/users/6357", "pm_score": 0, "selected": false, "text": "<p>I was not able to reproduce your macro but here is a (far from ideal) approach to your problem: Register persistently your...
2017/02/12
[ "https://vi.stackexchange.com/questions/11373", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10101/" ]
Like most programmers, I perform a lot of repetitive tasks. In optimising my workflow, I'm taking some of those repetitive tasks, and refactoring them into shell scripts. One thing that I'm trying to automate is the recreation of PostgreSQL views. I have the following view. ``` create or replace view person as select...
To avoid screen flashes when editing stream [non-interactively](https://vi.stackexchange.com/q/788/467), you need to start Vim in Ex mode by adding `-e` (*Ex mode*) or `-E` (*improved Ex mode*) into your command-line arguments. Here is the simple example editing text from the standard output and printing the result in...
11,375
<p>I'm trying to write an <code>autocmd</code> to make a commit to a git repository. Here is some non-functional code that should illustrate what I'm trying to do:</p> <pre><code>let g: CommMsg = '' augroup misc autocmd! autocmd nmap &lt;buffer&gt; gc :call GetCommMsg()&lt;CR&gt;!git commit -m '=CommMsg'&lt;CR&gt...
[ { "answer_id": 11376, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 2, "selected": false, "text": "<p>Maybe this is what you're aiming for?</p>\n\n<pre><code>nnoremap gc :execute '!git commit -m \"'.input('Enter message: ...
2017/02/13
[ "https://vi.stackexchange.com/questions/11375", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I'm trying to write an `autocmd` to make a commit to a git repository. Here is some non-functional code that should illustrate what I'm trying to do: ``` let g: CommMsg = '' augroup misc autocmd! autocmd nmap <buffer> gc :call GetCommMsg()<CR>!git commit -m '=CommMsg'<CR> augroup END function! GetCommMsg() let...
Maybe this is what you're aiming for? ``` nnoremap gc :execute '!git commit -m "'.input('Enter message: ').'"'<cr> ``` The only parts of your script that would do anything useful is the first line and the `nmap` line. The rest of it would either do nothing or not run at all. Since you're starting to learn VimL, her...
11,394
<p>I'm trying to autoload <code>.vimrc</code> if I'm not saving it to <code>.tmp/.vimrc</code> like so:</p> <pre><code>autocmd BufWritePost !*.tmp\/\.vimrc source % </code></pre> <p>It doesn't work, though.</p>
[ { "answer_id": 11397, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 3, "selected": true, "text": "<p>Not sure if you can negate a pattern. Take a look at <code>:h {pat}</code>. Also, if you negate such pattern (if it's ev...
2017/02/14
[ "https://vi.stackexchange.com/questions/11394", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I'm trying to autoload `.vimrc` if I'm not saving it to `.tmp/.vimrc` like so: ``` autocmd BufWritePost !*.tmp\/\.vimrc source % ``` It doesn't work, though.
Not sure if you can negate a pattern. Take a look at `:h {pat}`. Also, if you negate such pattern (if it's even possible), it will also match for `/path/to/a/file/foo.bar` or `/anything/you/would/think/of/bar.baz`. If you want to source only the `$HOME/.vimrc` when written, then you can specify full path like `/home/<U...
11,399
<p>I was editing the resume in latex I had downloaded from <a href="http://www.latextemplates.com/template/awesome-resume-cv" rel="nofollow noreferrer">here.</a></p> <p>Vim is most erratic when it comes to checking spelling. In the resume_cv.tex file, the spell checking works. When I open any of the linked files by op...
[ { "answer_id": 11397, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 3, "selected": true, "text": "<p>Not sure if you can negate a pattern. Take a look at <code>:h {pat}</code>. Also, if you negate such pattern (if it's ev...
2017/02/14
[ "https://vi.stackexchange.com/questions/11399", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3095/" ]
I was editing the resume in latex I had downloaded from [here.](http://www.latextemplates.com/template/awesome-resume-cv) Vim is most erratic when it comes to checking spelling. In the resume\_cv.tex file, the spell checking works. When I open any of the linked files by opening them (using `Ctrl-W`+`gf` command), cv-s...
Not sure if you can negate a pattern. Take a look at `:h {pat}`. Also, if you negate such pattern (if it's even possible), it will also match for `/path/to/a/file/foo.bar` or `/anything/you/would/think/of/bar.baz`. If you want to source only the `$HOME/.vimrc` when written, then you can specify full path like `/home/<U...
11,402
<p>I've toying with someone else's <code>.vimrc</code> file. I'm getting an error on a function call within the <code>.vimrc</code> file.</p> <pre><code>Error detected while processing &lt;FILE&gt;: line 1500: E492: Not an editor command: EQAS_Align('\S:', '', '\s') line 1501: E492: Not an editor command: EQ...
[ { "answer_id": 11404, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 4, "selected": true, "text": "<p>It seems that the following 2 lines:</p>\n\n<pre><code>EQAS_Align('\\S:', '', '\\s')\nEQAS_Align('[[:punct...
2017/02/14
[ "https://vi.stackexchange.com/questions/11402", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I've toying with someone else's `.vimrc` file. I'm getting an error on a function call within the `.vimrc` file. ``` Error detected while processing <FILE>: line 1500: E492: Not an editor command: EQAS_Align('\S:', '', '\s') line 1501: E492: Not an editor command: EQAS_Align('[[:punct:]]', '', '\s') ``` ...
It seems that the following 2 lines: ``` EQAS_Align('\S:', '', '\s') EQAS_Align('[[:punct:]]', '', '\s') ``` ... refer to a custom function named `EQAS_Align()`. It depends on what you want to do with it, but if you want its code to be processed, you have to prefix its name with the `:call` command: ``...
11,411
<p>I'm wanting to learn Vim, but think it's probably too daunting. I imagine learning enough to become powerful with it, then forgetting 99% after I'm on a computerless project for a while. I know just enough right now to open a file and get stuck, or make a huge mess and exit. If there is an autocomplete feature for...
[ { "answer_id": 11424, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 5, "selected": true, "text": "<p>I really don't think that having autocompletion or not will help you learning how to use Vim. Your main problem in my opi...
2017/02/14
[ "https://vi.stackexchange.com/questions/11411", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2466/" ]
I'm wanting to learn Vim, but think it's probably too daunting. I imagine learning enough to become powerful with it, then forgetting 99% after I'm on a computerless project for a while. I know just enough right now to open a file and get stuck, or make a huge mess and exit. If there is an autocomplete feature for comm...
I really don't think that having autocompletion or not will help you learning how to use Vim. Your main problem in my opinion is to learn the basics of the editor and then learn more and more commands. Anyway Vim has a built-in auto completion feature for the command line it is controlled with the `wildmenu` and `wild...
11,417
<p>I have taken the <code>.vimrc</code> from another guy. However, is <code>Leader</code> character is now <code>,</code>, and I am no longer able to modify it</p> <p><code>let mapleader = ","</code></p> <p>I'm trying to change it for the default leader with <code>let mapleader = "\"</code>, but it didn't work. Could...
[ { "answer_id": 11424, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 5, "selected": true, "text": "<p>I really don't think that having autocompletion or not will help you learning how to use Vim. Your main problem in my opi...
2017/02/15
[ "https://vi.stackexchange.com/questions/11417", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I have taken the `.vimrc` from another guy. However, is `Leader` character is now `,`, and I am no longer able to modify it `let mapleader = ","` I'm trying to change it for the default leader with `let mapleader = "\"`, but it didn't work. Could anyone be able to tell me how to obtain the default mapping?
I really don't think that having autocompletion or not will help you learning how to use Vim. Your main problem in my opinion is to learn the basics of the editor and then learn more and more commands. Anyway Vim has a built-in auto completion feature for the command line it is controlled with the `wildmenu` and `wild...
11,421
<p>I want all redundant whitespaces to be removed on write/save. How can I do that? By redundant I mean ones that exists after the last character or if there's an empty line and it contains a few whitespaces.</p>
[ { "answer_id": 11422, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>Probably something like that should work:</p>\n\n<pre><code>autocmd BufWritePre * :%s/\\s\\+$//\n</code></pre>\n\n<p>The...
2017/02/15
[ "https://vi.stackexchange.com/questions/11421", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11354/" ]
I want all redundant whitespaces to be removed on write/save. How can I do that? By redundant I mean ones that exists after the last character or if there's an empty line and it contains a few whitespaces.
Probably something like that should work: ``` autocmd BufWritePre * :%s/\s\+$// ``` The autocommand triggers `:%s/\s\+$//` each time a buffer will be written. And the substitution command removes all of the whitespaces at the end of lines.
11,426
<p>I like how nerdtree looks as a side-drawer.</p> <p><a href="https://i.stack.imgur.com/V0HTT.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/V0HTT.jpg" alt="enter image description here"></a> but if I close current buffer using <code>:bd</code></p> <p>nerdtree will become a fullscreen buffer</p> <p><a hr...
[ { "answer_id": 16032, "author": "dccsillag", "author_id": 1806, "author_profile": "https://vi.stackexchange.com/users/1806", "pm_score": 1, "selected": false, "text": "<p>With focus on <code>NERDTree</code>, type <code>A</code>. Then open some file from <code>NERDTree</code> and it will ...
2017/02/15
[ "https://vi.stackexchange.com/questions/11426", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I like how nerdtree looks as a side-drawer. [![enter image description here](https://i.stack.imgur.com/V0HTT.jpg)](https://i.stack.imgur.com/V0HTT.jpg) but if I close current buffer using `:bd` nerdtree will become a fullscreen buffer [![enter image description here](https://i.stack.imgur.com/8g51z.png)](https://i.s...
Some related posts are posted [here](https://github.com/scrooloose/nerdtree/issues/400) and [here](https://github.com/vim-airline/vim-airline/issues/460). Basically if you use `bd`, vim will close the window the current buffer is in, causing Nerdtree window to take the whole screen. The simple mapping below prevent the...
11,431
<p>I have two files written in php, both with a bunch of functions. I need to compare these function names with the other file, so I'm trying to get a list of all lines that begin with <code>function</code>. Preferably I would like to have these lines copy to a register. Is there an easy way to do this?</p>
[ { "answer_id": 11433, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 4, "selected": true, "text": "<p>This can be done pretty easily with the <code>global</code> command. I would try this:</p>\n\n<pre><code>:let @a=''\n...
2017/02/15
[ "https://vi.stackexchange.com/questions/11431", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11372/" ]
I have two files written in php, both with a bunch of functions. I need to compare these function names with the other file, so I'm trying to get a list of all lines that begin with `function`. Preferably I would like to have these lines copy to a register. Is there an easy way to do this?
This can be done pretty easily with the `global` command. I would try this: ``` :let @a='' :g/^function/y A ``` First we must call `:let @a=''` to make sure that the 'a' register is empty. Then, the global command is used to apply a command to every line matching a certain regex. In this case, the regex is `^functi...
11,432
<p>The old three lines:</p> <pre><code>able bee must </code></pre> <p>I want to change them to this in vim:</p> <pre><code>able /home/words/a/able bee /home/words/b/bee must /home/words/m/must </code></pre> <p>I knew using <code>%s/^\(.*\)$/\1/home/wprds/\1</code> can add some characters, but how can I get the firs...
[ { "answer_id": 11435, "author": "user9433424", "author_id": 6960, "author_profile": "https://vi.stackexchange.com/users/6960", "pm_score": 4, "selected": true, "text": "<p>I'm not sure this is exactly what you ask for, but assuming you wanted to replace:</p>\n\n<pre><code>able\nbee\nmust...
2017/02/15
[ "https://vi.stackexchange.com/questions/11432", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11373/" ]
The old three lines: ``` able bee must ``` I want to change them to this in vim: ``` able /home/words/a/able bee /home/words/b/bee must /home/words/m/must ``` I knew using `%s/^\(.*\)$/\1/home/wprds/\1` can add some characters, but how can I get the first letter of each substitution? Sorry for my poor English.
I'm not sure this is exactly what you ask for, but assuming you wanted to replace: ``` able bee must ``` … with: ``` able /home/words/a/able bee /home/words/b/bee must /home/words/m/must ``` Then, you could try the following substitution command: ``` :%s:\v(.).*:& /home/words/\1/& ``` Which could be broken dow...
11,445
<p>I want to write an <code>autocmd</code> <code>pat</code> that matches more than one file, eg:</p> <pre><code>" Source .vimrc after saving autocmd! BufWritePost ($MYVIMRC,$MYGVIMRC) nested source % | echom "Reloaded " . expand('%') | redraw </code></pre> <p><code>:help pat</code> doesn't give examples around the us...
[ { "answer_id": 11446, "author": "Kent", "author_id": 1569, "author_profile": "https://vi.stackexchange.com/users/1569", "pm_score": 3, "selected": true, "text": "<pre><code>autocmd! BufWritePost $MYVIMRC,$MYGVIMRC {cmd....}\n</code></pre>\n" }, { "answer_id": 11447, "author":...
2017/02/16
[ "https://vi.stackexchange.com/questions/11445", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5324/" ]
I want to write an `autocmd` `pat` that matches more than one file, eg: ``` " Source .vimrc after saving autocmd! BufWritePost ($MYVIMRC,$MYGVIMRC) nested source % | echom "Reloaded " . expand('%') | redraw ``` `:help pat` doesn't give examples around the usage of `(`, `{`, `|` and `,` How do I achieve the desired ...
``` autocmd! BufWritePost $MYVIMRC,$MYGVIMRC {cmd....} ```
11,455
<p>I'm in the browsing directory mode how can I change the current directory to that one I'm browsing? At least manually. But ":chdir ." doesn't work</p> <p>Moreover, in the config file I have "set autochdir" and it still doesn't change it always automatically</p>
[ { "answer_id": 11446, "author": "Kent", "author_id": 1569, "author_profile": "https://vi.stackexchange.com/users/1569", "pm_score": 3, "selected": true, "text": "<pre><code>autocmd! BufWritePost $MYVIMRC,$MYGVIMRC {cmd....}\n</code></pre>\n" }, { "answer_id": 11447, "author":...
2017/02/17
[ "https://vi.stackexchange.com/questions/11455", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11354/" ]
I'm in the browsing directory mode how can I change the current directory to that one I'm browsing? At least manually. But ":chdir ." doesn't work Moreover, in the config file I have "set autochdir" and it still doesn't change it always automatically
``` autocmd! BufWritePost $MYVIMRC,$MYGVIMRC {cmd....} ```
11,464
<p>There are a few commands to use folding (amongst all):</p> <pre><code>za When on a closed fold: open it. [...] When on an open fold: close it [...] zA When on a closed fold: open it recursively. When on an open fold: close it recursively [...] </code></pre> <p>However my "ideal" keystrok...
[ { "answer_id": 11465, "author": "Herb", "author_id": 5298, "author_profile": "https://vi.stackexchange.com/users/5298", "pm_score": 0, "selected": false, "text": "<p>You don't need to create a mapping, just use the <code>zc/zC</code> and <code>zo/zO</code> commands. </p>\n\n<p><code>zc</...
2017/02/18
[ "https://vi.stackexchange.com/questions/11464", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11416/" ]
There are a few commands to use folding (amongst all): ``` za When on a closed fold: open it. [...] When on an open fold: close it [...] zA When on a closed fold: open it recursively. When on an open fold: close it recursively [...] ``` However my "ideal" keystroke (which would be most com...
``` nnoremap <expr> <leader>z foldclosed('.') != -1 ? 'zO' : 'zc' ``` See `:h :map-<expr>`. On a fold, use `zO` to open it recursively, otherwise use `zc` to close one fold.
11,475
<p>I use vim for many different categories of projects, typically:</p> <ol> <li>Writing code (3 languages, python, Matlab and C)</li> <li>Writing documentation ( .rst, .html)</li> <li>Writing reports (.tex)</li> <li>Readme file (.md)</li> <li>As a plain text scratchpad (quick notes, meeting minutes etc.)</li> </ol> <...
[ { "answer_id": 11465, "author": "Herb", "author_id": 5298, "author_profile": "https://vi.stackexchange.com/users/5298", "pm_score": 0, "selected": false, "text": "<p>You don't need to create a mapping, just use the <code>zc/zC</code> and <code>zo/zO</code> commands. </p>\n\n<p><code>zc</...
2017/02/19
[ "https://vi.stackexchange.com/questions/11475", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8408/" ]
I use vim for many different categories of projects, typically: 1. Writing code (3 languages, python, Matlab and C) 2. Writing documentation ( .rst, .html) 3. Writing reports (.tex) 4. Readme file (.md) 5. As a plain text scratchpad (quick notes, meeting minutes etc.) While I understand why many experts here recommen...
``` nnoremap <expr> <leader>z foldclosed('.') != -1 ? 'zO' : 'zc' ``` See `:h :map-<expr>`. On a fold, use `zO` to open it recursively, otherwise use `zc` to close one fold.
11,476
<p>Consider the following line:</p> <pre><code>€ € </code></pre> <p>This file is encoded in UTF-8 and between the two Euro marks is a Tab character (the Stack Exchange software expands this to spaces). The byte value is:</p> <pre><code>e2 82 ac 09 e2 82 ac 0a </code></pre> <p>In my script I would like to get the ...
[ { "answer_id": 11480, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": true, "text": "<p>We discussed it less then 10 days ago <a href=\"https://www.reddit.com/r/vim/comments/5t08uo/vimscript_unicode/\" rel...
2017/02/19
[ "https://vi.stackexchange.com/questions/11476", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/51/" ]
Consider the following line: ``` € € ``` This file is encoded in UTF-8 and between the two Euro marks is a Tab character (the Stack Exchange software expands this to spaces). The byte value is: ``` e2 82 ac 09 e2 82 ac 0a ``` In my script I would like to get the character under the cursor. Vim has several usef...
We discussed it less then 10 days ago [on reddit](https://www.reddit.com/r/vim/comments/5t08uo/vimscript_unicode/). One solution is `matchstr(getline('.'), '\%'.col('.').'c.')` which doesn't mess with any register. I've put the [resulting functions](https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/en...
11,483
<p>If I open a random file (in this case, say <code>.zshrc</code>) in a blank vim with no rc file , but with vi compatibility forcing off</p> <pre><code>vim -N -u NORC ~/.zshrc </code></pre> <p>As expected vim will launch and display <code>.zshrc</code> without syntax highlighting.</p> <h3>attempt to enable syntax h...
[ { "answer_id": 11485, "author": "the_velour_fog", "author_id": 4603, "author_profile": "https://vi.stackexchange.com/users/4603", "pm_score": 1, "selected": false, "text": "<p>It turns out it was the tmux terminal detection - obviously beingis fundamental to everything else it seems the ...
2017/02/20
[ "https://vi.stackexchange.com/questions/11483", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
If I open a random file (in this case, say `.zshrc`) in a blank vim with no rc file , but with vi compatibility forcing off ``` vim -N -u NORC ~/.zshrc ``` As expected vim will launch and display `.zshrc` without syntax highlighting. ### attempt to enable syntax highlighting I have a file containing a collection o...
Adding `t_Co=256` to your vimrc should never be necessarily, save for some highly unusual and archaic situations. It's typically a sign that something else is set up wrong. By far the most common problem is a wrong `TERM` environment variable. You mentioned `tmux`, try using `screen-256color`, which should be the corr...
11,526
<p>I want to install a vim plugin, this plugin needs a <code>+python</code> feature, so when I open vim and type <code>:version</code> it displays <code>-python</code>. How can I make it enable?. </p> <p>Thanks.</p>
[ { "answer_id": 11527, "author": "akshay", "author_id": 246, "author_profile": "https://vi.stackexchange.com/users/246", "pm_score": 6, "selected": true, "text": "<p>You need to compile Vim yourself or get a prebuilt Vim package that was compiled with Python support. </p>\n\n<p>If you're ...
2017/02/24
[ "https://vi.stackexchange.com/questions/11526", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11437/" ]
I want to install a vim plugin, this plugin needs a `+python` feature, so when I open vim and type `:version` it displays `-python`. How can I make it enable?. Thanks.
You need to compile Vim yourself or get a prebuilt Vim package that was compiled with Python support. If you're on a Debian based system, the easiest way is to download the vim-gnome or vim-gtk package from `apt` (`apt install vim-gtk` for instance). Other distros might have a similar package with python support buil...
11,550
<p>I take part in some programming projects. I use <code>vim</code> to code for these projects. For each project I need a corresponding <code>.vimrc</code> with appropriate plugins set and customization. I can use custom <code>.vimrc</code> with command line options <code>-u</code>:</p> <pre><code>$ vim -u /home/loom...
[ { "answer_id": 11555, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>I read two problems expressed in your question.</p>\n\n<ol>\n<li>depending on the project you could activate differe...
2017/02/26
[ "https://vi.stackexchange.com/questions/11550", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11516/" ]
I take part in some programming projects. I use `vim` to code for these projects. For each project I need a corresponding `.vimrc` with appropriate plugins set and customization. I can use custom `.vimrc` with command line options `-u`: ``` $ vim -u /home/loom/.vimrc.custom ``` However, I share `~/.vim/` directory ...
So, I decided to have original `~/.vim/` directory empty and to create special `.vimrc.XXX` and `.vim.XXX/` for each project. For example ``` /home/loom/ ├── .vims/ │ ├── .vim.foo/ │ └── .vim.bar/ ├── .vimrc.foo └── .vimrc.bar ``` First lines of original `.vimrc` looks like ``` set nocompat...
11,560
<p>Copying this question over from <a href="https://stackoverflow.com/q/42474604/262108I">https://stackoverflow.com/q/42474604/262108I</a> recently started working with django templates and was wondering whether there are any autocompletion plugins for template directives like <code>{% block|if|... %}</code>etc that <s...
[ { "answer_id": 11563, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 3, "selected": true, "text": "<p>The principle:</p>\n\n<ul>\n<li>listen for <code>}</code>, not <code>%}</code></li>\n<li>analyse the context to decid...
2017/02/27
[ "https://vi.stackexchange.com/questions/11560", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11553/" ]
Copying this question over from <https://stackoverflow.com/q/42474604/262108I> recently started working with django templates and was wondering whether there are any autocompletion plugins for template directives like `{% block|if|... %}`etc that ***do not*** involve a snippets library. I specifically do not want a sn...
The principle: * listen for `}`, not `%}` * analyse the context to decide what to return from a [`:h :map-<expr>`](http://vimhelp.appspot.com/map.txt.html#%3amap%2d%3cexpr%3e) * the mapping shall be buffer local in order to avoid side-effects with other filetypes ([`:h :map-<buffer>`](http://vimhelp.appspot.com/map.tx...
11,578
<p>I've tried every tip I can find on this and none of them work. I've cleared my <code>.vimrc</code> file. I have a syntax script in <code>./vim/syntax/test.vim.</code> It consists of nothing but this:</p> <pre><code>highlight clear syn keyword syntaxElementKeyword ok hi def link syntaxElementKeyword Todo </code></pr...
[ { "answer_id": 11580, "author": "StevieD", "author_id": 2021, "author_profile": "https://vi.stackexchange.com/users/2021", "pm_score": 2, "selected": false, "text": "<p>Changing my test file to something like this:</p>\n\n<pre><code>syntax keyword Foo Foo \nhighlight Foo cterm=underline\...
2017/02/28
[ "https://vi.stackexchange.com/questions/11578", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I've tried every tip I can find on this and none of them work. I've cleared my `.vimrc` file. I have a syntax script in `./vim/syntax/test.vim.` It consists of nothing but this: ``` highlight clear syn keyword syntaxElementKeyword ok hi def link syntaxElementKeyword Todo ``` When I first load a file with my text and...
> > It consists of nothing but this: > > > > ``` > highlight clear > syn keyword syntaxElementKeyword ok > hi def link syntaxElementKeyword Todo > > ``` > > `highlight clear` will remove all the highlight groups, but not the syntax groups. They belong to 2 related but still different mechanisms. Their purpose i...
11,581
<p>In several terminal programs, such as <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/)" rel="noreferrer">PuTTY</a>, <a href="https://www.vandyke.com/products/securecrt/" rel="noreferrer">SecureCRT</a>, <a href="http://iterm.sourceforge.net/" rel="noreferrer">iTerm</a>, and Mac OS Terminal, if I have NumL...
[ { "answer_id": 11582, "author": "Jacktose", "author_id": 9267, "author_profile": "https://vi.stackexchange.com/users/9267", "pm_score": 6, "selected": true, "text": "<h3>Short answer</h3>\n\n<p>Turn off “application keypad mode switching.”</p>\n\n<h3>Terminal-specific instructions</h3>\n...
2017/02/28
[ "https://vi.stackexchange.com/questions/11581", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9267/" ]
In several terminal programs, such as [PuTTY](http://www.chiark.greenend.org.uk/~sgtatham/putty/)), [SecureCRT](https://www.vandyke.com/products/securecrt/), [iTerm](http://iterm.sourceforge.net/), and Mac OS Terminal, if I have NumLock on and I press the number pad (numpad) keys `0123456789` in insert mode, my vim loo...
### Short answer Turn off “application keypad mode switching.” ### Terminal-specific instructions * [PuTTY](http://vim.wikia.com/wiki/PuTTY_numeric_keypad_mappings#Using_the_numeric_keypad)) (also [here](https://stackoverflow.com/a/7284745/1144854)): `Terminal > Features > uncheck Disable application keypad mode` * ...
11,586
<p>I know <code>User1</code>... <code>User9</code> colors the status line. I have applied several colors to the statusline to make it easy to recognize, but I wish this is only applied to active panes, not inactive panes. So that inactive panes has monocolor statusline, and is not too distracting. I suppose this is pos...
[ { "answer_id": 11600, "author": "laktak", "author_id": 10337, "author_profile": "https://vi.stackexchange.com/users/10337", "pm_score": 2, "selected": true, "text": "<p>Unless I misunderstand the issue you should just use User1-5 for the active and the 6-9 for the inactive one.</p>\n\n<p...
2017/03/01
[ "https://vi.stackexchange.com/questions/11586", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10241/" ]
I know `User1`... `User9` colors the status line. I have applied several colors to the statusline to make it easy to recognize, but I wish this is only applied to active panes, not inactive panes. So that inactive panes has monocolor statusline, and is not too distracting. I suppose this is possible if there are two se...
Unless I misunderstand the issue you should just use User1-5 for the active and the 6-9 for the inactive one. For example I use the following in my update function (not complete but you should get the idea): ``` " active let s:a_statusline='%1* %<%f ' " ... etc. " inactive let s:na_statusline='%6* %<%f ' " ... etc. ...
11,589
<p>I'd like <code>vimdiff</code> to start with <em>all</em> the folded sections opened.</p> <p>So far I have tried the following:</p> <pre><code>vimdiff -c "set nofoldenable" -R &lt;(tree -d directory1) &lt;(tree -d directory2) </code></pre> <p>with the <code>-c "set nofoldenable"</code> being the attempt to achieve...
[ { "answer_id": 11600, "author": "laktak", "author_id": 10337, "author_profile": "https://vi.stackexchange.com/users/10337", "pm_score": 2, "selected": true, "text": "<p>Unless I misunderstand the issue you should just use User1-5 for the active and the 6-9 for the inactive one.</p>\n\n<p...
2017/03/01
[ "https://vi.stackexchange.com/questions/11589", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1109/" ]
I'd like `vimdiff` to start with *all* the folded sections opened. So far I have tried the following: ``` vimdiff -c "set nofoldenable" -R <(tree -d directory1) <(tree -d directory2) ``` with the `-c "set nofoldenable"` being the attempt to achieve what I want. However, that doesn't work, because it only affects th...
Unless I misunderstand the issue you should just use User1-5 for the active and the 6-9 for the inactive one. For example I use the following in my update function (not complete but you should get the idea): ``` " active let s:a_statusline='%1* %<%f ' " ... etc. " inactive let s:na_statusline='%6* %<%f ' " ... etc. ...
11,597
<p>What is the syntax for inserting a comment or comments into the vimrc file?</p> <p>Having trouble finding this on <a href="http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc" rel="noreferrer">vim documentation online</a>.</p>
[ { "answer_id": 11598, "author": "xaizek", "author_id": 860, "author_profile": "https://vi.stackexchange.com/users/860", "pm_score": 5, "selected": true, "text": "<p>It's in a different help file (<a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:comment\" rel=\"noreferrer\">c...
2017/03/01
[ "https://vi.stackexchange.com/questions/11597", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8496/" ]
What is the syntax for inserting a comment or comments into the vimrc file? Having trouble finding this on [vim documentation online](http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc).
It's in a different help file ([cmdline](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:comment), [help :comment](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:comment)): ``` *:quote* *:comment* '"' at the start of a line causes the whole line to be ignored. '"' after a command ...
11,601
<p>I am trying to rewrite adding a string to option with variable. The original string is</p> <pre><code>set rtp+=~/.vim/bundle/Vundle.vim </code></pre> <p>The following is the working <code>let</code> way:</p> <pre><code>let MYVIMDIR='/home/loom/foo' let &amp;rtp .= ','.expand(MYVIMDIR).'/bundle/Vundle.vim' </code>...
[ { "answer_id": 11603, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": false, "text": "<p>You could use <code>:exe</code>, but this is extremely cumbersome to use and you'll need to escape a few things. </p...
2017/03/01
[ "https://vi.stackexchange.com/questions/11601", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11516/" ]
I am trying to rewrite adding a string to option with variable. The original string is ``` set rtp+=~/.vim/bundle/Vundle.vim ``` The following is the working `let` way: ``` let MYVIMDIR='/home/loom/foo' let &rtp .= ','.expand(MYVIMDIR).'/bundle/Vundle.vim' ``` I am interested how rewrite it with `set`. The follow...
You could use `:exe`, but this is extremely cumbersome to use and you'll need to escape a few things. I used to use my own path fixing function. It looked like: ``` exe 'set rtp+='.lh#path#fix(somevariable) " with standard tools, may be it'd be (untested) exe 'set rtp+='.escape(somevariable, ' \|,') ``` `let &rtp ...
11,602
<p>I've turned on vim's relative line numbers, it starts from 0 but doing somthing like <code>10dd</code> means I only get up to line 9, leaving the last one behind (becuase it's 10 including the current line). Yes, I know, It's only a super simple equation (10 + 1) but it's time taken up when I just want to check the ...
[ { "answer_id": 11603, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": false, "text": "<p>You could use <code>:exe</code>, but this is extremely cumbersome to use and you'll need to escape a few things. </p...
2017/03/01
[ "https://vi.stackexchange.com/questions/11602", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11603/" ]
I've turned on vim's relative line numbers, it starts from 0 but doing somthing like `10dd` means I only get up to line 9, leaving the last one behind (becuase it's 10 including the current line). Yes, I know, It's only a super simple equation (10 + 1) but it's time taken up when I just want to check the number in the ...
You could use `:exe`, but this is extremely cumbersome to use and you'll need to escape a few things. I used to use my own path fixing function. It looked like: ``` exe 'set rtp+='.lh#path#fix(somevariable) " with standard tools, may be it'd be (untested) exe 'set rtp+='.escape(somevariable, ' \|,') ``` `let &rtp ...
11,609
<p>Very often, I write markdown in VIM, and there will be paragraphs in those markdown. To help my editing, I setup my Vim to wrap a line on 80 chars. It works nice if I just keep typing, but the problem is if I need to do some correction, it becomes very annoying. </p> <p>demo(taken from wikipedia first order logic):...
[ { "answer_id": 11610, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 1, "selected": false, "text": "<p>I would have a look at <a href=\"http://vimhelp.appspot.com/options.txt.html#%27textwidth%27\" rel=\"nofollow norefer...
2017/03/02
[ "https://vi.stackexchange.com/questions/11609", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1097/" ]
Very often, I write markdown in VIM, and there will be paragraphs in those markdown. To help my editing, I setup my Vim to wrap a line on 80 chars. It works nice if I just keep typing, but the problem is if I need to do some correction, it becomes very annoying. demo(taken from wikipedia first order logic): ``` The ...
Even simpler: the `a` flag for `'formatoptions'` enables automatic formatting of paragraphs whenever text is inserted or deleted. See [`:help fo-table`](http://vimhelp.appspot.com/change.txt.html#fo-table) for details on `'formatoptions'` flags and [`:help autoformat`](http://vimhelp.appspot.com/change.txt.html#autofor...
11,626
<p>Is there something similar in Vim? </p> <p><a href="https://packagecontrol.io/packages/InstaGoogling" rel="nofollow noreferrer">https://packagecontrol.io/packages/InstaGoogling</a></p> <p>Thanks in advance!</p>
[ { "answer_id": 11640, "author": "laktak", "author_id": 10337, "author_profile": "https://vi.stackexchange.com/users/10337", "pm_score": 1, "selected": false, "text": "<p>Install <a href=\"https://github.com/tyru/open-browser.vim\" rel=\"nofollow noreferrer\">'tyru/open-browser.vim'</a></...
2017/03/03
[ "https://vi.stackexchange.com/questions/11626", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
Is there something similar in Vim? <https://packagecontrol.io/packages/InstaGoogling> Thanks in advance!
To complement @laktak's answer, the author of the 'tyru/open-browser' plugin recommends the following maps: ``` nmap gx <Plug>(openbrowser-smart-search) vmap gx <Plug>(openbrowser-smart-search) ``` @laktak's suggestion of mapping `<F1>` works, but why use a function key when you can keep your fingers on home row? :)...
11,629
<p>I'm trying to understand and eventually fix the following behavior: when I save a file using VIM, it triggers the <code>change</code>/<code>write</code> event twice.</p> <p>I'm using Ubuntu 16.10, and I created an empty <code>.vimrc</code> file to make sure that no plugins create this behavior.</p> <p>So, I open t...
[ { "answer_id": 11649, "author": "laktak", "author_id": 10337, "author_profile": "https://vi.stackexchange.com/users/10337", "pm_score": 2, "selected": false, "text": "<p>If you have <code>backupcopy=no</code> Vim will try to rename the file. If this fails it will work the same way as <co...
2017/03/03
[ "https://vi.stackexchange.com/questions/11629", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/449/" ]
I'm trying to understand and eventually fix the following behavior: when I save a file using VIM, it triggers the `change`/`write` event twice. I'm using Ubuntu 16.10, and I created an empty `.vimrc` file to make sure that no plugins create this behavior. So, I open the `foo.txt` file: ``` vim -u .vimrc foo.txt ```...
If you have `backupcopy=no` Vim will try to rename the file. If this fails it will work the same way as `backupcopy=yes`. For example (with `strace`): ``` rename("test.txt", "/tmp/test.txt~") = -1 EXDEV (Invalid cross-device link) ``` But in any case, Vim will only write to the file once: ``` set backupcopy=no re...
11,638
<p>I want to have multiple lines of text appear in one cell (one row and one column). </p> <p>In Vimwiki it looks adequate. However, when I convert Vimwiki to HTML, each sentence gets its own row. So I know I am not getting it right, but I have not yet been able to figure out what I am missing.</p> <h1>MWE</h1> <...
[ { "answer_id": 11639, "author": "laktak", "author_id": 10337, "author_profile": "https://vi.stackexchange.com/users/10337", "pm_score": 2, "selected": false, "text": "<p>The vimwiki syntax does not support what you want.</p>\n\n<p>When you use <code>&gt;</code> or <code>\\/</code> you ar...
2017/03/03
[ "https://vi.stackexchange.com/questions/11638", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6590/" ]
I want to have multiple lines of text appear in one cell (one row and one column). In Vimwiki it looks adequate. However, when I convert Vimwiki to HTML, each sentence gets its own row. So I know I am not getting it right, but I have not yet been able to figure out what I am missing. MWE === This vimwiki text ``` ...
I added the functionality I wanted to vimwiki and [submitted a pull request](https://github.com/vimwiki/vimwiki/pull/331) to get it incorporated into the main body of code. In the process of doing this, I realized I can accomplish my larger goal using `blockquote` and CSS that vimwiki also currently provides.