qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
8,835
<p>Let's say I'm in the shell (<code>bash</code>) and want to see output that <code>:scriptnames</code> would give, but don't want to start vim or maybe I want to echo that into another file.</p> <p>So I execute</p> <pre><code>vim +scriptnames </code></pre> <p>Which shows me all the scripts, but how do I echo that i...
[ { "answer_id": 8836, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>That happens, because usually Vim switches to the alternate screen and works there. Upon exiting, Vim will switch ...
2016/07/17
[ "https://vi.stackexchange.com/questions/8835", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6300/" ]
Let's say I'm in the shell (`bash`) and want to see output that `:scriptnames` would give, but don't want to start vim or maybe I want to echo that into another file. So I execute ``` vim +scriptnames ``` Which shows me all the scripts, but how do I echo that into the shell's stdout?
That happens, because usually Vim switches to the alternate screen and works there. Upon exiting, Vim will switch back and therefore you don't see anything left from your Vim session, but the result of the command executed even before starting Vim. This feature is explained at `:h xterm-screens` [(link)](https://vimh...
8,855
<p>I am trying to change the default grep call to avoid unnecessary plugin installation. What I want from vim is to call the external search using the builtin command :grep with custom arguments, this is what I've tried putting in my rc:</p> <pre><code>set wildignore=*.o,*.obj,*~,*.pyc,.git/**,tags,cscope* let &amp;gre...
[ { "answer_id": 8858, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 5, "selected": true, "text": "<p>If any of the <a href=\"https://unix.stackexchange.com/questions/131032/globbing-fails-in-zsh-but-works-in-bash\">glo...
2016/07/19
[ "https://vi.stackexchange.com/questions/8855", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2561/" ]
I am trying to change the default grep call to avoid unnecessary plugin installation. What I want from vim is to call the external search using the builtin command :grep with custom arguments, this is what I've tried putting in my rc: ``` set wildignore=*.o,*.obj,*~,*.pyc,.git/**,tags,cscope* let &grepprg='grep -n -R ...
If any of the [globs has no match](https://unix.stackexchange.com/questions/131032/globbing-fails-in-zsh-but-works-in-bash), in zsh, the command will be aborted. This means you need to [escape your globs](https://stackoverflow.com/questions/221921/use-grep-exclude-include-syntax-to-not-grep-through-certain-files). I s...
8,866
<p>When I'm trying to increase numbers with <kbd>Ctrl</kbd><kbd>A</kbd> it removes the leading and the trailing zeros.</p> <p>For example:</p> <pre><code>1.009500 1.09500 1.0009500 </code></pre> <p>Results after pressing <kbd>Ctrl</kbd><kbd>A</kbd>:</p> <pre><code>1.009500 -&gt; 1.9501 1.09500 -&gt; 1.9501 1.0...
[ { "answer_id": 8867, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>Thanks to @statox's suggestion, you can solve your issue with:</p>\n\n<pre><code>:set nrformats-=octal\n</code></pre>\n\n<h...
2016/07/20
[ "https://vi.stackexchange.com/questions/8866", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3302/" ]
When I'm trying to increase numbers with `Ctrl``A` it removes the leading and the trailing zeros. For example: ``` 1.009500 1.09500 1.0009500 ``` Results after pressing `Ctrl``A`: ``` 1.009500 -> 1.9501 1.09500 -> 1.9501 1.0009500 -> 1.9501 ``` or if cursor in front of the `.` ``` 1.009500 -> 2.009500 1...
Thanks to @statox's suggestion, you can solve your issue with: ``` :set nrformats-=octal ``` --- Firstly, Vim does not increment decimal number, it will try to increment `1` and `009500` separately. So the question is why incrementing `009500` removes the leading `0`. As suggested by @sp asic, I think vim is trea...
8,870
<p>I tried doing the following command on a new install of Ubuntu and got a "Sorry, command not supported on this version message":</p> <pre><code>:echo @% </code></pre> <p>How could any version of vim not support echo? The reported version is 7.4 Small version without GUI.</p>
[ { "answer_id": 8871, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 3, "selected": true, "text": "<p>Ubuntu comes packaged with a tiny version of vim. It is nearly vi. To install the <em>real</em> version of vim, run</p...
2016/07/20
[ "https://vi.stackexchange.com/questions/8870", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6952/" ]
I tried doing the following command on a new install of Ubuntu and got a "Sorry, command not supported on this version message": ``` :echo @% ``` How could any version of vim not support echo? The reported version is 7.4 Small version without GUI.
Ubuntu comes packaged with a tiny version of vim. It is nearly vi. To install the *real* version of vim, run ``` sudo apt-get install vim ``` Personally, I prefer: ``` sudo apt-get install vim-gnome ``` since this comes with things like python and clipboard support, and gvim, but installing the default vim versio...
8,884
<p>Assume we have this text:</p> <pre><code>baaa </code></pre> <p><code>matchaddpos("Error", [[1,2]])</code> highlights the second character (the first 'a') as "Error" group.</p> <pre><code>baaa ^ highlighted </code></pre> <p>When I insert a 'b' at the beginning, it becomes</p> <pre><code>bbaaa ^ highlighted </c...
[ { "answer_id": 8885, "author": "Sato Katsura", "author_id": 2313, "author_profile": "https://vi.stackexchange.com/users/2313", "pm_score": 3, "selected": false, "text": "<p>You can't do that with <code>matchadpos()</code>. This is a known problem with Vim highlighting, and it isn't like...
2016/07/21
[ "https://vi.stackexchange.com/questions/8884", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8499/" ]
Assume we have this text: ``` baaa ``` `matchaddpos("Error", [[1,2]])` highlights the second character (the first 'a') as "Error" group. ``` baaa ^ highlighted ``` When I insert a 'b' at the beginning, it becomes ``` bbaaa ^ highlighted ``` It looks like the color is stick to the "grid" instead of the charac...
In vim, it is now possible since [patch 8.1.0579](https://github.com/vim/vim/commit/98aefe7c3250bb5d4153b994f878594d1745424e#diff-90dd8c04113fca83dfa90e38f053465e) using text properties (`:help textprop`). As the name suggests, a text property is a property that can be associated to text, and moves with it. Properties...
8,895
<p>Can I set something like <code>ctrl+s</code> to save the file? </p> <p>I don't want to use <code>:w</code> every time.</p>
[ { "answer_id": 8896, "author": "Herb", "author_id": 5298, "author_profile": "https://vi.stackexchange.com/users/5298", "pm_score": 2, "selected": false, "text": "<p>Yes, that's actually set up in the mswin.vim file that distributed with Vim 6.2 and above for windows.</p>\n\n<p>It contain...
2016/07/22
[ "https://vi.stackexchange.com/questions/8895", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8500/" ]
Can I set something like `ctrl+s` to save the file? I don't want to use `:w` every time.
First of all stop using `:w` to save. Use `:update` instead. `:update` writes the file to disk only when there are changes. So, it could be really helpful especially if the file is huge. Now to map `<C-S>` to `:update` here is how you do it ``` nnoremap <C-S> :update<cr> ``` You may also want to have this mapping i...
8,909
<p>Suppose I have the following table:</p> <pre><code>E 12.02 T 9.10 A 8.12 O 7.68 I 7.31 N 6.95 S 6.28 R 6.02 H 5.92 D 4.32 L 3.98 U 2.88 C 2.71 M 2.61 F 2.30 Y 2.11 W 2.09 G 2.03 P 1.82 B 1.49 V 1.11 K 0.69 X 0.17 Q 0.11 J 0.10 Z 0.07 </code></pre> <p>Values are s...
[ { "answer_id": 8911, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>If you want to do that in vim you can use the following macro:</p>\n\n<pre><code>qa^V3j$d\"_4dd^V3jI&lt;tab&gt;&lt;Esc&gt...
2016/07/22
[ "https://vi.stackexchange.com/questions/8909", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
Suppose I have the following table: ``` E 12.02 T 9.10 A 8.12 O 7.68 I 7.31 N 6.95 S 6.28 R 6.02 H 5.92 D 4.32 L 3.98 U 2.88 C 2.71 M 2.61 F 2.30 Y 2.11 W 2.09 G 2.03 P 1.82 B 1.49 V 1.11 K 0.69 X 0.17 Q 0.11 J 0.10 Z 0.07 ``` Values are separated by tabs. I want ...
Using the \*nix commands `split` and `paste` ``` $ split -l 4 ip.txt op ; paste op* > ip.txt ``` Or, from within vim as suggested by OP: ``` :!split -l 4 % /tmp/split; paste /tmp/split* > %; rm /tmp/split* ```
8,915
<p>I'm thinking about a feature which I think would improve my workflow a lot. I don't know if it already exists..</p> <p>The feature is about moving the cursor vertically over code blocks without losing its horizontal position in a speedy way. I would regard it as a more convenient alternative for <kbd>{</kbd> and <k...
[ { "answer_id": 8916, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 0, "selected": false, "text": "<p>You can start working from this simple mapping:</p>\n\n<pre><code>:nnoremap J :let c=col('.') &lt;bar&gt; execute \"normal...
2016/07/22
[ "https://vi.stackexchange.com/questions/8915", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6542/" ]
I'm thinking about a feature which I think would improve my workflow a lot. I don't know if it already exists.. The feature is about moving the cursor vertically over code blocks without losing its horizontal position in a speedy way. I would regard it as a more convenient alternative for `{` and `}`. Or you could say...
Here is a small function, that seems to do what you want: ``` function! Move(up) let curpos = getcurpos() let firstline='\(^\s*\n\)\zs\S\+' let lastline ='\S\+\ze\n\s*$' let flags = 'Wn'. (a:up ? 'b' : '') " Move to first or last line of paragraph, " or to the beginning/end of file let pat ...
8,919
<p>I'm aware of <a href="https://vi.stackexchange.com/questions/24/how-do-i-reload-my-vimrc-without-leaving-vim">this question</a>, but sourcing that way is not the same as restarting Vim. I want to do that without restarting Vim.</p> <p>Like, if you have <code>set fo+=c</code> in your <code>vimrc</code> then re-sour...
[ { "answer_id": 8921, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>That is no problem:</p>\n\n<blockquote>\n <p>:se[t] {option}+={value}</p>\n \n <p>Add the {value} to a number ...
2016/07/22
[ "https://vi.stackexchange.com/questions/8919", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2561/" ]
I'm aware of [this question](https://vi.stackexchange.com/questions/24/how-do-i-reload-my-vimrc-without-leaving-vim), but sourcing that way is not the same as restarting Vim. I want to do that without restarting Vim. Like, if you have `set fo+=c` in your `vimrc` then re-sourcing changes it to something like this: ```...
I have not tried it, and I would not be surprised if it has some unexpected side effects, but you could try to add ``` set all& ``` at the top of your `.vimrc` file. This will reset all options to their default setting, cf. [`:h :set-&`](http://vimdoc.sourceforge.net/htmldoc/options.html#:set-&). In particular, I a...
8,936
<p>I'm trying to write a plugin that highlights overused words.</p> <p>After much effort I managed to write a function (and a command, <code>:Ditto</code>) that will highlight the most used word in the file or in a specific range. So I can select a paragraph and call that function and the most frequent word in that pa...
[ { "answer_id": 8945, "author": "dbmrq", "author_id": 7642, "author_profile": "https://vi.stackexchange.com/users/7642", "pm_score": 2, "selected": false, "text": "<p>Ok, with some help from @Tumbler41 I arrived at this pattern:</p>\n\n<pre><code>\\(^\\n\\|\\%1l\\)\\s*\\S\\_.\\{-}\\n$\n</...
2016/07/25
[ "https://vi.stackexchange.com/questions/8936", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7642/" ]
I'm trying to write a plugin that highlights overused words. After much effort I managed to write a function (and a command, `:Ditto`) that will highlight the most used word in the file or in a specific range. So I can select a paragraph and call that function and the most frequent word in that paragraph will be highl...
With the following command (for testing): ``` com! -range MyCom <line1>,<line2> s/^/<line1>,<line2>: / ``` You can pass each paragraph in a buffer to `MyCom` with: ``` g/\v.(\n\n|\n*%$)/ '{,. MyCom ``` It searches for the last line of a paragraph, then uses from the previous paragraph mark to that point as the ra...
8,942
<p>When you execute the shell in <code>vim</code> via the <code>:sh</code> command, the shell that is set in the <code>shell</code> option is executed. However, is it possible to pass some information from the vim instance that you are running to the invoked shell?</p> <p>Of course that would be easily doable if you c...
[ { "answer_id": 8943, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>You can set or modify an environment variable in Vim like so:</p>\n\n<pre><code>:let $MY_ENV = 'coconuts!'\n</code></...
2016/07/25
[ "https://vi.stackexchange.com/questions/8942", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6300/" ]
When you execute the shell in `vim` via the `:sh` command, the shell that is set in the `shell` option is executed. However, is it possible to pass some information from the vim instance that you are running to the invoked shell? Of course that would be easily doable if you could alter the `shell` option to have some ...
You can set or modify an environment variable in Vim like so: ``` :let $MY_ENV = 'coconuts!' ``` Child processes inherit the parent process's environment, so this is available when you start a new shell process with `:sh` (which is a child of the vim process: ``` :sh $ echo $MY_ENV coconuts! ``` It also works wi...
8,948
<p>I'm trying to write a plugin to highlight overused words in a file. After <a href="https://vi.stackexchange.com/q/8936/7642">this question</a> I now have a way to highlight the most frequent words in each paragraph.</p> <p>To restrict the highlighting of a word to a single paragraph I'm using <code>matchadd</code> ...
[ { "answer_id": 8967, "author": "dbmrq", "author_id": 7642, "author_profile": "https://vi.stackexchange.com/users/7642", "pm_score": 0, "selected": false, "text": "<p>After looking into <code>:h autocmd-events</code> for a bit I came up with this:</p>\n\n<pre><code>let s:lastline = 0\n\nf...
2016/07/25
[ "https://vi.stackexchange.com/questions/8948", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7642/" ]
I'm trying to write a plugin to highlight overused words in a file. After [this question](https://vi.stackexchange.com/q/8936/7642) I now have a way to highlight the most frequent words in each paragraph. To restrict the highlighting of a word to a single paragraph I'm using `matchadd` with a line range: ``` matchadd...
I also have the same issue in my plugin, [diffchar.vim](http://www.vim.org/scripts/script.php?script_id=4932). This plugin highlights the exact diff units with matchadd/matchaddpos and tries to interactively update those highlights while editing. My approach is: * always record which lines are highlighted * get Text...
8,972
<p>I want to select a color scheme in gVim such that it's used always (i. e. if I select color scheme X, close gVim, and start it again, it should start with X as the color scheme, not the default one).</p> <p><a href="https://i.stack.imgur.com/30bY0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/30bY0.png"...
[ { "answer_id": 8975, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>In Vim, settings are saved across sessions by writing them in an init script called <code>vimrc</code>.</p>\n<p>On Windows, t...
2016/07/27
[ "https://vi.stackexchange.com/questions/8972", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8524/" ]
I want to select a color scheme in gVim such that it's used always (i. e. if I select color scheme X, close gVim, and start it again, it should start with X as the color scheme, not the default one). [![Screenshot](https://i.stack.imgur.com/30bY0.png)](https://i.stack.imgur.com/30bY0.png) How can I do it? Just sele...
In Vim, settings are saved across sessions by writing them in an init script called `vimrc`. On Windows, that `vimrc` is supposed to be at: ``` $HOME\_vimrc ``` or (if HOME is not defined): ``` C:\Users\yourlogin\_vimrc ``` On Unix at: ``` $HOME/.vimrc ``` The installer may or may not have created that file f...
8,976
<p>I'm using <a href="https://github.com/ctrlpvim/ctrlp.vim" rel="noreferrer">ctrlpvim/ctrlp.vim</a> to open files by fuzzy search.</p> <p>Is there a way to get the full path of the searched file and insert it under cursor, instead of opening it?</p>
[ { "answer_id": 8977, "author": "the_velour_fog", "author_id": 4603, "author_profile": "https://vi.stackexchange.com/users/4603", "pm_score": 2, "selected": false, "text": "<p>This is <s>really</s> hacky, but it worked for me, if you source this mapping</p>\n\n<pre><code>nnoremap &lt;Lead...
2016/07/27
[ "https://vi.stackexchange.com/questions/8976", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3302/" ]
I'm using [ctrlpvim/ctrlp.vim](https://github.com/ctrlpvim/ctrlp.vim) to open files by fuzzy search. Is there a way to get the full path of the searched file and insert it under cursor, instead of opening it?
You can customize the function handling the opening of files, as explained at `:help 'g:ctrlp_open_func'`. You could try something similar to this: ``` function! CtrlPOpenFunc(action, line) if a:action =~ '^h$' " Get the filename let filename = fnameescape(fnamemodify(a:line, ':p')) " Close C...
8,981
<p>If I purge my existing vim-full installation and install a GUI version like vim-gnome or vim-gtk, can I still use it in the text mode I am familiar with?</p> <p>What if I am using it from a terminal via SSH? How does the gui mode interact with a terminal-based user?</p> <p>I have seen the gui version of Vim referr...
[ { "answer_id": 8982, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 4, "selected": true, "text": "<p><strong>Yes.</strong></p>\n\n<p>Vim-gnome does install gvim, but it also installs a much more feature-filled version o...
2016/07/27
[ "https://vi.stackexchange.com/questions/8981", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6952/" ]
If I purge my existing vim-full installation and install a GUI version like vim-gnome or vim-gtk, can I still use it in the text mode I am familiar with? What if I am using it from a terminal via SSH? How does the gui mode interact with a terminal-based user? I have seen the gui version of Vim referred to as "gvim". ...
**Yes.** Vim-gnome does install gvim, but it also installs a much more feature-filled version of command line vim, including [Perl, Python, Ruby, and TCL scripting](https://askubuntu.com/a/281972/289381), system-clipboard, newer patches, etc. So not only can you continue to use command line vim, you will get a better...
8,984
<p>I just started using ycm with clang-completer, which apparently can also do syntax checking.</p> <p>It instantly reminded me why I avoided syntax checking in gVim: As soon as an error is found, the signs appear on the left in an extra column. By doing so they shift the window to the right to make place for the char...
[ { "answer_id": 8987, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 3, "selected": true, "text": "<p>You can do what some plugins do and create a dummy sign:</p>\n\n<pre><code>sign define Dummy\nautocmd VimEnter,SessionLoa...
2016/07/27
[ "https://vi.stackexchange.com/questions/8984", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8595/" ]
I just started using ycm with clang-completer, which apparently can also do syntax checking. It instantly reminded me why I avoided syntax checking in gVim: As soon as an error is found, the signs appear on the left in an extra column. By doing so they shift the window to the right to make place for the characters of ...
You can do what some plugins do and create a dummy sign: ``` sign define Dummy autocmd VimEnter,SessionLoadPost,BufRead * execute 'sign place 97349278 line=9999 name=Dummy buffer='.bufnr('%') ``` All this does is creates an empty sign on line `9999`, which should be far enough from valid lines in a file you actually...
8,993
<p><a href="https://github.com/lervag/vimtex/wiki/usage#default-mappings" rel="nofollow">vimtex</a> lists some commands like <code>ie</code> to be entered in mode <code>nxo</code>. How do I do that? What is mode <code>nxo</code>? (Usually <code>i</code> brings me into insert mode, and <code>e</code> then just inserts a...
[ { "answer_id": 8994, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 2, "selected": false, "text": "<p>N represents Normal mode and O represents operational mode and X represents Ex mode. Mappings can be done in normal, ...
2016/07/28
[ "https://vi.stackexchange.com/questions/8993", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8598/" ]
[vimtex](https://github.com/lervag/vimtex/wiki/usage#default-mappings) lists some commands like `ie` to be entered in mode `nxo`. How do I do that? What is mode `nxo`? (Usually `i` brings me into insert mode, and `e` then just inserts an `e`.)
In vimtex, the mappings like `ie` are actually vim text objects (not sure about the right vim nomenclature though). They work together with vim operators like `d` (delete). In particular `ie` stands for any tex environment like `equation`, `itemize`, .... For example, if you cursor is somewhere inside ``` \begin{equ...
9,001
<p>I would like to be able to search google from within any vim file. A nice command might be <code>:goo</code> while in normal mode. </p> <p>Then I type what I want to search and bam it opens my default browser with the search. </p> <p>How would I do this?</p>
[ { "answer_id": 9002, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>You have a couple of options here:</p>\n\n<p>Using a plugin:</p>\n\n<ul>\n<li><a href=\"http://www.vim.org/scripts/script.p...
2016/07/28
[ "https://vi.stackexchange.com/questions/9001", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2695/" ]
I would like to be able to search google from within any vim file. A nice command might be `:goo` while in normal mode. Then I type what I want to search and bam it opens my default browser with the search. How would I do this?
You have a couple of options here: Using a plugin: * [vim-g](http://www.vim.org/scripts/script.php?script_id=4183) * [gsearch](http://www.vim.org/scripts/script.php?script_id=3551) * [vim-quicklink](https://github.com/christoomey/vim-quicklink) Or, if you prefer a lightweight solution, you can try the following: ``...
9,005
<p>I am trying to format a list that uses tabs for indentation so it will render as a <a href="https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=lists" rel="nofollow noreferrer">bulleted list on Confluence</a>. That means that each instance of a tab needs to be replaced with an asterisk (*), plus on...
[ { "answer_id": 9006, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": true, "text": "<p>Here's a solution I came up with:</p>\n\n<pre><code>:%s/^\\(\\t*\\)/\\=\"*\" . substitute(submatch(1), '\\t', '\\*', 'g...
2016/07/28
[ "https://vi.stackexchange.com/questions/9005", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8603/" ]
I am trying to format a list that uses tabs for indentation so it will render as a [bulleted list on Confluence](https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=lists). That means that each instance of a tab needs to be replaced with an asterisk (\*), plus one leading asterisk, and then a space at...
Here's a solution I came up with: ``` :%s/^\(\t*\)/\="*" . substitute(submatch(1), '\t', '\*', 'g') . " "/ ``` * `%s///`: Do a substitute on every line in the file * `^\(\t*\)`: Match as many tabs as you can find at the beginning of the line * `\=`: Allows us to use an expression in the replacement * `substitute(sub...
9,012
<p>How can you do a case insensitive search with line contexts displayed in vim while using the <code>:g</code> ex command?</p> <p>I tried the following but it doesn't seem to work...</p> <pre><code>g/pattern/z#.1i|echo "================================" </code></pre> <p>I also tried this:</p> <pre><code>g/pattern/...
[ { "answer_id": 9013, "author": "user3224237", "author_id": 7892, "author_profile": "https://vi.stackexchange.com/users/7892", "pm_score": 2, "selected": false, "text": "<p>You can do a <code>set ic</code> before the search command.</p>\n" }, { "answer_id": 9014, "author": "gr...
2016/07/29
[ "https://vi.stackexchange.com/questions/9012", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
How can you do a case insensitive search with line contexts displayed in vim while using the `:g` ex command? I tried the following but it doesn't seem to work... ``` g/pattern/z#.1i|echo "================================" ``` I also tried this: ``` g/pattern/iz#.1|echo "================================" ``` ......
There are two ways to achieve this: *One* is to `set ignorecase`, then the pattern regex will ignore the case. Yet, this solution is poor if you are writing a script that may need to be reused by someone. A *better solution* is to use the `\c` (ignore case) `\C` (do not ignore case) modifiers in the regex. This comma...
9,022
<p>I frequently use vim to edit multiple files. On the command line, I'll type <code>vim *</code> or the like, and use <code>:wn</code> to move through the files until I get to the end.</p> <p>Invariably, I get to the last file, and type <code>:wn</code> and get the maddening message <code>E165: Cannot go beyond last...
[ { "answer_id": 9023, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 1, "selected": false, "text": "<p>I don't think there is a configuration option to change that behaviour. However you can create a custom command, ...
2016/07/30
[ "https://vi.stackexchange.com/questions/9022", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8621/" ]
I frequently use vim to edit multiple files. On the command line, I'll type `vim *` or the like, and use `:wn` to move through the files until I get to the end. Invariably, I get to the last file, and type `:wn` and get the maddening message `E165: Cannot go beyond last file`, when really what I want vim to do is quit...
I don't think there is a configuration option to change that behaviour. However you can create a custom command, that catches error E165 and quits in that case. Something like this should work (untested): ``` com! -count -bang Wnext try | <count>wn<bang> | catch /^Vim\%((\a\+)\)\=:E165/ | q | endtry ```
9,051
<p>I'm hoping to create a <a href="http://www.twilightlandscapes.com/IRAFtutorial/IRAFintro_04.html" rel="nofollow">.cl</a> script to run in <a href="http://iraf.noao.edu/" rel="nofollow">IRAF</a>. I have a list of spectra on which I want to run <a href="http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?dispcor" rel="nofoll...
[ { "answer_id": 9029, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 8, "selected": true, "text": "<p><code>ggVG</code> selects all content. <code>gg</code> moves to first line. <code>V</code> starts visual mode. <code>G<...
2016/08/02
[ "https://vi.stackexchange.com/questions/9051", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8655/" ]
I'm hoping to create a [.cl](http://www.twilightlandscapes.com/IRAFtutorial/IRAFintro_04.html) script to run in [IRAF](http://iraf.noao.edu/). I have a list of spectra on which I want to run [dispcor](http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?dispcor). I was wondering if there's an easy way to paste the output file n...
`ggVG` selects all content. `gg` moves to first line. `V` starts visual mode. `G` jumps to last line thereby selecting from first to last line
9,063
<p>Currently I have the following maps:</p> <pre><code>nmap J 5j nmap K 5k nmap L 5l nmap H 5h </code></pre> <p>This works great if I hit Shift j, it moves down for quick cursor movement. However if I let go of shift while holding j to go back to regular movement speed the cursor stops. </p> <p>The same is true for ...
[ { "answer_id": 9069, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>Instead of remapping, you should consider the other options for moving the cursor around, i.e.</p>\n\n<pre><code>C-D ...
2016/08/03
[ "https://vi.stackexchange.com/questions/9063", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2695/" ]
Currently I have the following maps: ``` nmap J 5j nmap K 5k nmap L 5l nmap H 5h ``` This works great if I hit Shift j, it moves down for quick cursor movement. However if I let go of shift while holding j to go back to regular movement speed the cursor stops. The same is true for if I am moving slowly by holding ...
Instead of remapping, you should consider the other options for moving the cursor around, i.e. ``` C-D Move the cursor Down one page (controlled by the 'scroll' option) C-U Move the cursor Up one page (controlled by the 'scroll' option) M Move the cursor to the Middle line of the window H ...
9,070
<p>I don't have much use for line numbers while in insert mode so I would like to turn them off. However they are great for normal mode. </p> <p>Constantly using <code>set nu!</code> is tiresome. Is there a way to tie <code>set nu!</code> to exiting and entering normal mode?</p> <p>Any solutions using the above or an...
[ { "answer_id": 9071, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 5, "selected": true, "text": "<p>You can do this with autocommands.</p>\n\n<pre><code>au InsertEnter * set nonumber\nau InsertLeave * set number\n</cod...
2016/08/03
[ "https://vi.stackexchange.com/questions/9070", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2695/" ]
I don't have much use for line numbers while in insert mode so I would like to turn them off. However they are great for normal mode. Constantly using `set nu!` is tiresome. Is there a way to tie `set nu!` to exiting and entering normal mode? Any solutions using the above or any other method?
You can do this with autocommands. ``` au InsertEnter * set nonumber au InsertLeave * set number ``` Not much explanation is needed. This does exactly what you asked for. It ties "entering and exiting insert mode" to "turning line numbers on and off".
9,079
<p>Using <a href="https://github.com/junegunn/fzf" rel="nofollow">FZF</a> in Vim, is it possible to search project directory and a library directory? For example when executing FZF, it would search directories:</p> <p><code>~/project/</code> and <code>~/libs/include</code>, and provide results.</p>
[ { "answer_id": 9098, "author": "Sol", "author_id": 8702, "author_profile": "https://vi.stackexchange.com/users/8702", "pm_score": -1, "selected": false, "text": "<p>FZF will search the total pwd. If pwd is <code>~</code>, both directories <code>~/project/</code> and <code>~/libs/include<...
2016/08/04
[ "https://vi.stackexchange.com/questions/9079", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3050/" ]
Using [FZF](https://github.com/junegunn/fzf) in Vim, is it possible to search project directory and a library directory? For example when executing FZF, it would search directories: `~/project/` and `~/libs/include`, and provide results.
You can specify the command to obtain the input of fzf by using the `fzf#run()` function. In your case, this can look something like this: ``` call fzf#run({'source': 'find ~/project/ ~/libs/include -type f', \ 'sink': 'edit'}) ``` and if you want, you can add a command like this ``` command! FZFLib ...
9,081
<p>When writing to a file, I often accidentally type <code>:wq</code> instead of <code>:w</code> since the two keys are right next to each other. But since I almost always have more than one buffer open, Vim stays up and whatever file I just closed stays in the list of buffers (<code>:ls</code>). </p> <p>It is sometim...
[ { "answer_id": 9083, "author": "grochmal", "author_id": 7700, "author_profile": "https://vi.stackexchange.com/users/7700", "pm_score": 1, "selected": false, "text": "<p>Not the exact solution but a rather popular one is the <a href=\"https://github.com/yegappan/mru\" rel=\"nofollow\">MRU...
2016/08/04
[ "https://vi.stackexchange.com/questions/9081", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8683/" ]
When writing to a file, I often accidentally type `:wq` instead of `:w` since the two keys are right next to each other. But since I almost always have more than one buffer open, Vim stays up and whatever file I just closed stays in the list of buffers (`:ls`). It is sometimes a lot of work to reopen the file manuall...
I played around with this a bit and the following seems to work for the cases I tested, including closing a window split and a tab with one window using `:q`. ``` augroup bufclosetrack au! autocmd WinLeave * let g:lastWinName = @% augroup END function! LastWindow() exe "split " . g:lastWinName endfunction comman...
9,089
<p>Let's say that I have a file containing several occurrences of the word <code>foo</code> and several occurrences of the word <code>bar</code>.</p> <p>I need to make all the words <code>foo</code> become <code>bar</code> and inversely all the words <code>bar</code> become <code>foo</code>.</p> <p>What is the most e...
[ { "answer_id": 9090, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 4, "selected": false, "text": "<p>Posting this so it can have an answer on our SE, but <a href=\"https://stackoverflow.com/questions/765894/can-i-substi...
2016/08/05
[ "https://vi.stackexchange.com/questions/9089", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
Let's say that I have a file containing several occurrences of the word `foo` and several occurrences of the word `bar`. I need to make all the words `foo` become `bar` and inversely all the words `bar` become `foo`. What is the most efficient way to do that? --- My first thought was to make it 3 steps: * First ma...
Posting this so it can have an answer on our SE, but [this](https://stackoverflow.com/questions/765894/can-i-substitute-multiple-items-in-a-single-regular-expression-in-vim-or-perl/766093#766093) is this source with full explanation. Here's a good way to use a single regex to do multiple substitutions: ``` :%s/foo\|b...
9,100
<p>I would like to set some options for all things I will read but not modify. That is special settings for read-only files (and files in vim view mode).</p> <p>Particularly I'm interested in <code>setlocal wrap</code> for read-only files.</p> <hr> <p>I know that for special type files (like quickfix) I can use <a ...
[ { "answer_id": 9101, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>I think, you can use an <code>BufEnter</code> autocommand, that checks, whether the file is modifiable. Something ...
2016/08/06
[ "https://vi.stackexchange.com/questions/9100", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8444/" ]
I would like to set some options for all things I will read but not modify. That is special settings for read-only files (and files in vim view mode). Particularly I'm interested in `setlocal wrap` for read-only files. --- I know that for special type files (like quickfix) I can use [autocmd](https://vi.stackexchan...
I think, you can use an `BufEnter` autocommand, that checks, whether the file is modifiable. Something like this should work (untested): ``` augroup ReadOnly au! au BufEnter * if (!&modifiable || &ro) | setl wrap | endif augroup END ```
9,118
<p>I'm a little puzzled about some default values in Vim. In particular, for <code>gq{motion}</code>, is said that</p> <pre><code>[...] If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum width of 79). </code></pre> <p>I thought that it should have made more sense if it would...
[ { "answer_id": 14132, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 4, "selected": false, "text": "<p>It is important to realize that this \"default\" only applies to the <code>gq</code> and <code>gw</code> commands and au...
2016/08/08
[ "https://vi.stackexchange.com/questions/9118", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4670/" ]
I'm a little puzzled about some default values in Vim. In particular, for `gq{motion}`, is said that ``` [...] If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum width of 79). ``` I thought that it should have made more sense if it would have set the max width to `80`, inst...
It is important to realize that this "default" only applies to the `gq` and `gw` commands and auto-format as described in that section. The default `textwidth` is 0. Furthermore, `:right` and `:center` default to 80, not 79. As for why 79 was chosen, it cannot be a direct hold-over from vi since `gq`, `gw`, and auto-f...
9,121
<p>I very often want to do the following or similar:</p> <ul> <li>indent all lines from previous position to current position inclusive</li> <li>repeat, repeat, repeat (to further indent the same lines)</li> </ul> <p>I feel I should be able to do that by saying:</p> <pre><code>&gt;''... </code></pre> <p>(greater-th...
[ { "answer_id": 9123, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 2, "selected": false, "text": "<p>After your first <code>&gt;''</code> you can do <code>&gt;']</code> to indent the last changed lines, which can be repeated ...
2016/08/09
[ "https://vi.stackexchange.com/questions/9121", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2065/" ]
I very often want to do the following or similar: * indent all lines from previous position to current position inclusive * repeat, repeat, repeat (to further indent the same lines) I feel I should be able to do that by saying: ``` >''... ``` (greater-than single-quote single-quote period period period). But it d...
After your first `>''` you can do `>']` to indent the last changed lines, which can be repeated with `.`. It's not quite `>''...`, but `>''>']..` is certainly better than `''ma''mb>'a>'b>'b>'b`. Alternatively, you could use visual mode and this fairly common mapping: ``` xnoremap > >gv xnoremap < <gv ``` and simpl...
9,130
<p>I use a mix of buffers and split panes to manage my workflow. Sometimes, I (perhaps accidentally) open a directory listing instead of a file. My buffers may look like this then:</p> <p><a href="https://i.stack.imgur.com/jh2CM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jh2CM.png" alt="directo...
[ { "answer_id": 9132, "author": "grochmal", "author_id": 7700, "author_profile": "https://vi.stackexchange.com/users/7700", "pm_score": 3, "selected": true, "text": "<p>What you call a directory listing is actually a special buffer with type <code>netrw</code>. It is created by a plugin ...
2016/08/10
[ "https://vi.stackexchange.com/questions/9130", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8745/" ]
I use a mix of buffers and split panes to manage my workflow. Sometimes, I (perhaps accidentally) open a directory listing instead of a file. My buffers may look like this then: [![directory listing](https://i.stack.imgur.com/jh2CM.png)](https://i.stack.imgur.com/jh2CM.png) At this point, I can `:bnext` or `:bpreviou...
What you call a directory listing is actually a special buffer with type `netrw`. It is created by a plugin also called `netrw`. Your issue probably stems from the fact that `netrw` (with the default listing) creates *several* hidden buffers, one for each directory listing you pass through, i.e. every time you change d...
9,151
<p>If I select multiple lines and do substitution at the beginning of text it actually substitutes at the beginning of the line. For example, given:</p> <pre><code>abc def ghi </code></pre> <p>If we do:</p> <pre><code>Vjj:s/^/--&gt;/ </code></pre> <p>then we get:</p> <pre><code>--&gt; abc --&gt; de...
[ { "answer_id": 9152, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p><code>^</code> represents the beginning of the line in regex language it is not related to the motion <code>^</code> that...
2016/08/11
[ "https://vi.stackexchange.com/questions/9151", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6952/" ]
If I select multiple lines and do substitution at the beginning of text it actually substitutes at the beginning of the line. For example, given: ``` abc def ghi ``` If we do: ``` Vjj:s/^/-->/ ``` then we get: ``` --> abc --> def --> ghi ``` but this is no different than ``` Vjj:s/0/-->/...
`^` represents the beginning of the line in regex language it is not related to the motion `^` that's why your solution won't work. You'll have to use that: ``` :%s/\(^\s*\)/\1--> ``` Here you use the substitution with a capture group, here is a detail of the pattern: ``` \( \) Will be used to capture chara...
9,156
<p>Lately I've been drastically reducing the number of plugins I'm using so I'm looking for answers using only built-in Vim features.</p> <p>I've been noticing a flaw in my workflow when I'm editing a lot of buffers: I am on a buffer and I want to switch to another one of which I don't remember the name and which isn'...
[ { "answer_id": 9159, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": false, "text": "<p>I encountered the same problem a while ago and I found a solution:</p>\n\n<pre><code>nnoremap &lt;leader&gt;b :buffers&lt;...
2016/08/11
[ "https://vi.stackexchange.com/questions/9156", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
Lately I've been drastically reducing the number of plugins I'm using so I'm looking for answers using only built-in Vim features. I've been noticing a flaw in my workflow when I'm editing a lot of buffers: I am on a buffer and I want to switch to another one of which I don't remember the name and which isn't the alte...
> > I've been noticing a flaw in my workflow when I'm editing a lot of buffers: I am on a buffer and I want to switch to another one of which I don't remember the name and which isn't the alternative buffer. So using `:b#` is not possible and using the completion with the command `:b` isn't convenient neither. > > >...
9,170
<p>I have my vim setup according to "Solution #1: Replicating Tabs with Buffers" on this site <a href="http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/" rel="nofollow">buffers-vs-tabs</a> with the vim-airline plugin.</p> <p>If I open numerous files in buffer 'tabs' <code>:bprevious</code>/<code>:bnext...
[ { "answer_id": 9180, "author": "jshort", "author_id": 8786, "author_profile": "https://vi.stackexchange.com/users/8786", "pm_score": 2, "selected": false, "text": "<p>So this has to do with the fact that:</p>\n\n<pre><code>vim .\n</code></pre>\n\n<p>Opens the current directory into a net...
2016/08/12
[ "https://vi.stackexchange.com/questions/9170", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8786/" ]
I have my vim setup according to "Solution #1: Replicating Tabs with Buffers" on this site [buffers-vs-tabs](http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/) with the vim-airline plugin. If I open numerous files in buffer 'tabs' `:bprevious`/`:bnext` just cycles through them great (and wrap when you ...
So this has to do with the fact that: ``` vim . ``` Opens the current directory into a netrw buffer that is not unlisted. This is what causes odd behavior with `:bp/:bn`. If I `:bdelete 1` soon as I open vim on a directory, then I don't have this issue for the rest of the session. Alternatively: ``` vim +':Ex' ``...
9,174
<p>I use gvim for writing emails and use <code>tw=72</code> to break long lines. Now I also edit basic mail headers in the same document, e.g. I am adding recipients to my mail. Now with <code>tw=72</code> it also breaks every time after 72 characters.</p> <p>How can I set <code>tw=0</code> on the first 4 lines (that'...
[ { "answer_id": 9176, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 1, "selected": false, "text": "<p>I don't believe this is possible. However, there are a couple workarounds.</p>\n\n<ol>\n<li><p>You could write your h...
2016/08/12
[ "https://vi.stackexchange.com/questions/9174", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8791/" ]
I use gvim for writing emails and use `tw=72` to break long lines. Now I also edit basic mail headers in the same document, e.g. I am adding recipients to my mail. Now with `tw=72` it also breaks every time after 72 characters. How can I set `tw=0` on the first 4 lines (that's the header part), and `tw=72` for the res...
Thanks to @Carpetsmoker's comment on my question, I was able to solve this exactly like I wanted it to have. With the following function in .vimrc (or in my case in a special file that it only loaded when editing my emails), tw is set to 500 if the line number is smaller than 5, otherwise it's 72. With `au CursorMoved...
9,189
<p>It would be fine if after <code>:make</code> command vim opened the new buffer with errors and put the cursor to it. Exactly like <code>:make | copen</code> command. How to map sequence <code>:make | copen</code>?</p>
[ { "answer_id": 9190, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>The best solution is to not create a mapping at all.</p>\n\n<p>Simply put the following snippet in your <code>vimrc</code>:<...
2016/08/13
[ "https://vi.stackexchange.com/questions/9189", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8810/" ]
It would be fine if after `:make` command vim opened the new buffer with errors and put the cursor to it. Exactly like `:make | copen` command. How to map sequence `:make | copen`?
You could create an abbreviation in the command line mode by adding this to your vimrc: ``` cabbrev mc make<bar>copen ``` Now when you'll type `mc` in the command line it will be replaced by `make|copen` making it faster to type. You could also create a mapping to invoke the commands you want: ``` nnoremap <key> :...
9,198
<p>Considerthis text with shopping and todo list</p> <pre><code>First thing in the morning - call Bob - buy carrots - buy bread - text Charlie - buy butter - email Alice only then start the day </code></pre> <p>What I am looking for a is a vim command to be applied from the first line that starts with a minus, to the...
[ { "answer_id": 9199, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>Here are two functions that you could use.\nBoth takes as argument a pattern to search and a command to execute on the\nc...
2016/08/15
[ "https://vi.stackexchange.com/questions/9198", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5919/" ]
Considerthis text with shopping and todo list ``` First thing in the morning - call Bob - buy carrots - buy bread - text Charlie - buy butter - email Alice only then start the day ``` What I am looking for a is a vim command to be applied from the first line that starts with a minus, to the last one that does. Somet...
Here are two functions that you could use. Both takes as argument a pattern to search and a command to execute on the consecutive lines matching the pattern. You can call them with: ``` call RangeFromPattern("^\s*-", "!sort -u") ``` The first one goes to the first line of the buffer, searches for the first line mat...
9,212
<p>In vim <code>:make</code> makes it easy to build and fix errors, and <code>:grep</code> and <code>:vimgrep</code> behaves like <code>:make</code>. But why do you need these two commands? Why not just search for the pattern and just press <code>n</code>? What are the advantages of them over just searching? </p>
[ { "answer_id": 9213, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 6, "selected": true, "text": "<p>As the doc say:</p>\n\n<pre><code>Vim has two ways to find matches for a pattern: Internal and external.\n</code></pre>\n\n...
2016/08/16
[ "https://vi.stackexchange.com/questions/9212", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8790/" ]
In vim `:make` makes it easy to build and fix errors, and `:grep` and `:vimgrep` behaves like `:make`. But why do you need these two commands? Why not just search for the pattern and just press `n`? What are the advantages of them over just searching?
As the doc say: ``` Vim has two ways to find matches for a pattern: Internal and external. ``` In a nutshell, `:vimgrep` uses Vim's grep mechanism to read and find in files. `:grep` uses an external commands to achieve the same job. The `/` search is for the current buffer only, whereas `:[vim]grep` search through ...
9,220
<p>I want to <code>imap</code> the sequence <code>^^</code> to <code>^{}&lt;++&gt;</code> and then place the cursor inside the brackets. (This is handy when editing <em>Latex</em> code and is a nice feature of the <em>vim latex suite</em> which I have recently abandoned) </p> <p>The straight forward approach doesn't w...
[ { "answer_id": 9221, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": true, "text": "<pre><code>inoremap ^^ ^{}&lt;++&gt;&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;\n</code></pre>\n\n<p>Is u...
2016/08/16
[ "https://vi.stackexchange.com/questions/9220", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8648/" ]
I want to `imap` the sequence `^^` to `^{}<++>` and then place the cursor inside the brackets. (This is handy when editing *Latex* code and is a nice feature of the *vim latex suite* which I have recently abandoned) The straight forward approach doesn't work for me: `:imap ^^ ^{x}<++><esc>Fxs` Any ideas?
``` inoremap ^^ ^{}<++><Left><Left><Left><Left><Left> ``` Is ugly, but it should work. See `:h i_<Left>`
9,231
<p>I tend to open multiple tabs in vim and multiple windows within a tab. </p> <p>I have a habit of traversing the code in a tree format - I open a tag in a new tab, so that my current view of the window remains unchanged. I can simply close the newly opened tab/window to resume to my previous view.</p> <p>Consider ...
[ { "answer_id": 9232, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p>For the windows you could use a function which get the number of the current window, goes to the previous one and close t...
2016/08/17
[ "https://vi.stackexchange.com/questions/9231", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2749/" ]
I tend to open multiple tabs in vim and multiple windows within a tab. I have a habit of traversing the code in a tree format - I open a tag in a new tab, so that my current view of the window remains unchanged. I can simply close the newly opened tab/window to resume to my previous view. Consider a case where I hav...
I have written the script for this purpose. It can be downloaded as vimball based plugin from <http://www.vim.org/scripts/script.php?script_id=5430>. ``` Installation details: $ wget http://www.vim.org/scripts/download_script.php?src_id=24462 -O FocusPrevious.vmb $ vim FocusPrevious.vmb Within vim: :source % :q ...
9,236
<p>I have encountered very strange problem using vimgrep command. I try to find a match in all the files in all subdirs of a specified directory:</p> <pre><code>:vimgrep /word_I_search/ path\to\my\dir\**\* </code></pre> <p>(there are backslashes in path because I am on Windows). Command reports:</p> <pre><code>E480:...
[ { "answer_id": 9232, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p>For the windows you could use a function which get the number of the current window, goes to the previous one and close t...
2016/08/18
[ "https://vi.stackexchange.com/questions/9236", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6194/" ]
I have encountered very strange problem using vimgrep command. I try to find a match in all the files in all subdirs of a specified directory: ``` :vimgrep /word_I_search/ path\to\my\dir\**\* ``` (there are backslashes in path because I am on Windows). Command reports: ``` E480: No match: word_I_search ``` But I ...
I have written the script for this purpose. It can be downloaded as vimball based plugin from <http://www.vim.org/scripts/script.php?script_id=5430>. ``` Installation details: $ wget http://www.vim.org/scripts/download_script.php?src_id=24462 -O FocusPrevious.vmb $ vim FocusPrevious.vmb Within vim: :source % :q ...
9,239
<p>We have two separate files:</p> <p><strong>f1.txt</strong></p> <pre><code>17.0, 155.7, 1123,9, </code></pre> <p>and </p> <p><strong>f2.txt</strong></p> <pre><code>1 2 3 </code></pre> <p>After opening files vertically with <code>vim -O ~/f1.txt ~/f2.txt</code></p> <p><strong>How to obtain?</strong></p> <pre><...
[ { "answer_id": 9241, "author": "kba", "author_id": 6337, "author_profile": "https://vi.stackexchange.com/users/6337", "pm_score": 2, "selected": false, "text": "<p>I'd rather use the <code>paste</code> command line tool, if you are using Linux/BSD/OSX:</p>\n\n<pre><code>paste -d '' f1.tx...
2016/08/18
[ "https://vi.stackexchange.com/questions/9239", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8867/" ]
We have two separate files: **f1.txt** ``` 17.0, 155.7, 1123,9, ``` and **f2.txt** ``` 1 2 3 ``` After opening files vertically with `vim -O ~/f1.txt ~/f2.txt` **How to obtain?** ``` 17.0,1 155.7,2 1123,9,3 ``` which is the equivalent of `paste -d '' f1.txt f2.txt` in bash --- I tried all I could but in ...
I have answered a similar question here: <https://stackoverflow.com/a/20050503/164835> But that question is not exactly same as this one, so I answer here once again: in **File1** do: * `:%right` * `0<ctrl-v>G$` -> column select all * `y` -> yank in **File2** do: * `P` -> paste * `:%left` **Done**! It is pure vi...
9,240
<p>I'm trying to create my first own <code>.vimrc</code> file. I'm having some trouble when trying to load plugins with Vundle. For example, I want to use <code>vim-airline</code>, so I have (in the correct place I believe) in my <code>.vimrc</code> file this:</p> <pre><code>Plugin 'vim-airline/vim-airline' Plugin 'vi...
[ { "answer_id": 9245, "author": "Martijn Courteaux", "author_id": 8868, "author_profile": "https://vi.stackexchange.com/users/8868", "pm_score": 0, "selected": false, "text": "<p>Turns out I was able to fix it using this:</p>\n\n<pre><code>let g:airline_theme = 'luna'\n</code></pre>\n\n<p...
2016/08/18
[ "https://vi.stackexchange.com/questions/9240", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8868/" ]
I'm trying to create my first own `.vimrc` file. I'm having some trouble when trying to load plugins with Vundle. For example, I want to use `vim-airline`, so I have (in the correct place I believe) in my `.vimrc` file this: ``` Plugin 'vim-airline/vim-airline' Plugin 'vim-airline/vim-airline-themes' ``` I installed...
That command from the plugin is not available, until sourcing the vimrc is actually done. So either explicitly set the theme using `let g:airline_theme = 'luna'` which is the documented way to set your airline theme, or wrap your command into an VimEnter autocommand.
9,250
<p>Is it possible to include external files to be sourced in the vimrc file? </p> <p>Is it as simple a matter as just adding <code>source somefile</code>?</p>
[ { "answer_id": 9252, "author": "user3224237", "author_id": 7892, "author_profile": "https://vi.stackexchange.com/users/7892", "pm_score": 2, "selected": false, "text": "<p>Yes, or even just <code>so somefile</code>. See <code>:help so</code>.</p>\n" }, { "answer_id": 9253, "a...
2016/08/19
[ "https://vi.stackexchange.com/questions/9250", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
Is it possible to include external files to be sourced in the vimrc file? Is it as simple a matter as just adding `source somefile`?
Unlike `:source`, `:runtime` doesn't need an absolute path to work. It is much better than `:source` for building portable setups. See `:help :runtime`. In the following example, we tell Vim to look for a `vimrc` file in the directories given by the `runtimepath` variable. Since `~/.vim/` is the first directory in th...
9,264
<p>Let's say I have the following text and my cursor is on the "d"</p> <pre><code>someCamelCaseWord ^ </code></pre> <p>I want to delete "Word" so that the text reads "someCamelCase"</p> <p>What's the fewest number of keystrokes required to achieve this?</p>
[ { "answer_id": 9265, "author": "Herb", "author_id": 5298, "author_profile": "https://vi.stackexchange.com/users/5298", "pm_score": 4, "selected": true, "text": "<p>In this specific instance, the best I could come up with is 4, including holding the shift key. There are several possibilit...
2016/08/20
[ "https://vi.stackexchange.com/questions/9264", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7454/" ]
Let's say I have the following text and my cursor is on the "d" ``` someCamelCaseWord ^ ``` I want to delete "Word" so that the text reads "someCamelCase" What's the fewest number of keystrokes required to achieve this?
In this specific instance, the best I could come up with is 4, including holding the shift key. There are several possibilities. xxxx - delete the character under the cursor. 3Xx - delete 3 characters to the left, delete the character under the cursor. 3hdw - Move 3 characters to the left, delete to the end of t...
9,277
<p>I am looking for a way to create a newline with an indentation equal to the current column position of my cursor.</p> <p>Here is an example. Say I'm editing some line of code looking like this, with my cursor on the opening bracket <code>[</code>:</p> <pre><code>data Foo a = Bar a | Baz [a] </code></pre> <p>I'd l...
[ { "answer_id": 9278, "author": "jjaderberg", "author_id": 1306, "author_profile": "https://vi.stackexchange.com/users/1306", "pm_score": 3, "selected": true, "text": "<p>To do this manually you probably just open a new line below the current and insert a bunch of whitespace. You can crea...
2016/08/21
[ "https://vi.stackexchange.com/questions/9277", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2438/" ]
I am looking for a way to create a newline with an indentation equal to the current column position of my cursor. Here is an example. Say I'm editing some line of code looking like this, with my cursor on the opening bracket `[`: ``` data Foo a = Bar a | Baz [a] ``` I'd like to have a command that act a bit like `o...
To do this manually you probably just open a new line below the current and insert a bunch of whitespace. You can create a command that does this, and a convenient map to execute the command. Try something like: ``` nnoremap <LocalLeader>o :OpenIndentToCursorCol<CR> command! OpenIndentToCursorCol call append('.', repe...
9,287
<p>When using VIM, it is possible to get a file listing in one split window by doing this:</p> <pre><code>:vsp :e. </code></pre> <p>Then you have something that looks like this:</p> <p><a href="https://i.stack.imgur.com/JHcKD.png" rel="noreferrer"><img src="https://i.stack.imgur.com/JHcKD.png" alt="enter image descr...
[ { "answer_id": 9289, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>There is a dedicated command for opening a netrw listing in a vertical split:</p>\n\n<pre><code>:Vex[plore]\n</code></pre>\n\...
2016/08/22
[ "https://vi.stackexchange.com/questions/9287", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8869/" ]
When using VIM, it is possible to get a file listing in one split window by doing this: ``` :vsp :e. ``` Then you have something that looks like this: [![enter image description here](https://i.stack.imgur.com/JHcKD.png)](https://i.stack.imgur.com/JHcKD.png) However if you open a file then how can you get back to ...
There is a dedicated command for opening a netrw listing in a vertical split: ``` :Vex[plore] ``` There is a dedicated command for going back to the latest netrw listing: ``` :Rex[plore] ``` Netrw comes with a complete documentation; read it: `:help netrw`.
9,294
<p>What I want to do is replace this:</p> <pre><code>&lt;|Filename.ext|5|0|&gt; </code></pre> <p>with</p> <pre><code>&lt;|Filename.ext|5|0|&gt; &lt;|Filename.ext|5|1|&gt; &lt;|Filename.ext|5|2|&gt; &lt;|Filename.ext|5|3|&gt; &lt;|Filename.ext|5|4|&gt; </code></pre> <p>I wrote a necessary regular expression:</p> <p...
[ { "answer_id": 9295, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": true, "text": "<p>If you have Vim version <code>7.4.754</code> or later you can do this simply with some copy/paste and <code>g&lt;C-a&gt;</c...
2016/08/22
[ "https://vi.stackexchange.com/questions/9294", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7816/" ]
What I want to do is replace this: ``` <|Filename.ext|5|0|> ``` with ``` <|Filename.ext|5|0|> <|Filename.ext|5|1|> <|Filename.ext|5|2|> <|Filename.ext|5|3|> <|Filename.ext|5|4|> ``` I wrote a necessary regular expression: ``` <|\(\w\| \)\+\.\w\+|\d\{1,2}|0|> ``` So, substitution would go something like this: ...
If you have Vim version `7.4.754` or later you can do this simply with some copy/paste and `g<C-a>`: ``` yy4pf0<C-v>3jg<C-a> ``` Decomposing: ``` yy4p duplicate the line 4 time and put you on the 2nd line f0 go to the 0 <C-v>3j start a visual block selection and go down 3 lines g<C-a> increment suc...
9,303
<p>Say you have some text like this:</p> <pre><code>## countries, primary United States,Washington,North America Canada,Ottawa,North America Australia,Canberra,Oceania ## countries, secondary France,Paris,Europe Japan,Tokyo,Asia United Kingdom,London,Europe </code></pre> <p>And you want to filter <em>only the non-com...
[ { "answer_id": 9317, "author": "Ingo", "author_id": 3343, "author_profile": "https://vi.stackexchange.com/users/3343", "pm_score": 2, "selected": false, "text": "<p>If you want to have the table spacing inferred using the whole file, you could delete the headlines, run <code>column</code...
2016/08/23
[ "https://vi.stackexchange.com/questions/9303", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8927/" ]
Say you have some text like this: ``` ## countries, primary United States,Washington,North America Canada,Ottawa,North America Australia,Canberra,Oceania ## countries, secondary France,Paris,Europe Japan,Tokyo,Asia United Kingdom,London,Europe ``` And you want to filter *only the non-comment lines* through an extern...
If you want to have the table spacing inferred using the whole file, you could delete the headlines, run `column` on the resulting file and reinsert the headlines using something like this: ``` function! Column() let b:headlines={} g/^##.*$/let b:headlines[line(".")+len(b:headlines)]=getline(".")|d %!column -ts,...
9,331
<p>I am actually stuck level 10 at <a href="http://vim-adventures.com" rel="nofollow">vim-adventures</a>, but this question concerns vim in general. </p> <p>I have a new file with this content: </p> <pre><code>99 bottles of beer </code></pre> <p>If I yank the line with <kbd>"</kbd><kbd>a</kbd><kbd>Y</kbd> I get ...
[ { "answer_id": 9332, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": true, "text": "<p>One way is to use a capital \"A\" for the yank command which appends to the register instead of replacing it. So you wo...
2016/08/24
[ "https://vi.stackexchange.com/questions/9331", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2548/" ]
I am actually stuck level 10 at [vim-adventures](http://vim-adventures.com), but this question concerns vim in general. I have a new file with this content: ``` 99 bottles of beer ``` If I yank the line with `"``a``Y` I get `99 bottles of beer<cr>`, if I do `"``a``0``y``$` I get `99 bottles of beer` without t...
One way is to use a capital "A" for the yank command which appends to the register instead of replacing it. So you would need to position your cursor on a blank line and then do `"AY`. See `:h quote` for more info. Another way to do it would be to run the following command: ``` :let @a = @a . "\n" ``` Registers ca...
9,338
<p>And I add this in the vimrc file:</p> <pre><code>autocmd FileType markdown iabbrev mkdc &lt;!--i--&gt;&lt;left&gt;&lt;left&gt;&lt;left&gt; </code></pre> <p>What I want to do is source the vimrc and make the abbreviation effective for the current file I'm editing.</p> <p>I have tried:</p> <ol> <li><code>:!sc</cod...
[ { "answer_id": 9339, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": true, "text": "<p>Your autocommand is executed when the <code>FileType</code> event is triggered, with the <code>markdown</code> value. Sourcin...
2016/08/25
[ "https://vi.stackexchange.com/questions/9338", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1788/" ]
And I add this in the vimrc file: ``` autocmd FileType markdown iabbrev mkdc <!--i--><left><left><left> ``` What I want to do is source the vimrc and make the abbreviation effective for the current file I'm editing. I have tried: 1. `:!sc`, `:redraw!` 2. `:source $MYVIMRC` 3. `:q` and rerun Vim But it seems that ...
Your autocommand is executed when the `FileType` event is triggered, with the `markdown` value. Sourcing your `vimrc` is not enough because it only adds the autocommand but the event is not triggered. What you need to do is: 1. Source your `vimrc` with `:source $MYVIMRC`, this will add your autocommand to the existin...
9,344
<p>I have the file /path/a.md which has many sections as follows:</p> <pre><code># abc this this the content of section abc # def this this the content of section abc ## defg this this the content of subsection defg of def </code></pre> <p>And in an other file /path/b.md I have the the following:</p> <pre><code>I wa...
[ { "answer_id": 9345, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>This function is not thoroughly tested but it should provide a good enough bootstrap for your own experiments.</p>\n\n<p>In <...
2016/08/25
[ "https://vi.stackexchange.com/questions/9344", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1788/" ]
I have the file /path/a.md which has many sections as follows: ``` # abc this this the content of section abc # def this this the content of section abc ## defg this this the content of subsection defg of def ``` And in an other file /path/b.md I have the the following: ``` I want to switch to def section by this l...
This function is not thoroughly tested but it should provide a good enough bootstrap for your own experiments. In `~/.vim/after/ftplugin/markdown.vim`: ``` function! s:MDGoToSection() let raw_filename = expand('<cfile>') let arg = substitute(raw_filename, '\([^#]*\)\(#\{1,6\}\)\([^#]*\)', '+\/\2\\\\s\3 \1', '...
9,366
<p>Vim automatically continues a comment when I press Enter in Insert mode, which I find helpful.</p> <p>However, I do not want the comment continued after pressing 'o' from normal mode to insert a new line below the end of the comment.</p> <p>I read that I need to remove the option <code>o</code> from my <code>forma...
[ { "answer_id": 9367, "author": "theonlygusti", "author_id": 9024, "author_profile": "https://vi.stackexchange.com/users/9024", "pm_score": 3, "selected": true, "text": "<p>I found out that I can provide a makeshift solution using an autocommand.</p>\n\n<p>The following line in your <code...
2016/08/26
[ "https://vi.stackexchange.com/questions/9366", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
Vim automatically continues a comment when I press Enter in Insert mode, which I find helpful. However, I do not want the comment continued after pressing 'o' from normal mode to insert a new line below the end of the comment. I read that I need to remove the option `o` from my `formatoptions`, so I put this line rig...
I found out that I can provide a makeshift solution using an autocommand. The following line in your `.vimrc` file should apply the new formatoptions everywhere: ``` autocmd FileType * set formatoptions-=o ``` However, this doesn't really get to solving the problem; I still don't understand why a simple `set` wasn'...
9,372
<p>For easy horizontal scrolling in long lines, I use these mappings that work well for me:</p> <pre><code>map &lt;m-[&gt; 20zh map &lt;m-]&gt; 20zl </code></pre> <p>Something that has always annoyed me is when the following use case happens (<code>|</code> is the current cursor position):</p> <pre><code>some |short...
[ { "answer_id": 9377, "author": "Jerome Dalbert", "author_id": 7318, "author_profile": "https://vi.stackexchange.com/users/7318", "pm_score": 3, "selected": true, "text": "<p>I eventually came up with this solution (edited with @Rich's answer to remove an unnecessary former Python depende...
2016/08/27
[ "https://vi.stackexchange.com/questions/9372", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7318/" ]
For easy horizontal scrolling in long lines, I use these mappings that work well for me: ``` map <m-[> 20zh map <m-]> 20zl ``` Something that has always annoyed me is when the following use case happens (`|` is the current cursor position): ``` some |short line some other line some other line some other line some o...
I eventually came up with this solution (edited with @Rich's answer to remove an unnecessary former Python dependency). ``` noremap <silent> <m-[> 20zh:call SetVirtualEdit()<cr> noremap <silent> <m-]> :set virtualedit=all<cr>20zl noremap <silent> ^ :set virtualedit=<cr>^ noremap <silent> $ :set virtualedit=<cr>$ func...
9,382
<p>The arrow keys can easily be enhanced and I would like to add the "bubble" feature for all modes. </p> <p>The idea is to use the <code>&lt;C-Up/Down&gt;</code> to take the line and move it along the text and preserve the cursor position. If possible I also would like the <code>cut</code> with <code>dd</code> to not...
[ { "answer_id": 9385, "author": "Sato Katsura", "author_id": 2313, "author_profile": "https://vi.stackexchange.com/users/2313", "pm_score": 3, "selected": true, "text": "<p>Here's a trick I picked up a long time ago:</p>\n\n<pre><code>nnoremap &lt;silent&gt; &lt;M-c&gt; @='\"zyy\"zp'&lt;...
2016/08/28
[ "https://vi.stackexchange.com/questions/9382", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2548/" ]
The arrow keys can easily be enhanced and I would like to add the "bubble" feature for all modes. The idea is to use the `<C-Up/Down>` to take the line and move it along the text and preserve the cursor position. If possible I also would like the `cut` with `dd` to not alter the yank registers. The following works ...
Here's a trick I picked up a long time ago: ``` nnoremap <silent> <M-c> @='"zyy"zp'<CR> vnoremap <silent> <M-c> @='"zy"zPgv'<CR> nnoremap <silent> <M-j> @='"zdd"zp'<CR> vnoremap <silent> <M-j> @='"zx"zp`[V`]'<CR> nnoremap <silent> <M-k> @='k"zdd"zpk'<CR> vnoremap <silent> <M-k> @='"zxk"zP`[V`]'<CR> ``` The poi...
9,400
<p>Now I navigate from one tab to another tab in Vim using the <code>gt</code> command, but it's little frustrating for me, because so far I've worked with editors that support mouse navigation.</p> <p>Is there a way that I can control Vim with mouse?</p>
[ { "answer_id": 9401, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 5, "selected": true, "text": "<p>Give this a try:</p>\n\n<pre><code>:set mouse=a\n</code></pre>\n\n<p>I think you'll find the keys a bit faster though, if y...
2016/08/16
[ "https://vi.stackexchange.com/questions/9400", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8840/" ]
Now I navigate from one tab to another tab in Vim using the `gt` command, but it's little frustrating for me, because so far I've worked with editors that support mouse navigation. Is there a way that I can control Vim with mouse?
Give this a try: ``` :set mouse=a ``` I think you'll find the keys a bit faster though, if you take the time to learn them.
9,418
<p>I am using the <a href="http://cmder.net/" rel="nofollow">cmder</a> under windows 7.</p> <p>I am using Vim version 7.4; I'm using the airline plugin and I installed the powerline font/patch.</p> <p>I followed the instruction and also added the following to my <code>vimrc</code>:</p> <pre><code>if !exists('g:airli...
[ { "answer_id": 9419, "author": "dNitro", "author_id": 7976, "author_profile": "https://vi.stackexchange.com/users/7976", "pm_score": 3, "selected": true, "text": "<p>From <a href=\"https://github.com/cmderdev/cmder/issues/225\" rel=\"nofollow\">issue#225</a> of cmder:</p>\n\n<blockquote>...
2016/09/01
[ "https://vi.stackexchange.com/questions/9418", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9092/" ]
I am using the [cmder](http://cmder.net/) under windows 7. I am using Vim version 7.4; I'm using the airline plugin and I installed the powerline font/patch. I followed the instruction and also added the following to my `vimrc`: ``` if !exists('g:airline_symbols') let g:airline_symbols = {} endif " unicode symb...
From [issue#225](https://github.com/cmderdev/cmder/issues/225) of cmder: > > This not a specific problem of cmder, but rather of cmd in general, > which does not use UTF-8 by default. > > > So just run `chcp 65001` from cmder terminal to set unicode code page to *UTF8*. BUT this way you should run this code eve...
9,425
<p>Are this:</p> <pre><code>set noexpandtab set shiftwidth=4 set tabstop=4 set softtabstop=0 </code></pre> <p>..and this:</p> <pre><code>set noexpandtab set shiftwidth=4 set tabstop=4 set softtabstop=4 </code></pre> <p>..exactly the same? I thought that if <code>softtabstop=0</code>, then nothing happens if <kbd>Ta...
[ { "answer_id": 9450, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 3, "selected": true, "text": "<p>Think of <code>'softtabstop'</code> as an additional control over <code>'tabstop'</code>, allowing you to reach indents...
2016/09/02
[ "https://vi.stackexchange.com/questions/9425", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8626/" ]
Are this: ``` set noexpandtab set shiftwidth=4 set tabstop=4 set softtabstop=0 ``` ..and this: ``` set noexpandtab set shiftwidth=4 set tabstop=4 set softtabstop=4 ``` ..exactly the same? I thought that if `softtabstop=0`, then nothing happens if `Tab` is pressed, but this does not seem to be the case.
Think of `'softtabstop'` as an additional control over `'tabstop'`, allowing you to reach indents "in between" tab stops. With your indent setting, you don't actually need that, so the value of `'softtabstop'` doesn't really matter: You can set it to `0`, turning this off, set this equal to `'tabstop'`, in which case ...
9,426
<p>I have been following the following two tutorials to try and set up <code>eslint</code> and <code>Neomake</code>:</p> <ul> <li><a href="https://www.gregjs.com/vim/2015/linting-code-with-neomake-and-neovim/" rel="noreferrer">Linting code with Neomake and Neovim</a></li> <li><a href="https://www.gregjs.com/vim/2015/l...
[ { "answer_id": 18918, "author": "icc97", "author_id": 11986, "author_profile": "https://vi.stackexchange.com/users/11986", "pm_score": 0, "selected": false, "text": "<p>This doesn't exactly answer your question, but I found that neomake works better with <a href=\"https://github.com/mant...
2016/09/03
[ "https://vi.stackexchange.com/questions/9426", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7052/" ]
I have been following the following two tutorials to try and set up `eslint` and `Neomake`: * [Linting code with Neomake and Neovim](https://www.gregjs.com/vim/2015/linting-code-with-neomake-and-neovim/) * [Linting code with Neovim and Neomake - ESLint edition](https://www.gregjs.com/vim/2015/linting-code-with-neovim-...
Some [lightly edited] info from the comments: > > Actually this might be the reason for empty Quickfix window. On your screen cast when you run `:lopen`, Neomake runs for that buffer due to the autocmd for BufEnter. It should be additionally limited to JavaScript files only: > > > ``` augroup neomake au! auto...
9,431
<p>I get no syntax highlight now in Debian's Vim by the workflow which works in Ubuntu 16.04: installation of packages and activating syntax</p> <ol> <li>installation <code>apt-get install vim texlive-full</code></li> <li>activation in Vim, <code>:set syntax=latex</code></li> </ol> <p>I know that the Texlive is worki...
[ { "answer_id": 9437, "author": "Brian Tiffin", "author_id": 9087, "author_profile": "https://vi.stackexchange.com/users/9087", "pm_score": 1, "selected": false, "text": "<p>There is no latex.vim syntax file that ships with Vim (as far as I know, and see on this Fedora 21 install).</p>\n\...
2016/09/03
[ "https://vi.stackexchange.com/questions/9431", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2923/" ]
I get no syntax highlight now in Debian's Vim by the workflow which works in Ubuntu 16.04: installation of packages and activating syntax 1. installation `apt-get install vim texlive-full` 2. activation in Vim, `:set syntax=latex` I know that the Texlive is working because I get correct LaTeX syntax in Geany. Debia...
And to make it persistent, check out vim's help files under the keyword `au` for autocmd ``` :h au ``` Then create a group (i.e. *scope/namespace* as the ubiquitous term) to protect yourself from duplicate definitions (just like an include guard in C) ``` augroup debianlatexfix " Remove all vimrc autocommands wi...
9,432
<p>Is there any way to have the confirm function place the choices on the same line as the msg prompt?</p> <pre><code>confirm("Yes no question", "&amp;Yes\n&amp;No", 2) </code></pre> <p>Instead of</p> <pre><code>Yes no question (Y)es, [N]o: </code></pre> <p>it would save a message area scroll if it was</p> <pre><...
[ { "answer_id": 9439, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": true, "text": "<p>Unfortunately you can't; this format is \"hardcoded\" (in <code>msg_show_console_dialog()</code>).</p>\n\n<p>But you ...
2016/09/03
[ "https://vi.stackexchange.com/questions/9432", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9087/" ]
Is there any way to have the confirm function place the choices on the same line as the msg prompt? ``` confirm("Yes no question", "&Yes\n&No", 2) ``` Instead of ``` Yes no question (Y)es, [N]o: ``` it would save a message area scroll if it was ``` Yes no question (Y)es, [N]o: ``` Docs mention adding `\n` to ...
Unfortunately you can't; this format is "hardcoded" (in `msg_show_console_dialog()`). But you can re-create a function which mostly behaves the same with [`getchar()`](http://vimhelp.appspot.com/eval.txt.html#getchar%28%29): ``` fun! Confirm(msg) echo a:msg . ' ' let l:answer = nr2char(getchar()) if l:an...
9,433
<p>I have two buffers in vim:</p> <pre><code>:ls 1 %a ".vimrc" line 1 2 #h "script.sh" line 1 Press ENTER or type command to continue </code></pre> <p>As seen above, I'm on the first buffer. Now if I execute the <code>:set softtabstop=16</code> command, then I expect i...
[ { "answer_id": 9434, "author": "Brian Tiffin", "author_id": 9087, "author_profile": "https://vi.stackexchange.com/users/9087", "pm_score": 2, "selected": false, "text": "<p>Not an expert, @Martin, but from reading <code>:help set</code> you would need to \"unset\" the local value of <cod...
2016/09/03
[ "https://vi.stackexchange.com/questions/9433", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8626/" ]
I have two buffers in vim: ``` :ls 1 %a ".vimrc" line 1 2 #h "script.sh" line 1 Press ENTER or type command to continue ``` As seen above, I'm on the first buffer. Now if I execute the `:set softtabstop=16` command, then I expect it to affect both buffers. However, th...
Options can be *global*, *window-local*, or *buffer-local*. When you `:set` a *global* option, the new value is *global*. When you `:setlocal` a *global* option, the new value is *local*. When you `:set` a *local* option, the new value is *local*. `softtabstop` being a *buffer-local* option, changing its value only...
9,455
<p>I understand how <a href="http://vimdoc.sourceforge.net/htmldoc/autocmd.html" rel="noreferrer">auto commands</a> work, and how to use them, but I'm somewhat unsure of what augroup is for. I read in <code>:help augroup</code></p> <pre><code> *:aug* *:augroup* :aug[ro...
[ { "answer_id": 9458, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 5, "selected": false, "text": "<p>Autocommand groups give you the opportunity to organize your autocommands, which is a quite useful feature in and of itself....
2016/09/06
[ "https://vi.stackexchange.com/questions/9455", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
I understand how [auto commands](http://vimdoc.sourceforge.net/htmldoc/autocmd.html) work, and how to use them, but I'm somewhat unsure of what augroup is for. I read in `:help augroup` ``` *:aug* *:augroup* :aug[roup] {name} Define the autocmd group na...
The main reason to use `augroup`s is to allow greater control over ranges of autocommands, e.g. to delete a bunch of autocommands in one go. A common pattern is to use the `au!` as the first part of a group. This removes all existing autocommands in the group, and allows one to start afresh. If you did not use a group,...
9,468
<p>I have installed <a href="https://github.com/Shougo/deoplete.nvim" rel="nofollow">deoplete</a> plugin into my Neovim using <a href="https://github.com/Shougo/dein.vim" rel="nofollow">dein</a>. I have put <code>let g:deoplete#enable_at_startup = 1</code> into my <code>init.vim</code> and I can see the autocomplete li...
[ { "answer_id": 9470, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 4, "selected": true, "text": "<p>Vim uses <code>Ctrl-n</code> (next item) and <code>Ctrl-p</code> (previous item), <code>Ctrl-y</code> (accept match) or ...
2016/09/06
[ "https://vi.stackexchange.com/questions/9468", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9149/" ]
I have installed [deoplete](https://github.com/Shougo/deoplete.nvim) plugin into my Neovim using [dein](https://github.com/Shougo/dein.vim). I have put `let g:deoplete#enable_at_startup = 1` into my `init.vim` and I can see the autocomplete list when I type in the insert mode - so far so good. However I am not able to ...
Vim uses `Ctrl-n` (next item) and `Ctrl-p` (previous item), `Ctrl-y` (accept match) or `Ctrl-e` (cancel) and so on for completion. See `:h ins-completion-menu` and `:h popupmenu-keys` for details. The following `deoplete` settings may help (they use `Tab`, `Enter` and `Esc`) - see the comments for what they do: ``` "...
9,481
<p>I want to access <a href="http://jupyter.org/" rel="noreferrer">Jupyter notebook</a> from inside vim.</p> <p>I have compile vim with Python support, and try this plugin <a href="http://github.com/ivanov/vim-ipython" rel="noreferrer">http://github.com/ivanov/vim-ipython</a>. The documentation suggest me to run :IPyt...
[ { "answer_id": 9483, "author": "maksay", "author_id": 7612, "author_profile": "https://vi.stackexchange.com/users/7612", "pm_score": 3, "selected": true, "text": "<p>This maybe not the answer to your question, but perhaps an answer to your problem with vim-ipython: you could try <a href=...
2016/09/07
[ "https://vi.stackexchange.com/questions/9481", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9171/" ]
I want to access [Jupyter notebook](http://jupyter.org/) from inside vim. I have compile vim with Python support, and try this plugin <http://github.com/ivanov/vim-ipython>. The documentation suggest me to run :IPython command. This seems to not working at all. Some thread on the internet give me a gist that probably ...
This maybe not the answer to your question, but perhaps an answer to your problem with vim-ipython: you could try <http://github.com/wilywampa/vim-ipython> It doesn't seem that it is too active either, but at least it works for me with Jupyter 5.0.0. Make sure to read the help thoroughly as there are several actions ...
9,486
<p>I have <code>Anaconda</code> (including python3.5.2), <code>VIM</code> (7.4) and <code>Jedi-VIM</code> installed on my system. There was also a <code>python</code> installed on the linux system by default.</p> <p>The autocompletion is working on base packages, at least. But for packages like <code>numpy</code> (whi...
[ { "answer_id": 9488, "author": "Sato Katsura", "author_id": 2313, "author_profile": "https://vi.stackexchange.com/users/2313", "pm_score": 2, "selected": false, "text": "<p>You can't. The <code>:python</code> and <code>:python3</code> commands always use the compiled-in interpreters. I...
2016/09/08
[ "https://vi.stackexchange.com/questions/9486", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9186/" ]
I have `Anaconda` (including python3.5.2), `VIM` (7.4) and `Jedi-VIM` installed on my system. There was also a `python` installed on the linux system by default. The autocompletion is working on base packages, at least. But for packages like `numpy` (which was included in `Anaconda`) the completion is not working. By...
I was able to fix it myself by providing `jedi-vim` with the location of the packages in my `anaconda` folder using the `$PYTHONPATH` variable as follows: ``` export PYTHONPATH=$PYTHONPATH:/home/user1/anaconda3/lib/python3.5/site-packages ``` Thanks to all! Or Add following line in ~/.bash\_profile `export PYTHONP...
9,494
<p>I just recently learned how to use folds and I find it very useful. I have added a rule to automatically save the view with my folds when I'm editing the markdown files with the rule:</p> <pre><code>augroup QuickNotes au BufWinLeave *.md mkview au BufWinEnter *.md silent loadview augroup END </code></pre> <p>B...
[ { "answer_id": 9488, "author": "Sato Katsura", "author_id": 2313, "author_profile": "https://vi.stackexchange.com/users/2313", "pm_score": 2, "selected": false, "text": "<p>You can't. The <code>:python</code> and <code>:python3</code> commands always use the compiled-in interpreters. I...
2016/09/09
[ "https://vi.stackexchange.com/questions/9494", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3254/" ]
I just recently learned how to use folds and I find it very useful. I have added a rule to automatically save the view with my folds when I'm editing the markdown files with the rule: ``` augroup QuickNotes au BufWinLeave *.md mkview au BufWinEnter *.md silent loadview augroup END ``` But when I have saved it an...
I was able to fix it myself by providing `jedi-vim` with the location of the packages in my `anaconda` folder using the `$PYTHONPATH` variable as follows: ``` export PYTHONPATH=$PYTHONPATH:/home/user1/anaconda3/lib/python3.5/site-packages ``` Thanks to all! Or Add following line in ~/.bash\_profile `export PYTHONP...
9,500
<p>I'm trying to do something fairly simple. I'm writing latex and I have all these blocks of code, that I'm trying to comment out (and disregard the words in the word count). So I have to write these lines a bazillion times:</p> <pre><code>%TC:ignore \iffalse </code></pre> <p>and this as well:</p> <pre><code>\fi %T...
[ { "answer_id": 9501, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": true, "text": "<p>Sure, you've got a couple options.</p>\n\n<p>Use an abbreviation:</p>\n\n<pre><code>iabbrev zlc %TC:ignore&lt;CR&gt;\\i...
2016/09/09
[ "https://vi.stackexchange.com/questions/9500", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9194/" ]
I'm trying to do something fairly simple. I'm writing latex and I have all these blocks of code, that I'm trying to comment out (and disregard the words in the word count). So I have to write these lines a bazillion times: ``` %TC:ignore \iffalse ``` and this as well: ``` \fi %TC:endignore ``` Is it possible to s...
Sure, you've got a couple options. Use an abbreviation: ``` iabbrev zlc %TC:ignore<CR>\iffalse ``` * If you type zlc`Enter` in insert mode it will fill in the text. * `iabbrev` is an abbreviation that only works in insert mode Use a function: ``` command! Zlc call Ignore() function! Ignore() normal! i%TC:ignor...
9,509
<p>When I'm executing an external command in silent mode in vim, when it returns the screen is blank and I need to redraw it.</p> <p>Here's how I solve it in the <code>.vimrc</code></p> <pre><code>nnoremap &lt;F5&gt; :silent :make&lt;CR&gt;:redr!&lt;CR&gt; </code></pre> <p>without the <code>redr!</code> the screen i...
[ { "answer_id": 9519, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 4, "selected": true, "text": "<p>This is by design. The <code>:help :!</code> (a closely related command) offers this:</p>\n\n<pre><code> Vim red...
2016/09/10
[ "https://vi.stackexchange.com/questions/9509", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/496/" ]
When I'm executing an external command in silent mode in vim, when it returns the screen is blank and I need to redraw it. Here's how I solve it in the `.vimrc` ``` nnoremap <F5> :silent :make<CR>:redr!<CR> ``` without the `redr!` the screen is blank and I have to press `Ctrl`+`l`in order to continue. Is it a bug,...
This is by design. The `:help :!` (a closely related command) offers this: ``` Vim redraws the screen after the command is finished, because it may have printed any text. This requires a hit-enter prompt, so that you can read any messages. To avoid this use: :silent !{cmd} ...
9,520
<p>I'm looking for a way that will highlight lines (or part of lines) that don't adhere to current tabs settings.</p> <p>Say for instance, I have the following configuration in my <code>.vimrc</code></p> <pre><code>tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab </code></pre> <p>Is it possible to highlight lines...
[ { "answer_id": 9521, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 2, "selected": false, "text": "<p>My <a href=\"http://www.vim.org/scripts/script.php?script_id=1690\" rel=\"nofollow\">IndentConsistencyCop plugin</a> c...
2016/09/12
[ "https://vi.stackexchange.com/questions/9520", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/496/" ]
I'm looking for a way that will highlight lines (or part of lines) that don't adhere to current tabs settings. Say for instance, I have the following configuration in my `.vimrc` ``` tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab ``` Is it possible to highlight lines that don't adhere to the above settings ?
My [IndentConsistencyCop plugin](http://www.vim.org/scripts/script.php?script_id=1690) checks the consistency of the used indent, and compares this with the buffer's indent settings. With a companion plugin, it can be triggered automatically for configured filetypes. (The plugin page has links to alternative plugins.)
9,522
<p>Vim 8 was released <a href="https://github.com/vim/vim/releases/tag/v8.0.0000" rel="noreferrer">today</a> and the <a href="https://raw.githubusercontent.com/vim/vim/master/runtime/doc/version8.txt" rel="noreferrer">release notes</a> mentions a new "package" feature. What is it and how should I use it?</p> <p>Most i...
[ { "answer_id": 9523, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 8, "selected": true, "text": "<p>First of all, the relevant documentation can be found with <a href=\"http://vimhelp.appspot.com/repeat.txt.html#packages\"...
2016/09/12
[ "https://vi.stackexchange.com/questions/9522", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
Vim 8 was released [today](https://github.com/vim/vim/releases/tag/v8.0.0000) and the [release notes](https://raw.githubusercontent.com/vim/vim/master/runtime/doc/version8.txt) mentions a new "package" feature. What is it and how should I use it? Most importantly, does it replace the good old [plugin managers](https:/...
First of all, the relevant documentation can be found with [`:h packages`](http://vimhelp.appspot.com/repeat.txt.html#packages) on the newly compiled Vim8 version and [here on Github](https://github.com/vim/vim/blob/856c1110c1cf0d6e44e387b70732/runtime/doc/repeat.txt#L525). A first important note is about the vocabula...
9,537
<p>I have a line that fits a "template", and multiple pieces of "data". For each piece of data, I want to copy the template and replace all occurrences of a pattern in that line with the data. I'm using the method below, but I want to know if there's a better (shorter, easier) way.</p> <p>Given this buffer (cursor is ...
[ { "answer_id": 9523, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 8, "selected": true, "text": "<p>First of all, the relevant documentation can be found with <a href=\"http://vimhelp.appspot.com/repeat.txt.html#packages\"...
2016/09/13
[ "https://vi.stackexchange.com/questions/9537", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1176/" ]
I have a line that fits a "template", and multiple pieces of "data". For each piece of data, I want to copy the template and replace all occurrences of a pattern in that line with the data. I'm using the method below, but I want to know if there's a better (shorter, easier) way. Given this buffer (cursor is at `|`): ...
First of all, the relevant documentation can be found with [`:h packages`](http://vimhelp.appspot.com/repeat.txt.html#packages) on the newly compiled Vim8 version and [here on Github](https://github.com/vim/vim/blob/856c1110c1cf0d6e44e387b70732/runtime/doc/repeat.txt#L525). A first important note is about the vocabula...
9,543
<p>Looking at the <a href="https://github.com/vim/vim/blob/89bcfda6834aba724d12554a34b9ed49f5789fd5/runtime/ftplugin/markdown.vim" rel="noreferrer">ftplugin file for markdown</a> in Vim, it certainly appears that folding is supported, but I cannot get folding to work.</p> <p>If I have some content like this:</p> <pre...
[ { "answer_id": 9544, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": false, "text": "<h2> Markdown folding: </h2>\n\n<p>As ana found out, for markdown specifically make sure that you have <code>let g:markdo...
2016/09/14
[ "https://vi.stackexchange.com/questions/9543", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9258/" ]
Looking at the [ftplugin file for markdown](https://github.com/vim/vim/blob/89bcfda6834aba724d12554a34b9ed49f5789fd5/runtime/ftplugin/markdown.vim) in Vim, it certainly appears that folding is supported, but I cannot get folding to work. If I have some content like this: ``` # A heading Some content. More content. ...
Markdown folding: ------------------ As ana found out, for markdown specifically make sure that you have `let g:markdown_folding = 1` or folding wont be "turned on". General folding tips: --------------------- Vim won't fold automatically, try putting your cursor over the text and doing `zc`. This should close the f...
9,560
<p>This is probably easier to explain with an example. I prefer expressing things like</p> <pre><code>const array = { a: 1, b: 2, c: 3 } </code></pre> <p>on a single line at first but eventually I might want to switch to</p> <pre><code>const array = { a: 1, b: 2, c: 3, d: 4, } </code></pre> <p>as the array ...
[ { "answer_id": 9561, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 1, "selected": false, "text": "<p>Here is a slight workaround, which is interesting to learn new functionalities and can solve your problem:</p>\n\n<p>If yo...
2016/09/15
[ "https://vi.stackexchange.com/questions/9560", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9283/" ]
This is probably easier to explain with an example. I prefer expressing things like ``` const array = { a: 1, b: 2, c: 3 } ``` on a single line at first but eventually I might want to switch to ``` const array = { a: 1, b: 2, c: 3, d: 4, } ``` as the array gets longer. I realized that I'm not doing this v...
There's a plugin called SplitJoin.vim that aims to address exactly your problem. Find it here: <https://github.com/AndrewRadev/splitjoin.vim>
9,573
<p>I'm had some trouble defining a mapping in my .vimrc. I want <code>&lt;leader&gt;sv</code> to source my .vimrc, but first I want to write, if I'm currently editing it.</p> <h3>Goal</h3> <p>The intention of the code is this:</p> <pre><code>if expand('%:p') ==? expand($MYVIMRC) write endif source $MYVIMRC&lt;cr...
[ { "answer_id": 9574, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 0, "selected": false, "text": "<p>You can use pipes for mappings, but I would recomend just wrapping it all in a function. Something like:</p>\n\n<pre><...
2016/09/16
[ "https://vi.stackexchange.com/questions/9573", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9267/" ]
I'm had some trouble defining a mapping in my .vimrc. I want `<leader>sv` to source my .vimrc, but first I want to write, if I'm currently editing it. ### Goal The intention of the code is this: ``` if expand('%:p') ==? expand($MYVIMRC) write endif source $MYVIMRC<cr> ``` ### Attempt 1 I tried writing my comm...
This is where `<expr>` mappings are useful. From `:h <expr>` ``` *:map-<expr>* *:map-expression* If the first argument to one of these commands is "<expr>" and it is used to define a new mapping or abbreviation, the argument is an expression. The expression is evaluated to obtain the {rhs} tha...
9,604
<p>How can I make it so when in visual mode, pressing <code>b</code> will toggle highlighted text to its bold unicode counterpart?</p> <p>This is what I mean by its Unicode counterpart:</p> <p><a href="http://qaz.wtf/u/convert.cgi?text=Boat+Programming+should+be+a+valid+SE+Tag" rel="nofollow">http://qaz.wtf/u/convert...
[ { "answer_id": 9605, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 2, "selected": true, "text": "<p>Create a mapping like this so that you can press a key and it will call the function which converts the text for you.</...
2016/09/20
[ "https://vi.stackexchange.com/questions/9604", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7960/" ]
How can I make it so when in visual mode, pressing `b` will toggle highlighted text to its bold unicode counterpart? This is what I mean by its Unicode counterpart: <http://qaz.wtf/u/convert.cgi?text=Boat+Programming+should+be+a+valid+SE+Tag> For example: --- Formatting done with markup **SE bold** *SE Italic* ...
Create a mapping like this so that you can press a key and it will call the function which converts the text for you. ``` :vmap b :call MakeMeBold() ``` Let's create a function now. ``` :function MakeMeBold() :normal! gv"by :let @b=substitute (@b,"a","A","g") . :normal! gv"bp :endfuncti...
9,606
<p>I just followed these instructions to compile vim with python 3: <a href="https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source" rel="noreferrer">https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source</a></p> <p>After the install I checked to see if I have python3:</p> <pre><code...
[ { "answer_id": 9607, "author": "Sato Katsura", "author_id": 2313, "author_profile": "https://vi.stackexchange.com/users/2313", "pm_score": 3, "selected": true, "text": "<p>This is the expected result. There are no tests <code>has('python/dyn')</code> and <code>has('python3/dyn')</code>,...
2016/09/20
[ "https://vi.stackexchange.com/questions/9606", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9347/" ]
I just followed these instructions to compile vim with python 3: <https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source> After the install I checked to see if I have python3: ``` vim --version | grep "python" ``` Which returned: ``` +python3/dyn ``` and ``` +python/dyn ``` But when I st...
This is the expected result. There are no tests `has('python/dyn')` and `has('python3/dyn')`, only `has('python')` and `has('python3')`.
9,609
<p>I have installed plugins YouCompleteMe and python-mode so as to use the auto-completion when editing a python file. But when I open an <code>.py</code> file and type <kbd>.</kbd> in insert mode, the cursor does not move forward as it does in any other case. Then I type a letter and it appears <strong>before</strong>...
[ { "answer_id": 9625, "author": "Romapecker", "author_id": 9349, "author_profile": "https://vi.stackexchange.com/users/9349", "pm_score": 0, "selected": false, "text": "<p>I copied a <code>.vimrc</code> file to my computer from another computer where the auto-completion works. It turned o...
2016/09/20
[ "https://vi.stackexchange.com/questions/9609", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9349/" ]
I have installed plugins YouCompleteMe and python-mode so as to use the auto-completion when editing a python file. But when I open an `.py` file and type `.` in insert mode, the cursor does not move forward as it does in any other case. Then I type a letter and it appears **before** the dot, which makes auto-completio...
For anyone else stumbling upon this; the reason why `:iunmap` didn't work is found in `:help E31`: ``` - If the mapping is buffer-local you need to use ":unmap <buffer>". ``` YouCompleteMe seems to just set everything buffer-locally (after all, why shouldn't it?). When vim throws an error message like `E31: No such...
9,616
<p><a href="https://i.stack.imgur.com/gssQ0.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/gssQ0.jpg" alt="enter image description here"></a></p> <p>I don't know why my gvim windows looks like this in linux. Is there anything I need to add to my vimrc file in addition to this?</p> <pre><code>execute pathog...
[ { "answer_id": 9619, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": false, "text": "<p>The problem is probably that you don't have the Consolas font installed and that Vim defaults to an ugly default fon...
2016/09/21
[ "https://vi.stackexchange.com/questions/9616", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6706/" ]
[![enter image description here](https://i.stack.imgur.com/gssQ0.jpg)](https://i.stack.imgur.com/gssQ0.jpg) I don't know why my gvim windows looks like this in linux. Is there anything I need to add to my vimrc file in addition to this? ``` execute pathogen#infect() syntax on filetype plugin indent on set nocompatibl...
The problem is probably that you don't have the Consolas font installed and that Vim defaults to an ugly default font. Try using a different font, for example this should work on most Linux systems: ``` set guifont=Dejavu\ Sans\ Mono\ 12 ``` If you want it to work on both Windows and Linux you can use something lik...
9,631
<p>I have the following line in my vimrc:</p> <pre><code>autocmd Filetype html setlocal tabstop=8 softtabstop=8 shiftwidth=8 expandtab </code></pre> <p>Doesn't count for anything when I open an html file:</p> <pre><code>:set expandtab? sts? noexpandtab softtabstop=0 </code></pre> <p>How can I go about figuring out ...
[ { "answer_id": 9632, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>Run <code>:verbose set &lt;name&gt;</code>, e.g.:</p>\n\n<pre><code>:verbose set tabstop\ntabstop=4\n Last set f...
2016/09/21
[ "https://vi.stackexchange.com/questions/9631", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9376/" ]
I have the following line in my vimrc: ``` autocmd Filetype html setlocal tabstop=8 softtabstop=8 shiftwidth=8 expandtab ``` Doesn't count for anything when I open an html file: ``` :set expandtab? sts? noexpandtab softtabstop=0 ``` How can I go about figuring out what is resetting `expandtab` and `softtabstop`? ...
Run `:verbose set <name>`, e.g.: ``` :verbose set tabstop tabstop=4 Last set from ~/.vim/settings.vim ``` `:verbose` also works with other commands (e.g. `:map`). See [`:help :verbose`](http://vimhelp.appspot.com/various.txt.html#%3averbose).
9,644
<p>How can one use a variable when executing something via <code>normal!</code> in vimscript?</p> <p><strong>Example:</strong> </p> <pre><code>function! MyFunction(someArg) normal! (a:someArg)l endfunction </code></pre> <p>This should move the cursor <code>someArg</code> steps to the right.</p>
[ { "answer_id": 9645, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>The <code>execute</code> function takes a string as argument, it expands the string and execute it a a regular ex command....
2016/09/22
[ "https://vi.stackexchange.com/questions/9644", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
How can one use a variable when executing something via `normal!` in vimscript? **Example:** ``` function! MyFunction(someArg) normal! (a:someArg)l endfunction ``` This should move the cursor `someArg` steps to the right.
The `execute` function takes a string as argument, it expands the string and execute it a a regular ex command. Thus you can do: ``` function! MyFunction(someArg) execute "normal! ". a:someArg. "l" endfunction ``` The `.` is a standard vimscript operator to concatenate strings. `execute` can be shortened to ...
9,653
<p>From <strong><a href="https://vi.stackexchange.com/a/2002/4652">How do I jump to the location of my last edit?</a></strong></p> <p>I can press:</p> <pre><code>`. </code></pre> <p>to take my cursor to the position of last edit but:</p> <pre><code>`` </code></pre> <p>doesn't take me to the last position of my cur...
[ { "answer_id": 9654, "author": "Insane", "author_id": 4652, "author_profile": "https://vi.stackexchange.com/users/4652", "pm_score": 2, "selected": false, "text": "<p>As an alternative I found and downloaded the plugin <a href=\"https://github.com/farmergreg/vim-lastplace/\" rel=\"nofoll...
2016/09/24
[ "https://vi.stackexchange.com/questions/9653", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4652/" ]
From **[How do I jump to the location of my last edit?](https://vi.stackexchange.com/a/2002/4652)** I can press: ``` `. ``` to take my cursor to the position of last edit but: ``` `` ``` doesn't take me to the last position of my cursor, as it says it should in the question / answer linked above. > > There is ...
That link addresses a different use case so it only *partially* applies. 1. The "single quote" and "single backtick" marks are not saved between sessions so there's no reason to expect ```` to work its magic in your specific example. 2. ```` moves the cursor to the position before the last **"jump"**. Since you are mo...
9,662
<p>I do quite often use this mapping:</p> <pre><code>autocmd FileType cpp nnoremap &lt;buffer&gt; == :%!clang-format -style=file&lt;cr&gt;2g;zz </code></pre> <p>It reindents the whole file and returns the cursor to the last edit position.</p> <p>Problem is, if I have folds, they get closed. All of them.</p> <p>How do I...
[ { "answer_id": 9663, "author": "Dalker", "author_id": 2058, "author_profile": "https://vi.stackexchange.com/users/2058", "pm_score": 1, "selected": false, "text": "<p>EDIT: Here's something that might solve the issue.\nIt's really a template of a possible solution (not actually tested).<...
2016/09/24
[ "https://vi.stackexchange.com/questions/9662", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3280/" ]
I do quite often use this mapping: ``` autocmd FileType cpp nnoremap <buffer> == :%!clang-format -style=file<cr>2g;zz ``` It reindents the whole file and returns the cursor to the last edit position. Problem is, if I have folds, they get closed. All of them. How do I keep each fold's state after this command? [Som...
Here is how I did it: ``` autocmd FileType cpp nnoremap <buffer> == :mkview<cr>:%!clang-format -style=file<cr>:loadview<cr> ```
9,672
<p>I want to do the following:</p> <p>When I insert an HTML tag (which is a sequence of text that starts with <code>&lt;tagname tag_attributes</code> and ends with <code>&gt;</code>), as soon as I press <kbd>></kbd> to insert the <code>&gt;</code> character, I want:</p> <ol> <li>A text <code>&lt;/tagname&gt;</code> t...
[ { "answer_id": 9673, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": false, "text": "<p>Here is a simple <em>ad-hoc</em> solution to put in <code>~/.vim/after/ftplugin/html.vim</code>:</p>\n\n<pre><code>inoremap ...
2016/09/25
[ "https://vi.stackexchange.com/questions/9672", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4840/" ]
I want to do the following: When I insert an HTML tag (which is a sequence of text that starts with `<tagname tag_attributes` and ends with `>`), as soon as I press `>` to insert the `>` character, I want: 1. A text `</tagname>` to be inserted two lines under the current line. 2. Put the cursor on the line which is b...
Here is a simple *ad-hoc* solution to put in `~/.vim/after/ftplugin/html.vim`: ``` inoremap <buffer> > ></<C-x><C-o><C-y><C-o>%<CR><C-o>O ``` Breakdown: ``` ></ insert '></' <C-x><C-o><C-y> use the built-in omni-completion to finish the closing tag <C-o>% move the cursor to the beginni...
9,674
<p>I'd like to bind some combinations to <code>Alt-_some-key_</code>, but not quite sure about how to do it correctly. Here is one of my current setup (example):</p> <pre><code>vnoremap &lt;ESC&gt;c "+y </code></pre> <p>This is because my terminal accept <code>Alt-c</code> as <code>&lt;ESC&gt;c</code>. But I suppose ...
[ { "answer_id": 9678, "author": "Dalker", "author_id": 2058, "author_profile": "https://vi.stackexchange.com/users/2058", "pm_score": 2, "selected": false, "text": "<p>You could define a global variable containing the key that might change, and then use an <a href=\"http://learnvimscriptt...
2016/09/25
[ "https://vi.stackexchange.com/questions/9674", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9417/" ]
I'd like to bind some combinations to `Alt-_some-key_`, but not quite sure about how to do it correctly. Here is one of my current setup (example): ``` vnoremap <ESC>c "+y ``` This is because my terminal accept `Alt-c` as `<ESC>c`. But I suppose it's not portable. Is there a way to specify some alias (like `Alt`) a...
From [`:h keycodes`](http://vimdoc.sourceforge.net/htmldoc/intro.html#keycodes) and more precisely [`:h meta`](http://vimdoc.sourceforge.net/htmldoc/intro.html#meta): > > `<M-...>` alt-key or meta-key > > > So on most system the mapping you're looking for is: ``` vnoremap <M-c> "+y ``` Note that the behavior ...
9,676
<p>I would like to have a <strong>Paste + Override</strong> shortcut, which should basically have the behaviour of going into <strong>Replace</strong>-mode, typing everything currently in the clipboard, exiting <strong>Replace</strong>-mode. </p> <p>How can I approach this?</p>
[ { "answer_id": 9678, "author": "Dalker", "author_id": 2058, "author_profile": "https://vi.stackexchange.com/users/2058", "pm_score": 2, "selected": false, "text": "<p>You could define a global variable containing the key that might change, and then use an <a href=\"http://learnvimscriptt...
2016/09/25
[ "https://vi.stackexchange.com/questions/9676", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I would like to have a **Paste + Override** shortcut, which should basically have the behaviour of going into **Replace**-mode, typing everything currently in the clipboard, exiting **Replace**-mode. How can I approach this?
From [`:h keycodes`](http://vimdoc.sourceforge.net/htmldoc/intro.html#keycodes) and more precisely [`:h meta`](http://vimdoc.sourceforge.net/htmldoc/intro.html#meta): > > `<M-...>` alt-key or meta-key > > > So on most system the mapping you're looking for is: ``` vnoremap <M-c> "+y ``` Note that the behavior ...
9,684
<p>Say in Gvim I have a line in the current buffer:</p> <pre><code>~/.bashrc </code></pre> <p>How can I access this file (<code>~/.bashrc</code>) in the same, or a new, or a vertical-split window?</p> <p>I tried <code>gx</code>, which opens the file with <code>xdg-open</code>. It opens the file in a new Gvim session...
[ { "answer_id": 9685, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": true, "text": "<p>The whole point of <code>gx</code> is to open the file under the cursor <em>in an external program.</em></p>\n\n<p>Use <code>...
2016/09/26
[ "https://vi.stackexchange.com/questions/9684", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9018/" ]
Say in Gvim I have a line in the current buffer: ``` ~/.bashrc ``` How can I access this file (`~/.bashrc`) in the same, or a new, or a vertical-split window? I tried `gx`, which opens the file with `xdg-open`. It opens the file in a new Gvim session / instance, rather than in the current one.
The whole point of `gx` is to open the file under the cursor *in an external program.* Use `gf` to open the file in a new buffer. Use `<C-w><C-f>` to open it in a new horizontal window then use `<C-w>L` to turn that window into a vertical one.
9,692
<p>In an unusual state, I want to ensure that a user sees a warning message upon startup, and presses a key to continue.</p> <p>I could use <code>sleep &lt;seconds&gt;</code>, but I'm sure that <code>vim</code> can do this. Go vim!</p>
[ { "answer_id": 9696, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 4, "selected": false, "text": "<p>You can use the <code>input</code> function, e.g.</p>\n\n<pre><code>call input('Press any key to continue')\n</cod...
2016/09/27
[ "https://vi.stackexchange.com/questions/9692", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5324/" ]
In an unusual state, I want to ensure that a user sees a warning message upon startup, and presses a key to continue. I could use `sleep <seconds>`, but I'm sure that `vim` can do this. Go vim!
You can use the `input` function, e.g. ``` call input('Press any key to continue') ``` See [`:h input()`](http://vimdoc.sourceforge.net/htmldoc/eval.html#input()).
9,693
<p>I've recently learned about Vim's omnicompletion and while attempting to make it work, I get the error <code>Pattern not found</code>. To test it I used the following code:</p> <pre><code>class C def hello puts "Hello, World!" end def goodbye puts "Goodbye, cruel world!" end end x = C.new x.&lt;C-...
[ { "answer_id": 9697, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 1, "selected": false, "text": "<p>Are you using any kind of auto-completion plugin, like neocomplete/YouCompleteMe? I also use Arch Linux and for me it gi...
2016/09/27
[ "https://vi.stackexchange.com/questions/9693", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8251/" ]
I've recently learned about Vim's omnicompletion and while attempting to make it work, I get the error `Pattern not found`. To test it I used the following code: ``` class C def hello puts "Hello, World!" end def goodbye puts "Goodbye, cruel world!" end end x = C.new x.<C-x><C-o> ``` Which gives th...
Just solved my problem. Not 100% sure how, but I'll do my best to explain all the steps I took: 1. Installed Vundle and configured it to manage vim-ruby and neocomplete, ran `:PluginInstall` and `:PluginUpdate` a few times, tried rebooting 2. Added the following lines to my .vimrc, found in another thread: ``` autoc...
9,694
<p>I saw the so called <code>&lt;Leader&gt;</code> in my <code>vimrc</code> quite often. But is there a way to define my own key in a similar manner? I mean I would like to define some sort of <code>&lt;Mykey&gt;</code> and use it further in my <code>vimrc</code> to define more complicated combinations. I mean somethin...
[ { "answer_id": 9695, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>You can define your own <code>&lt;leader&gt;</code> key with:</p>\n\n<pre><code>let mapleader = \"something\"\n</code></pre>...
2016/09/27
[ "https://vi.stackexchange.com/questions/9694", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9237/" ]
I saw the so called `<Leader>` in my `vimrc` quite often. But is there a way to define my own key in a similar manner? I mean I would like to define some sort of `<Mykey>` and use it further in my `vimrc` to define more complicated combinations. I mean something like this: ``` nnoremap <Mykey>u "some keystroke ``` T...
You can define your own `<leader>` key with: ``` let mapleader = "something" ``` You could also hack the `<localleader>` to get a second `<leader>`: ``` let localleader = "something else" ``` But `<leader>` and `<localleader>` are not special keys *at all*. Assuming your `<leader>` is set to `,` (the example in `...
9,700
<p>Normally, a substitute with the <code>c</code> option gives me two options: (y)es or (n)o. Is it possible to have several numbered yes options to choose from?</p> <p><strong>Example</strong></p> <p><strong>File</strong></p> <pre><code>person: Alice dog: Tobby person: Bob </code></pre> <p><strong>Pattern 1</stron...
[ { "answer_id": 9703, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 5, "selected": true, "text": "<p>The implementation of <code>:s//c</code> is fixed; what you're looking for is replacement with a Vimscript expression (...
2016/09/27
[ "https://vi.stackexchange.com/questions/9700", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9449/" ]
Normally, a substitute with the `c` option gives me two options: (y)es or (n)o. Is it possible to have several numbered yes options to choose from? **Example** **File** ``` person: Alice dog: Tobby person: Bob ``` **Pattern 1** `:%s/person:/woman:/c` **Pattern 2** `:%s/person:/man:/c` Pattern 1 and 2 have the ...
The implementation of `:s//c` is fixed; what you're looking for is replacement with a Vimscript expression (`:help sub-replace-expr`). You can query a single-digit via `getchar()`, or prompt for longer numbers via `input()`: ``` :%s/person:/\=get(['woman', 'man'], getchar() - char2nr(1), submatch(0)) . ':'/ :%s/person...
9,715
<p>When refactoring I sometimes do too much at once—all little steps, but I forget to commit after each little change.</p> <p>Of course in many cases a commit after <em>each</em> change would be too much, but if each individual change were initially made as a separate commit, it would be very easy to <code>git rebase<...
[ { "answer_id": 9723, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 2, "selected": false, "text": "<p>I would recommend one of the <em>undo tree visualizer plugins</em>:</p>\n\n<ul>\n<li><a href=\"https://github.com/mbbi...
2016/09/28
[ "https://vi.stackexchange.com/questions/9715", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
When refactoring I sometimes do too much at once—all little steps, but I forget to commit after each little change. Of course in many cases a commit after *each* change would be too much, but if each individual change were initially made as a separate commit, it would be very easy to `git rebase` them to combine them ...
Here's a quick and dirty function that does what you request: ``` function! UndoCommits(steps) for i in range(a:steps) undo endfor for i in range(a:steps) write execute printf('!silent git commit -am "%s"', "undo-commit" . i) redo endfor write execute printf('!s...
9,717
<p>I'm trying to change the location of the <code>viminfo</code> file.</p> <p>Why does the value of <code>&amp;viminfo</code> revert after it is set in <code>vimrc</code>?</p> <p><strong>TL;DR:</strong></p> <p>In my <code>vimrc</code> I have:</p> <pre><code>set nocompatible exec "set viminfo+=n".expand($XDG_DATA_HO...
[ { "answer_id": 9744, "author": "Tom Hale", "author_id": 5324, "author_profile": "https://vi.stackexchange.com/users/5324", "pm_score": 4, "selected": true, "text": "<p><strong>TL;DR</strong></p>\n\n<p>This seems to be a bug in <code>vim</code> where <code>set nocompatible</code> is not <...
2016/09/28
[ "https://vi.stackexchange.com/questions/9717", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5324/" ]
I'm trying to change the location of the `viminfo` file. Why does the value of `&viminfo` revert after it is set in `vimrc`? **TL;DR:** In my `vimrc` I have: ``` set nocompatible exec "set viminfo+=n".expand($XDG_DATA_HOME)."/vim/viminfo" echom &viminfo ``` I've noticed that `echo &viminfo` from command mode show...
**TL;DR** This seems to be a bug in `vim` where `set nocompatible` is not [idempotent](https://en.wikipedia.org/wiki/Idempotence) and doesn't follow the [principle of least astonishment](https://en.wikipedia.org/wiki/Principle_of_least_astonishment). As a workaround, either: 1. Ensure that you `set nocompatible` (or...
9,718
<p>I tried to bind the following to insert a line after the line I'm currently on. Here it is:</p> <pre><code>nnoremap &lt;CR&gt; o&lt;ESC&gt;k </code></pre> <p>But this works weird. After inserting a new line cursor is at the beginning of the line I was on. </p> <p>Is there a way to insert a new line in normal mode...
[ { "answer_id": 9719, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 2, "selected": false, "text": "<p>Almost every time you move your cursor, the previous location is added to \"the jumplist\". Using <code>&lt;C-o&gt;</...
2016/09/28
[ "https://vi.stackexchange.com/questions/9718", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9237/" ]
I tried to bind the following to insert a line after the line I'm currently on. Here it is: ``` nnoremap <CR> o<ESC>k ``` But this works weird. After inserting a new line cursor is at the beginning of the line I was on. Is there a way to insert a new line in normal mode and stay at the same position?
*That's odd, I was quite sure to have already answered this question twice. It may have been on [SO](https://stackoverflow.com/a/3171023/15934)...* Anyway. Use `append()`. It won't move the cursor or alter more registers than necessary. ``` " This also supports counts. Try 3<cr> :nnoremap <buffer> <cr> :<C-U>call app...
9,750
<p>When switching buffers with <code>:e#</code> or <code>&lt;ctrl&gt;-^</code>, I commonly see the line with the cursor (the current line) move to the middle of the window (maybe related to the <code>scroll_cursor_halfway</code> function mentioned <a href="https://vi.stackexchange.com/questions/8992">in this question</...
[ { "answer_id": 9765, "author": "jrw32982", "author_id": 9490, "author_profile": "https://vi.stackexchange.com/users/9490", "pm_score": 1, "selected": false, "text": "<p>I can't answer why it happens, but the way I'm currently making it more consistent:</p>\n\n<pre><code>map &lt;SPACE&gt;...
2016/09/29
[ "https://vi.stackexchange.com/questions/9750", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9490/" ]
When switching buffers with `:e#` or `<ctrl>-^`, I commonly see the line with the cursor (the current line) move to the middle of the window (maybe related to the `scroll_cursor_halfway` function mentioned [in this question](https://vi.stackexchange.com/questions/8992)?). I'm used to this, and it can be very convenient...
I can't answer why it happens, but the way I'm currently making it more consistent: ``` map <SPACE> :e#<CR>z.0 ``` This maps the spacebar to switch to the [alternate file](http://vimdoc.sourceforge.net/htmldoc/editing.html#alternate-file), then move the line with the cursor to the middle of the screen and finally mo...
9,754
<p>I am using vim 7.4.52 in Ubuntu 14.04 LTS.My vim background color is darkblue. I set this in .vimrc using <code>set background darkblue</code></p> <p>Now I want to set the background color with another color using hex code.</p> <p>Is there any system to set this? i.e.<code>set background=#300A24</code>(this is my ...
[ { "answer_id": 9755, "author": "Dalker", "author_id": 2058, "author_profile": "https://vi.stackexchange.com/users/2058", "pm_score": 3, "selected": false, "text": "<p>To set the background (and foreground) to some explicit color, you probably want to use a <code>highlight</code> command ...
2016/09/30
[ "https://vi.stackexchange.com/questions/9754", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9498/" ]
I am using vim 7.4.52 in Ubuntu 14.04 LTS.My vim background color is darkblue. I set this in .vimrc using `set background darkblue` Now I want to set the background color with another color using hex code. Is there any system to set this? i.e.`set background=#300A24`(this is my default terminal color)
To set the background (and foreground) to some explicit color, you probably want to use a `highlight` command in your vimrc, such as ``` " plain text hi Normal ctermfg=227 ctermbg=17 ``` (assuming you are indeed in a terminal and not a gvim window). The color codes '227' and '17' are interpreted in the terminal...
9,757
<p>I am using Vundle on Windows gVim. I have a plugin that I am writing myself called hotdogstand that is stored in my local filesystem at <code>vimfiles\hotdogstand</code>, and it is not tied to a Github repository. How do I load this plugin in Vundle? I tried using:</p> <pre><code>Plugin 'file:///Users/snrub/vimfile...
[ { "answer_id": 9758, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>From the Vundle <a href=\"https://github.com/VundleVim/Vundle.vim\" rel=\"nofollow\">README</a> and from <a href=\"https:...
2016/09/30
[ "https://vi.stackexchange.com/questions/9757", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9047/" ]
I am using Vundle on Windows gVim. I have a plugin that I am writing myself called hotdogstand that is stored in my local filesystem at `vimfiles\hotdogstand`, and it is not tied to a Github repository. How do I load this plugin in Vundle? I tried using: ``` Plugin 'file:///Users/snrub/vimfiles/bundle/Vundle.vim/hotdo...
Below left is downloaded zip format of a plugin, right is created by 'get clone <https://plugin/path>' command in Git Bash. Left is equivalent to the plugin you wrote locally. Although the plugin itself is the same, 'get clone' command will also create .git directory which contains git repo files. [![enter image ...
9,760
<p>When I hit the arrow keys in insert mode I get characters instead of navigation:</p> <p><a href="https://i.stack.imgur.com/TeW9I.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/TeW9I.gif" alt="Pressing arrow keys types characters" /></a></p> <p>I'd like to be able to use the arrow keys to navigate.</p> <hr...
[ { "answer_id": 14438, "author": "Mikhail Vasin", "author_id": 15461, "author_profile": "https://vi.stackexchange.com/users/15461", "pm_score": 3, "selected": false, "text": "<p>Updating the <code>vim</code> package fixed the broken arrows issue for me.</p>\n\n<p>If you are on Ubuntu, run...
2016/09/30
[ "https://vi.stackexchange.com/questions/9760", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
When I hit the arrow keys in insert mode I get characters instead of navigation: [![Pressing arrow keys types characters](https://i.stack.imgur.com/TeW9I.gif)](https://i.stack.imgur.com/TeW9I.gif) I'd like to be able to use the arrow keys to navigate. --- Things I've tried ================= I have `set nocompatibl...
What's causing the behaviour ============================ When you press the left arrow, your terminal is sending the following escape sequence: ``` ESC O D ``` This can also be notated as `^[OD`, where `^[` is notation for `Ctrl-[`, which is another way of notating or entering the ESC character. (Try it in insert ...
9,764
<p>When making a digraph, I can't seem use the <code>¨</code> symbol without getting an <code>E39: Number expected</code>. This error is there even when escaping it with a backslash. </p>
[ { "answer_id": 14438, "author": "Mikhail Vasin", "author_id": 15461, "author_profile": "https://vi.stackexchange.com/users/15461", "pm_score": 3, "selected": false, "text": "<p>Updating the <code>vim</code> package fixed the broken arrows issue for me.</p>\n\n<p>If you are on Ubuntu, run...
2016/09/30
[ "https://vi.stackexchange.com/questions/9764", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5285/" ]
When making a digraph, I can't seem use the `¨` symbol without getting an `E39: Number expected`. This error is there even when escaping it with a backslash.
What's causing the behaviour ============================ When you press the left arrow, your terminal is sending the following escape sequence: ``` ESC O D ``` This can also be notated as `^[OD`, where `^[` is notation for `Ctrl-[`, which is another way of notating or entering the ESC character. (Try it in insert ...
9,766
<p>I have three macros that I have created separately over time. <code>a</code> performs a search and replace, <code>b</code> adds tags to every line and <code>c</code> appends text at the beginning and the end of the file.</p> <p>I execute them like this:</p> <p><code>@a</code></p> <p><code>:%norm! @b</code></p> <...
[ { "answer_id": 14438, "author": "Mikhail Vasin", "author_id": 15461, "author_profile": "https://vi.stackexchange.com/users/15461", "pm_score": 3, "selected": false, "text": "<p>Updating the <code>vim</code> package fixed the broken arrows issue for me.</p>\n\n<p>If you are on Ubuntu, run...
2016/09/30
[ "https://vi.stackexchange.com/questions/9766", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1328/" ]
I have three macros that I have created separately over time. `a` performs a search and replace, `b` adds tags to every line and `c` appends text at the beginning and the end of the file. I execute them like this: `@a` `:%norm! @b` `@c` How can I execute them in this order without starting each one separately?
What's causing the behaviour ============================ When you press the left arrow, your terminal is sending the following escape sequence: ``` ESC O D ``` This can also be notated as `^[OD`, where `^[` is notation for `Ctrl-[`, which is another way of notating or entering the ESC character. (Try it in insert ...