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 |
|---|---|---|---|---|---|---|
4,031 | <p>Sometimes I use marks to navigate easily through different files using <code>mA</code>, <code>mB</code>... and <code>'A</code>, <code>'B</code>...</p>
<p>And sometime (more often than I'd like to admit) because of inattention or whatever the reason is, I use <code>m[LETTER]</code> with an already existing mark whic... | [
{
"answer_id": 4032,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 4,
"selected": true,
"text": "<p>Here is some basic VimScript which roughly does what you want.</p>\n\n<p>We override the <code>ma</code> through <cod... | 2015/07/24 | [
"https://vi.stackexchange.com/questions/4031",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | Sometimes I use marks to navigate easily through different files using `mA`, `mB`... and `'A`, `'B`...
And sometime (more often than I'd like to admit) because of inattention or whatever the reason is, I use `m[LETTER]` with an already existing mark which erase its previous value when I don't want to. Most of the time... | Here is some basic VimScript which roughly does what you want.
We override the `ma` through `mz` mappings to store the current value in `g:previous_marks` before calling the original `m` to actually set the mark. We also define `<Leader>ma` through `<Leader>mz` to show the history for said mark.
You will probably wan... |
4,050 | <p>I am using vim to edit latex documents. Often, I will want to change the name of a variable to something else. However, it's a little annoying to have to wade through irrelevant matches when I search for the variable name. I would like to search only in "math zones" as defined in the tex syntax file. Is there an eas... | [
{
"answer_id": 4051,
"author": "Peter Lewerin",
"author_id": 2942,
"author_profile": "https://vi.stackexchange.com/users/2942",
"pm_score": 1,
"selected": false,
"text": "<p>If you're searching for the string <code>foo</code> inside <code>$...$</code> or <code>$$...$$</code>, this should... | 2015/07/28 | [
"https://vi.stackexchange.com/questions/4050",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2976/"
] | I am using vim to edit latex documents. Often, I will want to change the name of a variable to something else. However, it's a little annoying to have to wade through irrelevant matches when I search for the variable name. I would like to search only in "math zones" as defined in the tex syntax file. Is there an easy w... | Here is a function that you could try. I've only tested it a little bit but it seems to work ok.
```
function! JJSyntaxSearch(pattern, syntaxitem)
while search(a:pattern, 'W') > 0
for id in synstack(line("."),col("."))
if synIDattr(id,"name") =~? a:syntaxitem
return line(".")
endif
endfor... |
4,054 | <p>I like the behavior of the <code>'smartcase'</code> option, which lets searches I type in by hand be case-insensitive by default, case-sensitive when there are any capital letters. I also like the behavior of the <code>'noignorecase'</code> option, which lets searches generated by the editor (as when hitting <code>*... | [
{
"answer_id": 4055,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 5,
"selected": true,
"text": "<p>You can fix that for the <code>*</code> command by putting the following mapping in your <code>~/.vimrc</code>.</p>\n\n<... | 2015/07/28 | [
"https://vi.stackexchange.com/questions/4054",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2982/"
] | I like the behavior of the `'smartcase'` option, which lets searches I type in by hand be case-insensitive by default, case-sensitive when there are any capital letters. I also like the behavior of the `'noignorecase'` option, which lets searches generated by the editor (as when hitting `*` or `#`) be case-sensitive by... | You can fix that for the `*` command by putting the following mapping in your `~/.vimrc`.
```
nnoremap * <silent> *N:let @/.='\C'<CR>n
```
When you type `*`, the mapping first executes the normal `*` command, then jumps back to the original word (`N`), then appends `\C` to the search expression (`:let @/.='\C'<CR>`)... |
4,056 | <p>One of the plugins I have installed (probably Supertab) provides a nice view of documentation for the currently highlighted item in the completion menu:</p>
<p><a href="https://i.stack.imgur.com/fVILE.png"><img src="https://i.stack.imgur.com/fVILE.png" alt="enter image description here"></a></p>
<p>The (apparently... | [
{
"answer_id": 4057,
"author": "FDinoff",
"author_id": 46,
"author_profile": "https://vi.stackexchange.com/users/46",
"pm_score": 8,
"selected": true,
"text": "<p>The top window is called the preview window. So any of <code><c-w>z</code>, <code><c-w><c-z></code> or <cod... | 2015/07/29 | [
"https://vi.stackexchange.com/questions/4056",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | One of the plugins I have installed (probably Supertab) provides a nice view of documentation for the currently highlighted item in the completion menu:
[](https://i.stack.imgur.com/fVILE.png)
The (apparently) scratch buffer remains open even after I... | The top window is called the preview window. So any of `<c-w>z`, `<c-w><c-z>` or `:pc[lose][!]` should work.
The below is the help for `:help :pclose`
```
CTRL-W z CTRL-W_z
CTRL-W CTRL-Z CTRL-W_CTRL-Z
:pc :pclose
:pc[lose][!] Close any "Preview" window currently open. When the 'hidden'
o... |
4,059 | <p>I want to map an action that repeats the last make command.</p>
<p>Ideally, such a mapping would work also in insert mode (i.e. it would automatically switch to command mode.)</p>
<p>Also, it would be nice, if such an action also automatically saved the buffers with unsaved changes in them.</p>
<p>Basically, this... | [
{
"answer_id": 4061,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>You could use Ingo Karkat's <a href=\"http://www.vim.org/scripts/script.php?script_id=1661\" rel=\"nofollow\">Redocommand... | 2015/07/29 | [
"https://vi.stackexchange.com/questions/4059",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2357/"
] | I want to map an action that repeats the last make command.
Ideally, such a mapping would work also in insert mode (i.e. it would automatically switch to command mode.)
Also, it would be nice, if such an action also automatically saved the buffers with unsaved changes in them.
Basically, this would automate steps li... | It's fairly easy to translate your keystrokes into a mapping:
```
nnoremap <F9> :wa<CR>:ma<Up><CR>
imap <F9> <Esc><F9>i
```
Here `<CR>` means carriage return. You can also use `<Enter>` but that's longer to type!
The `imap` jumps out of insert mode with `<Esc>`, invokes the normal-mode F9 mapping, then goes back in... |
4,071 | <p>While I was customizing my status line, I was wondering if I could make certain elements of the status line disappear if the window width is too small. To do this, I would have to know how much space the status line is actually taking up. Is there a way of doing this? If not, is there some other way of hiding/sho... | [
{
"answer_id": 4072,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 3,
"selected": true,
"text": "<p>While I'm not a statusline connoisseur, I think the general idea is to do it \"the other way around\": while computing t... | 2015/07/29 | [
"https://vi.stackexchange.com/questions/4071",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/865/"
] | While I was customizing my status line, I was wondering if I could make certain elements of the status line disappear if the window width is too small. To do this, I would have to know how much space the status line is actually taking up. Is there a way of doing this? If not, is there some other way of hiding/showing c... | While I'm not a statusline connoisseur, I think the general idea is to do it "the other way around": while computing the statusline, the evaluated code (functions etc.) *could* check for Vim's windows width and decide if (or how) a certain information will be displayed. To put it in a silly way, something like this:
`... |
4,082 | <p>I am trying to enter a latin cross (<code>✝</code>, Unicode <code>271d</code>) into a document. I can't find a pre-defined digraph for this. I am able to enter such a character with <code><ctrl-v>u271d</code> or I can define a new digraph in my <code>.vimrc</code> like so: <code>digraph \|- 10013</code>.</p>
... | [
{
"answer_id": 4085,
"author": "jjaderberg",
"author_id": 1306,
"author_profile": "https://vi.stackexchange.com/users/1306",
"pm_score": 2,
"selected": false,
"text": "<p>There is no such digraph defined by default. You can review available digraphs at <code>:help digraph-table</code>. T... | 2015/07/30 | [
"https://vi.stackexchange.com/questions/4082",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | I am trying to enter a latin cross (`✝`, Unicode `271d`) into a document. I can't find a pre-defined digraph for this. I am able to enter such a character with `<ctrl-v>u271d` or I can define a new digraph in my `.vimrc` like so: `digraph \|- 10013`.
But before I'd do that I'd like to know if there is really no pre-de... | You can use the [`:digraphs`](http://vimhelp.appspot.com/digraph.txt.html#%3adigraphs) command to get a list of all defined digraphs. This isn't very easy to search, but we can use [`:redir`](http://vimhelp.appspot.com/various.txt.html#%3aredir) to store it to a file:
```
:redir all_digraphs
:digraphs
:redir END
:e al... |
4,091 | <p>When I need to work on different projects at the same time I have the folowing workflow:</p>
<ul>
<li>I create one tab for each project.</li>
<li>In each tab I open the files that I want to edit, which makes several buffers.</li>
<li>Optionnaly if I need to see two (or more) files at the same time I create split wi... | [
{
"answer_id": 4092,
"author": "philolo1",
"author_id": 3003,
"author_profile": "https://vi.stackexchange.com/users/3003",
"pm_score": 3,
"selected": false,
"text": "<p>Mhh, i did not find any plugin out there, but you could write it yourself. You need to learn vimscript for this. I just... | 2015/07/30 | [
"https://vi.stackexchange.com/questions/4091",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | When I need to work on different projects at the same time I have the folowing workflow:
* I create one tab for each project.
* In each tab I open the files that I want to edit, which makes several buffers.
* Optionnaly if I need to see two (or more) files at the same time I create split windows so I have a tab contai... | Mhh, i did not find any plugin out there, but you could write it yourself. You need to learn vimscript for this. I just implemented the functionality that you can switch between buffers in a tab (no deletion yet). You can copy this into your vimrc:
```
if !exists("g:WindowBufManager")
let g:WindowBufManager= {}
end... |
4,093 | <p>I have a custom syntax plugin for a file format that can contain embedded HLSL or GLSL code. At the moment, I've manually included a bunch of <code>syntax keyword</code> and <code>syntax match</code> commands in my syntax file to cover the basics of HLSL or GLSL source. I'd <em>prefer</em> to simply reference an exi... | [
{
"answer_id": 4094,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>Since <code>try</code>/<code>endtry</code> did not seem to work for me after a cursory attempt, I resorted to relying on t... | 2015/07/30 | [
"https://vi.stackexchange.com/questions/4093",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I have a custom syntax plugin for a file format that can contain embedded HLSL or GLSL code. At the moment, I've manually included a bunch of `syntax keyword` and `syntax match` commands in my syntax file to cover the basics of HLSL or GLSL source. I'd *prefer* to simply reference an existing HLSL syntax plugin via `sy... | From [`:help :runtime`](http://vimhelp.appspot.com/repeat.txt.html#%3aruntime)
>
> When `'verbose'` is one or higher, there is a message when no file could be found.
>
>
>
This uses `:echomsg` to print the error, which you can capture like:
```
redir => error
verbose silent runtime syntax/cx.vim
redir END
`... |
4,096 | <p>I frequently use <code>:e.</code> to navigate folders and open files in gVim. But later, when I try to close the session with a <code>:qall</code>, I am asked by vim whether or not I want to save changes to the folder(s) I was navigating with netrw. I couldn't save such changes, even if checked yes.</p>
<p>What d... | [
{
"answer_id": 4103,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>You could try setting the <code>buftype</code> option. E.g. doing <code>:set buftype=nofile</code> should make ig... | 2015/07/30 | [
"https://vi.stackexchange.com/questions/4096",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2452/"
] | I frequently use `:e.` to navigate folders and open files in gVim. But later, when I try to close the session with a `:qall`, I am asked by vim whether or not I want to save changes to the folder(s) I was navigating with netrw. I couldn't save such changes, even if checked yes.
What do I add to my vimrc to let Vim kno... | You could try setting the `buftype` option. E.g. doing `:set buftype=nofile` should make ignore that buffer.
But I'am wondering how you could modify this buffer, since this should read-protected and not-modifiable. |
4,098 | <p>I'm running the command</p>
<pre><code>:.,.5s/^/!&
</code></pre>
<p>to block comment a section of code, however, after running the command the editor highlights the first character in every line of the file. I guess this doesn't surprise me since those characters match the regex, but I thought this would be su... | [
{
"answer_id": 4100,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 2,
"selected": false,
"text": "<h3>Standing on the shoulders of giants</h3>\n\n<p>I would highly recommend commenting plugin like <a href=\"https://gi... | 2015/07/30 | [
"https://vi.stackexchange.com/questions/4098",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3005/"
] | I'm running the command
```
:.,.5s/^/!&
```
to block comment a section of code, however, after running the command the editor highlights the first character in every line of the file. I guess this doesn't surprise me since those characters match the regex, but I thought this would be suppressed if I add a range. | ### Standing on the shoulders of giants
I would highly recommend commenting plugin like [commentary](https://github.com/tpope/vim-commentary) (which I use), [Nerd Commenter](https://github.com/scrooloose/nerdcommenter), [EnhCommentify](http://www.vim.org/scripts/script.php?script_id=23), [tComment](https://github.com/... |
4,102 | <p>I've been using Gvim for a while, but lately stopped using GUI options and went to just commands. <code>:ls</code> is used all the time, but I have a huge project and it is hard to see the file name quickly in the long path. I like how GVim displays buffers in the "Buffers" menu:</p>
<pre><code><file name> ... | [
{
"answer_id": 4114,
"author": "joeytwiddle",
"author_id": 630,
"author_profile": "https://vi.stackexchange.com/users/630",
"pm_score": 2,
"selected": false,
"text": "<p>Here is my suggestion to get you started.</p>\n\n<p>I haven't tested or debugged it, so that's your task. :)</p>\n\n<... | 2015/07/30 | [
"https://vi.stackexchange.com/questions/4102",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3006/"
] | I've been using Gvim for a while, but lately stopped using GUI options and went to just commands. `:ls` is used all the time, but I have a huge project and it is hard to see the file name quickly in the long path. I like how GVim displays buffers in the "Buffers" menu:
```
<file name> <path from $HOME>
``... | I came up with a solution which I think does what you want.
I know that you asked only for hints, so I'll write hints I would have given and then the final function. You'll be free to read it or not.
So here are my tips:
### Creating a function
You said you were really new to vimscript, so here is a short reminder... |
4,116 | <p>In Vim, the character class <code>\s</code> matches any whitespace character. When I'm using those special characters in groups e.g. <code>[\s\w]</code> it does not match any single whitespace or word character, it does match <code>s</code> or <code>w</code>.</p>
<p>How does one use character classes inside groups?... | [
{
"answer_id": 4117,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 5,
"selected": true,
"text": "<p>That's not a group, it's a range, and in Vim you can't use character classes (although it's possible in other regex impl... | 2015/07/31 | [
"https://vi.stackexchange.com/questions/4116",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/129/"
] | In Vim, the character class `\s` matches any whitespace character. When I'm using those special characters in groups e.g. `[\s\w]` it does not match any single whitespace or word character, it does match `s` or `w`.
How does one use character classes inside groups? | That's not a group, it's a range, and in Vim you can't use character classes (although it's possible in other regex implementations, e.g. in [python](https://stackoverflow.com/questions/13142440/python-regex-including-whitespace-inside-character-range)). You'll have to use an [alternation](http://vimregex.com/#alternat... |
4,120 | <p>I created an <code>augroup</code> in my <code>.vimrc</code> containing several <code>autocmd</code> and I need to enable/disable these <code>autocommand</code> on the fly. </p>
<p>The idea is to create a mapping (let's say <kbd>F4</kbd> for example) which would enable these autocommands when pressed once and disabl... | [
{
"answer_id": 4121,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": false,
"text": "<p><em>(I actually figured it out by myself but as I didn't find an answer on this site I thought that could be usefull to c... | 2015/07/31 | [
"https://vi.stackexchange.com/questions/4120",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | I created an `augroup` in my `.vimrc` containing several `autocmd` and I need to enable/disable these `autocommand` on the fly.
The idea is to create a mapping (let's say `F4` for example) which would enable these autocommands when pressed once and disable them when pressed again without having to source a file or re... | Building on your answer: you don't need a variable to keep state of the `augroup`, you can use [`exists()`](http://vimhelp.appspot.com/eval.txt.html#exists%28%29) for that, provided that you know at least one of the `autocmd`s that are part of the group:
```
function! ToggleTestAutoGroup()
if !exists('#TestAutoGro... |
4,134 | <p>I found <a href="http://vim.wikia.com/wiki/VimTip1235" rel="noreferrer">this vim tip</a> which allows you to evaluate a Python expression and displays the result in the command line. You just have to add</p>
<pre><code>:command! -nargs=+ Calc :py print <args>
:py from math import *
</code></pre>
<p>to your <... | [
{
"answer_id": 4135,
"author": "philolo1",
"author_id": 3003,
"author_profile": "https://vi.stackexchange.com/users/3003",
"pm_score": 2,
"selected": false,
"text": "<p>I do the following: </p>\n\n<p>I create somewhere a calculator.py file containing this. </p>\n\n<pre><code> import sys ... | 2015/08/01 | [
"https://vi.stackexchange.com/questions/4134",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2804/"
] | I found [this vim tip](http://vim.wikia.com/wiki/VimTip1235) which allows you to evaluate a Python expression and displays the result in the command line. You just have to add
```
:command! -nargs=+ Calc :py print <args>
:py from math import *
```
to your `.vimrc` and then you can do e.g.
```
:Calc sum([x^2 for x i... | ```
function! CalcAndAppend(expr)
py << EOF
import vim
evaluated = eval(vim.eval("a:expr"))
vim.current.buffer.append(str(evaluated), vim.current.window.cursor[0])
EOF
endfunction
function! CalcAndAppendRegister(reg, expr)
py << EOF
import vim
evaluated = eval(vim.eval("a:expr"))
evalString = "'" + str(evaluated) + "... |
4,139 | <p>I've got a somewhat obfuscated javascript file with multiple variables named <code>a##########</code>, where <code>#</code> stands for a single <code>0-9</code> digit. Each such identifier may or may not be unique.</p>
<p>I was substituting these manually, using <code>:%s/<c-r>k/f#/g</code>, where <code>k</co... | [
{
"answer_id": 4145,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 2,
"selected": false,
"text": "<p>I couldn't find a simple one-liner with the functionality you want, but I did cook up a script for it:</p>\n\n<pre><code... | 2015/08/02 | [
"https://vi.stackexchange.com/questions/4139",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1275/"
] | I've got a somewhat obfuscated javascript file with multiple variables named `a##########`, where `#` stands for a single `0-9` digit. Each such identifier may or may not be unique.
I was substituting these manually, using `:%s/<c-r>k/f#/g`, where `k` was the register I put one of these identifiers and `#` was a numbe... | Although I think John's answer is quite good, I thought of a different way to achieve this. It still requires a custom function, but it is a little bit simpler.
The idea is to create an incrementer object that keeps track of the individual variable IDs. To do this, we define a dictionary with an incrementer function (... |
4,148 | <p>I know I can join lines in Vim with <code>J</code> and several variants thereof (<code>gJ</code>, etc.); <code>J</code> will <em>"Remove the indent and insert up to two spaces"</em>.</p>
<p>But is there also a straightforward way to insert another character instead of the two spaces? For example a comma (<code>,</c... | [
{
"answer_id": 4149,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 5,
"selected": false,
"text": "<p>A simple way is this: simply select your lines (all but the last one) - or use <code>%</code> - and run:</p>\n\n<pre><... | 2015/08/03 | [
"https://vi.stackexchange.com/questions/4148",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | I know I can join lines in Vim with `J` and several variants thereof (`gJ`, etc.); `J` will *"Remove the indent and insert up to two spaces"*.
But is there also a straightforward way to insert another character instead of the two spaces? For example a comma (`,`) or comma & space (`,`)?
Given:
```
8
9
10
32
```
I'... | I wrote a Join plugin, can do what you want, and a lot more.
>
> Except for all features provided by the build-in :join command, Join
> can:
>
>
> * Join lines with separator (string)
> * Join lines with or without trimming the leading/trailing whitespaces
> * Join lines with negative count (backwards join)
> * Jo... |
4,150 | <p>I am trying to change a text file with data in 'document' form into unnormalized csv. The data are a list of hymn authors ('document header') and for each author a list of one or more hymns they have written ('document line'). The specific operation I am struggling with is taking each 'document header' and prependin... | [
{
"answer_id": 4153,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 2,
"selected": false,
"text": "<p>This is one way to do it (I'm sure it's not perfect, but it gets the job done):</p>\n\n<pre><code>:g/./if getline('.')[... | 2015/08/03 | [
"https://vi.stackexchange.com/questions/4150",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1306/"
] | I am trying to change a text file with data in 'document' form into unnormalized csv. The data are a list of hymn authors ('document header') and for each author a list of one or more hymns they have written ('document line'). The specific operation I am struggling with is taking each 'document header' and prepending i... | This is one way to do it (I'm sure it's not perfect, but it gets the job done):
```
:g/./if getline('.')[0] =~ '\w' | delete | else | s/\s\+\(\w\+\)\s\+\(\w\+\)/\=@" . ',' . submatch(1) . ',' . submatch(2)/ | -join! |endif
:g/^$/delete
```
BTW, this would look much nicer if you would allow yourself to use functions.... |
4,152 | <p>One of the reasons i prefer to run Vim from a terminal instead of running gVim is that the output of external gets cluttered up by escape sequences each time I execute commands like <code>ls</code> and <code>grep</code> that I have aliased to colorize the output in my <code>.bashrc</code>.</p>
<p>When executing <co... | [
{
"answer_id": 4153,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 2,
"selected": false,
"text": "<p>This is one way to do it (I'm sure it's not perfect, but it gets the job done):</p>\n\n<pre><code>:g/./if getline('.')[... | 2015/08/03 | [
"https://vi.stackexchange.com/questions/4152",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3032/"
] | One of the reasons i prefer to run Vim from a terminal instead of running gVim is that the output of external gets cluttered up by escape sequences each time I execute commands like `ls` and `grep` that I have aliased to colorize the output in my `.bashrc`.
When executing `:!ls` I get output that looks like this:
```... | This is one way to do it (I'm sure it's not perfect, but it gets the job done):
```
:g/./if getline('.')[0] =~ '\w' | delete | else | s/\s\+\(\w\+\)\s\+\(\w\+\)/\=@" . ',' . submatch(1) . ',' . submatch(2)/ | -join! |endif
:g/^$/delete
```
BTW, this would look much nicer if you would allow yourself to use functions.... |
4,163 | <p>I'm returning to Vim after using Emacs for a few years. I'm trying to <a href="https://stackoverflow.com/a/1220118/580010">grok</a> Vim by reading and watching tutorials, as well as actually using it daily.</p>
<p>When editing text, I find the Emacs commands of Alt-F, Alt-B, Ctrl-a, Ctrl-e, Alt-D and Alt-Backspace ... | [
{
"answer_id": 4164,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<blockquote>\n <p>Alt-F, Alt-B, Ctrl-a, Ctrl-e, Alt-D and Alt-Backspace</p>\n</blockquote>\n\n<p>The equivalent commands in no... | 2015/08/03 | [
"https://vi.stackexchange.com/questions/4163",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2932/"
] | I'm returning to Vim after using Emacs for a few years. I'm trying to [grok](https://stackoverflow.com/a/1220118/580010) Vim by reading and watching tutorials, as well as actually using it daily.
When editing text, I find the Emacs commands of Alt-F, Alt-B, Ctrl-a, Ctrl-e, Alt-D and Alt-Backspace to be very useful and... | **1**
You can achieve those or better (pinky) command mappings very quickly. I'm not recommending this solution, but as an example, if you want to move the cursor to the beginning of line with `<C-a>` you can execute the following line after hitting `:` from normal mode (or add the line to your vimrc)
```
inoremap <C... |
4,170 | <p>Is there a command for deleting line (or n lines) above current one? Above = current not included.</p>
<p>I.e., is there an alternative to <kbd>d</kbd><kbd>k</kbd> which doesn't delete current line? Similar to how <kbd>o</kbd>/<kbd>O</kbd> and <kbd>p</kbd>/<kbd>P</kbd> work, but with deletion.</p>
<p>Currently, I'... | [
{
"answer_id": 4171,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p><strong>EDIT</strong> I didn't know the built-in features suggested by @Romainl in his answer: of course the <code>-d</co... | 2015/08/04 | [
"https://vi.stackexchange.com/questions/4170",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1733/"
] | Is there a command for deleting line (or n lines) above current one? Above = current not included.
I.e., is there an alternative to `d``k` which doesn't delete current line? Similar to how `o`/`O` and `p`/`P` work, but with deletion.
Currently, I'm doing `k``d``d`, which moves cursor one line up and deletes it. I cou... | ```
:-d
```
cuts the line above the current line.
---
```
:-5d
```
cuts the 5th line above the current line (but moves the cursor).
---
```
:-5,-d
```
cuts the 5 lines above the current line.
---
```
:+,+5d
```
cuts the 5 lines below the current line. |
4,190 | <p>With the <code>textwidth</code> option set the text written can be wrapped when we leave insert mode. If I type a line longer than my <code>textwidth</code> value then it will go on a new line. </p>
<p>e.g. with <code>set textwidth=5</code> and <code>set linebreak</code> :</p>
<pre><code>1 2 3 [4]
1 2 3
4[]
lor... | [
{
"answer_id": 4194,
"author": "ZeroKelvinKeyboard",
"author_id": 2283,
"author_profile": "https://vi.stackexchange.com/users/2283",
"pm_score": 1,
"selected": false,
"text": "<p>Check that your <code>formatoptions</code> contain at least the letters 't' and 'c'.</p>\n\n<p>Make sure past... | 2015/08/06 | [
"https://vi.stackexchange.com/questions/4190",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | With the `textwidth` option set the text written can be wrapped when we leave insert mode. If I type a line longer than my `textwidth` value then it will go on a new line.
e.g. with `set textwidth=5` and `set linebreak` :
```
1 2 3 [4]
1 2 3
4[]
lorem ipsum dolor[Esc]
lorem
ipsum
dolor[]
```
[X] means: I pres... | So as we troubleshooted in the comments the problem came from the `formatoption` value.
According to `:h formatoptions` :
>
> This is a sequence of letters which describes how automatic
> formatting is to be done.
>
>
>
Your settings contained the letter `l` which according to `:h fo-table` does the following:
... |
4,192 | <p>I can grab the number of lines of a buffer with <code>line("$")</code>, but this does not take into account if my terminal is small and I have <code>set wrap</code> and some lines wrap. </p>
<p>I wonder if it is possible to query this (greater) line count value? Basically it would be the # of times that you could <... | [
{
"answer_id": 4193,
"author": "philolo1",
"author_id": 3003,
"author_profile": "https://vi.stackexchange.com/users/3003",
"pm_score": 2,
"selected": false,
"text": "<p>The issue is that vim does not store the wrapped lines, it only displays those you have here. If you really want to do ... | 2015/08/07 | [
"https://vi.stackexchange.com/questions/4192",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/390/"
] | I can grab the number of lines of a buffer with `line("$")`, but this does not take into account if my terminal is small and I have `set wrap` and some lines wrap.
I wonder if it is possible to query this (greater) line count value? Basically it would be the # of times that you could `gj` from the top of the file (pl... | It is better to employ `strdisplaywidth()` for this job. It takes things like number, fold and sign columns into account as well as `&linebreak`, `&showbreak` and `&breakindent` option effects. Problem is that you still have to somehow calculate width of the window available for text (i.e. exclude widths of number, fol... |
4,196 | <p>I have many python code examples in my markdown files, which should be prepended with <code>>>></code> symbols.</p>
<p>So I write a vim function to do this job:</p>
<pre><code>function AddShellPrompt() range
let lnum = a:firstline
while lnum <= a:lastline
let replaced_line = substitute(... | [
{
"answer_id": 4199,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 0,
"selected": false,
"text": "<p>It should be possible by including the <code>\\|</code> operator in your regex.</p>\n\n<p>For example : </p>\n\n<p>The tex... | 2015/08/07 | [
"https://vi.stackexchange.com/questions/4196",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3085/"
] | I have many python code examples in my markdown files, which should be prepended with `>>>` symbols.
So I write a vim function to do this job:
```
function AddShellPrompt() range
let lnum = a:firstline
while lnum <= a:lastline
let replaced_line = substitute(getline(lnum), '^\s\+', '&>>>', '')
... | The question seems easier when you word it differently. If you are happy with the logic of *Any of the characters `-+*/%(=`or the word `import`*, the regex is simply
```
[-+*/%()]\|import
```
where
`[-+*/%()]` is a set of characters that can match, `\|` stands for *or*, and `import` is the word itself.
Of course, i... |
4,232 | <p>I installed colorscheme "jellybeans" for Vim. Why does the colors look differently when I run Vim with and without sudo?</p>
<p>Example on the screen below - the left one is without sudo, the right is with sudo. The one with sudo is working properly - how can I make Vim to have the same colors without usin... | [
{
"answer_id": 4234,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 3,
"selected": false,
"text": "<p>When you run vim with sudo, you are running as user root, so you are using root's vimrc and .vim. Your colorscheme and ... | 2015/08/08 | [
"https://vi.stackexchange.com/questions/4232",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1067/"
] | I installed colorscheme "jellybeans" for Vim. Why does the colors look differently when I run Vim with and without sudo?
Example on the screen below - the left one is without sudo, the right is with sudo. The one with sudo is working properly - how can I make Vim to have the same colors without using sudo?
[![enter i... | The solution was: making sure users who run vim can actually read the colorscheme file. Giving everyone read permission is done with:
```
sudo chmod +r /usr/share/vim/vim74/colors/jellybeans.vim
``` |
4,235 | <p>When editing source code using gvim (v.7.4.488), I want to commit some changes the vcs (I'm using git 2.1.4 from the command line in Ubuntu linux).</p>
<pre><code>git --status
</code></pre>
<p>shows which files I changed. However, it also shows the vim <code>.*.swp</code> of the currently visible buffer(s) (both ... | [
{
"answer_id": 4237,
"author": "Lithis",
"author_id": 2680,
"author_profile": "https://vi.stackexchange.com/users/2680",
"pm_score": 4,
"selected": true,
"text": "<p><code>vim -r</code> at the command line will list all swap files in the current directory and temporary directories, and w... | 2015/08/09 | [
"https://vi.stackexchange.com/questions/4235",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3101/"
] | When editing source code using gvim (v.7.4.488), I want to commit some changes the vcs (I'm using git 2.1.4 from the command line in Ubuntu linux).
```
git --status
```
shows which files I changed. However, it also shows the vim `.*.swp` of the currently visible buffer(s) (both if the file contain unsaved changes an... | `vim -r` at the command line will list all swap files in the current directory and temporary directories, and whether they contain any unsaved changes. Look for the line that says `modified: no/YES`.
I don’t know how to tell Vim to look in a different directory, so you’ll need to change to each directory that contains... |
4,244 | <p>I've been aware of these tab related settings in Vim:</p>
<ul>
<li><code>ts</code></li>
<li><code>sw</code></li>
<li><code>expandtab</code></li>
<li><code>smarttab</code></li>
<li><code>sts</code></li>
</ul>
<p>My normal setting is <code>set ts=4 sw=4 expandtab smarttab</code>. </p>
<p>But according to <a href="h... | [
{
"answer_id": 4250,
"author": "Lithis",
"author_id": 2680,
"author_profile": "https://vi.stackexchange.com/users/2680",
"pm_score": 6,
"selected": true,
"text": "<p>As the <code>softtabstop</code> documention mentions, it's useful if you want to keep the default tab stop size of 8, but ... | 2015/08/10 | [
"https://vi.stackexchange.com/questions/4244",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3114/"
] | I've been aware of these tab related settings in Vim:
* `ts`
* `sw`
* `expandtab`
* `smarttab`
* `sts`
My normal setting is `set ts=4 sw=4 expandtab smarttab`.
But according to [`sts` documentation](http://vimdoc.sourceforge.net/htmldoc/options.html#%27sts%27), if `expandtab` is not set, it will try to use a combin... | As the `softtabstop` documention mentions, it's useful if you want to keep the default tab stop size of 8, but edit a file as if the tab stop size was some other value. For example, if you wanted an indentation level of 4 while editing code, but some comments had tab-indented text such as a table that depended on a tab... |
4,245 | <p>I know that you can pass several flags to Vim at startup.</p>
<p>For example: the <code>-w</code> flags enables to records every keystrokes on the file output.</p>
<pre><code>vi -w output
</code></pre>
<p>But I wonder if there is a way of doing this from the vimrc file, without having the <code>-w</code> flag at vi... | [
{
"answer_id": 4268,
"author": "Jeeter",
"author_id": 3138,
"author_profile": "https://vi.stackexchange.com/users/3138",
"pm_score": 0,
"selected": false,
"text": "<p>(This solution only works if you want to save your keystrokes to a single file)</p>\n\n<p>You could alias it in your <cod... | 2015/08/10 | [
"https://vi.stackexchange.com/questions/4245",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I know that you can pass several flags to Vim at startup.
For example: the `-w` flags enables to records every keystrokes on the file output.
```
vi -w output
```
But I wonder if there is a way of doing this from the vimrc file, without having the `-w` flag at vim startup.
More generally: how can I specify a vim ... | This is not possible.
If the `-w` or `-W` flags are given, Vim will set the `scriptout` variable to a filehandle (`main.c`, `command_line_scan()`, around line 2374). This variable is referenced in only 2 other places; `getchar.c` for writing to the file, and `message.c`, to work around a problem which causes a charact... |
4,246 | <p>I saw somewhere on the web someone using <code>Ctrl-J</code> and as I didn't know this mapping I looked up in <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#j">the relevant doc</a> and found the following:</p>
<pre><code>j or
<Down> or
CTRL-J or
<NL> or
CTRL-N ... | [
{
"answer_id": 4248,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<p>See <code>:help key-notation</code>.</p>\n\n<ol>\n<li><p><code><NL></code> means \"linefeed\" and <code><CR></co... | 2015/08/10 | [
"https://vi.stackexchange.com/questions/4246",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | I saw somewhere on the web someone using `Ctrl-J` and as I didn't know this mapping I looked up in [the relevant doc](http://vimdoc.sourceforge.net/htmldoc/motion.html#j) and found the following:
```
j or
<Down> or
CTRL-J or
<NL> or
CTRL-N [count] lines downward linewise.
```
Whic... | Interesting that you mentioned `<CR>`. `<CR>` or carriage return, technically used to mean *go to the start of the line*. `<NL>`, or newline aka line feed (usually called `LF`), was used to mean *go to the next line*. Over time, the distinction was lost in most applications.1 Pressing `Enter` actually yields a carriage... |
4,257 | <p>I have a couple of plugins that don't work correctly on some machines running earlier versions of Vim. </p>
<p>Is there a way to supress the <code>Error detected while processing...</code> errors when I start up vim in these environments?</p>
| [
{
"answer_id": 4259,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 3,
"selected": false,
"text": "<p>It depends on the plugin and on what is causing the error. Most plugins have a block of code near the top of the plugin... | 2015/08/11 | [
"https://vi.stackexchange.com/questions/4257",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1623/"
] | I have a couple of plugins that don't work correctly on some machines running earlier versions of Vim.
Is there a way to supress the `Error detected while processing...` errors when I start up vim in these environments? | If you happen to have [pathogen](https://github.com/tpope/vim-pathogen), another solution here is to use its `g:pathogen_disabled` array variable. In your .vimrc you can add bundle names to this array based on vim's reported environment. Upon calling call `pathogen#infect()`, it will not enable the listed plugins.
```... |
4,261 | <p>Every now and then when I try to quit vim, I incidentally open window with command cheat sheet as in attached picture. How do I do this and how is it called?</p>
<p><a href="https://i.stack.imgur.com/qk1Ka.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qk1Ka.png" alt="enter image description her... | [
{
"answer_id": 4262,
"author": "charlee",
"author_id": 3132,
"author_profile": "https://vi.stackexchange.com/users/3132",
"pm_score": 3,
"selected": false,
"text": "<p>This is command history invoked by <code>q:</code>.</p>\n\n<p><a href=\"http://vim.wikia.com/wiki/Using_command-line_his... | 2015/08/11 | [
"https://vi.stackexchange.com/questions/4261",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3131/"
] | Every now and then when I try to quit vim, I incidentally open window with command cheat sheet as in attached picture. How do I do this and how is it called?
[](https://i.stack.imgur.com/qk1Ka.png) | That's not a cheat sheet; it's a history of the commands you've executed. It allows you to find, edit and repeat commands you've previously executed. There are a couple of ways you can enter it. One is to type `Ctrl-F` while on the ex command line. Another way is to type `q:` while in normal mode. You can read more abo... |
4,269 | <p>Is there a way to expand a UltiSnips snippet while in vim command-line mode? I can only expand a snippet in insert mode. </p>
<p>I am using UltiSnips to help inserting unicode characters. And I need to write these characters in the command-line for searching. I do not want to insert them using <code><C-v>u</c... | [
{
"answer_id": 4281,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 1,
"selected": false,
"text": "<p>While I didn't achieve to trigger the completion from the command-line mode you can work this like this :</p>\n\n<p>Prepar... | 2015/08/11 | [
"https://vi.stackexchange.com/questions/4269",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3140/"
] | Is there a way to expand a UltiSnips snippet while in vim command-line mode? I can only expand a snippet in insert mode.
I am using UltiSnips to help inserting unicode characters. And I need to write these characters in the command-line for searching. I do not want to insert them using `<C-v>u`. I also prefer not to ... | While I didn't achieve to trigger the completion from the command-line mode you can work this like this :
Prepare your command inside insert mode (or at least the part you cannot create from command-line mode). Yank it and insert it inside your command using `<C-r>` and the `"` register like so :
Insert Mode
```
t... |
4,271 | <p>I have a function that is called via a mapping when I am in insert mode:</p>
<pre><code>inoremap <buffer> <M-i> <ESC>:call TheFunc()<CR>
</code></pre>
<p>The function is supposed to "calculate" a string (<code>l:text</code>) and to insert it at the current cursor position:</p>
<pre><code>f... | [
{
"answer_id": 4276,
"author": "EvergreenTree",
"author_id": 865,
"author_profile": "https://vi.stackexchange.com/users/865",
"pm_score": 4,
"selected": true,
"text": "<p>There is a better way of using functions in mappings, and that is by using the <code><expr></code> flag. For e... | 2015/08/11 | [
"https://vi.stackexchange.com/questions/4271",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | I have a function that is called via a mapping when I am in insert mode:
```
inoremap <buffer> <M-i> <ESC>:call TheFunc()<CR>
```
The function is supposed to "calculate" a string (`l:text`) and to insert it at the current cursor position:
```
fu! TheFunc()
if g:FOO = 1
let l:text = XYZ()
elseif g:FOO =... | There is a better way of using functions in mappings, and that is by using the `<expr>` flag. For example, say you wanted to insert the current line number at the cursor position by typing `ln` in insert mode. This is how you would accomplish that with an `<expr>` mapping:
```
inoremap <expr> ln line(".")
```
Instea... |
4,288 | <p>Is it possible to show every n relative line numbers? So for example, I can see a a (+/-) 10, 20, 30... instead of a value on every line. </p>
<p>If there's no current way to do it, is it possible to create? i.e. can a plugin programmically change the line numbers shown?</p>
| [
{
"answer_id": 4299,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": true,
"text": "<p>I made a little script that does nearly what you do.</p>\n\n<h1>Explanations</h1>\n\n<p>The core concept behind it comes di... | 2015/08/12 | [
"https://vi.stackexchange.com/questions/4288",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2512/"
] | Is it possible to show every n relative line numbers? So for example, I can see a a (+/-) 10, 20, 30... instead of a value on every line.
If there's no current way to do it, is it possible to create? i.e. can a plugin programmically change the line numbers shown? | I made a little script that does nearly what you do.
Explanations
============
The core concept behind it comes directly from the [vim-signature](https://github.com/kshenoy/vim-signature) plugin. Here is a step-by-step walkthrough :
1. Remove all previous signs from the sign bar
2. Build a list of the lines you wan... |
4,302 | <p>I use <code>list</code> and <code>listchars</code> to show my whitespace, but the code style I adhere to uses tabs. Seeing <code>></code> or <code>^I</code> for all of my tabs is nauseating.</p>
<p>How would I keep all of my existing list characters but with a blank tab character?</p>
| [
{
"answer_id": 4303,
"author": "Qix - MONICA WAS MISTREATED",
"author_id": 3164,
"author_profile": "https://vi.stackexchange.com/users/3164",
"pm_score": 2,
"selected": false,
"text": "<p>Turns out non-breaking spaces work just fine.</p>\n\n<p>As per <a href=\"https://stackoverflow.com/a... | 2015/08/13 | [
"https://vi.stackexchange.com/questions/4302",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3164/"
] | I use `list` and `listchars` to show my whitespace, but the code style I adhere to uses tabs. Seeing `>` or `^I` for all of my tabs is nauseating.
How would I keep all of my existing list characters but with a blank tab character? | `'listchars'` takes two characters for `tab` so you can simply use two regular spaces:
```
set listchars=tab:\ \ ,trail:·,eol:¬,nbsp:_
``` |
4,307 | <p>I'm using <a href="https://github.com/terryma/vim-multiple-cursors" rel="noreferrer">vim-multiple-cursors</a> plugin.</p>
<p>I would like to put cursors exactly where I want. For example (<code>[x]</code> are the cursor positions):</p>
<pre><code>Lorem ipsum dolor sit amet[1], consectetur adipiscing elit,
sed do ... | [
{
"answer_id": 4310,
"author": "Alex Stragies",
"author_id": 3102,
"author_profile": "https://vi.stackexchange.com/users/3102",
"pm_score": 3,
"selected": false,
"text": "<p>Your given use-cases to me sound like to want to know the <code>.</code> key command (repeat last Editing command)... | 2015/08/13 | [
"https://vi.stackexchange.com/questions/4307",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2977/"
] | I'm using [vim-multiple-cursors](https://github.com/terryma/vim-multiple-cursors) plugin.
I would like to put cursors exactly where I want. For example (`[x]` are the cursor positions):
```
Lorem ipsum dolor sit amet[1], consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna[2]
aliqu... | **Using multiple cursor isn't a Vimmer thing**
As I said in the comments using multi cursors (even with a plugin) isn't really "following the Vim way", I totally understand that it is attractive for someone coming from Sublime-Text but you can often find alternatives which are at least as efficient with Vim built-in f... |
4,346 | <p>One thing I often do here is to add links to documentation when writing <code>:he foo</code>, and I usually link to <a href="http://vimhelp.appspot.com" rel="noreferrer">http://vimhelp.appspot.com</a>. The problem is, that site's search is about slightly worse than the Stack Exchange sites' search. <a href="http://v... | [
{
"answer_id": 4359,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p><strong>EDIT 2</strong></p>\n\n<p>I've improved the function, the encoding should be working on all of the help topics an... | 2015/08/15 | [
"https://vi.stackexchange.com/questions/4346",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | One thing I often do here is to add links to documentation when writing `:he foo`, and I usually link to <http://vimhelp.appspot.com>. The problem is, that site's search is about slightly worse than the Stack Exchange sites' search. <http://vimdoc.sourceforge.net>, on the other hand, has excellent search functionality,... | **EDIT 2**
I've improved the function, the encoding should be working on all of the help topics and it is now available as a [plugin](https://github.com/statox/GOD.vim).
**EDIT**
Here is an updated version of the function allowing to call vimhelp.appspot.com. It has several advantages:
* You can type a tag in the s... |
4,353 | <p>As a way of organizing my codes, I like to include some titles as comments with specific patterns (I wish I can add ASCII art!). Consider for example, putting the following to mark a specific block of code:</p>
<pre><code>//===================== Solving a big problem =============================//
//-------------... | [
{
"answer_id": 4358,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p><strong>Please don't do that</strong>: This type of title comments is just too heavy and\ndoesn't improve the readability... | 2015/08/16 | [
"https://vi.stackexchange.com/questions/4353",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2199/"
] | As a way of organizing my codes, I like to include some titles as comments with specific patterns (I wish I can add ASCII art!). Consider for example, putting the following to mark a specific block of code:
```
//===================== Solving a big problem =============================//
//--------------------The mos... | **Please don't do that**: This type of title comments is just too heavy and
doesn't improve the readability of your code. If you really need to create a
section use light multi lines comments like:
```
"
" Solving a big problem
"
```
That's much easier to read. So now that I gave my totally subjective opinion,
which... |
4,363 | <p>I want to use visual block mode (ctl-v) to select all the comments but none of the code:</p>
<pre><code>a = 1 // short comment
b = 2 // this one is a longer comment
c = 3 // shortest
</code></pre>
<p>My selection is marked with X characters here. Notice that if I start at the to... | [
{
"answer_id": 4364,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 3,
"selected": false,
"text": "<p>One (*) secret is:</p>\n\n<pre><code>set virtualedit=block\n</code></pre>\n\n<p>... in your <code>vimrc</code> :) </p>\... | 2015/08/16 | [
"https://vi.stackexchange.com/questions/4363",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2985/"
] | I want to use visual block mode (ctl-v) to select all the comments but none of the code:
```
a = 1 // short comment
b = 2 // this one is a longer comment
c = 3 // shortest
```
My selection is marked with X characters here. Notice that if I start at the top-left my selection is uns... | The secret is to press `$` after you have expanded your block vertically:
```
<C-v>jj$
```
or to press `$` before expanding your block vertically:
```
<C-v>$jj
```
Well, `$` is the secret.
…which is not *that* surprising, after all. |
4,366 | <p>I'm trying to create a function mapping that takes a count, in this case the number of lines to yank to the system clipboard. </p>
<pre><code>func! Clipboard()
echo 'Clipboard function called'
if v:count is 0
normal "+yy
else
exec 'normal ' . v:count . '"+yy'
endif
endfunc
nmap YY :call Clipboard(... | [
{
"answer_id": 4380,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 2,
"selected": true,
"text": "<p><em>(just to move the relevant comments in an answer)</em></p>\n\n<p>Use <code>range</code>, so that the function handle... | 2015/08/16 | [
"https://vi.stackexchange.com/questions/4366",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3201/"
] | I'm trying to create a function mapping that takes a count, in this case the number of lines to yank to the system clipboard.
```
func! Clipboard()
echo 'Clipboard function called'
if v:count is 0
normal "+yy
else
exec 'normal ' . v:count . '"+yy'
endif
endfunc
nmap YY :call Clipboard()<CR>
```
Prob... | *(just to move the relevant comments in an answer)*
Use `range`, so that the function handles the range itself (`a:firstline`, `a:lastline`), so it's called only once. See [here](http://vimhelp.appspot.com/eval.txt.html#E124) (`:h func-range`).
Another approach: use `:<C-u>call Clipboard()<CR>` in your map. You clear... |
4,368 | <p>When editing an Haskell file, I want to configure a comment format <code>{- -}</code> such that:</p>
<pre><code>{- <cr>
- <cr>
- -}
</code></pre>
<p>But it doesn't work as expected (but almost there):</p>
<pre><code>{- <cr>
- <cr>
- -}
</code></pre>
<p>notice that after hitting <kbd>ent... | [
{
"answer_id": 4371,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>The behavior of the comments is controled by the <code>comments</code>options (see <a href=\"http://vimdoc.sourceforge.ne... | 2015/08/17 | [
"https://vi.stackexchange.com/questions/4368",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1097/"
] | When editing an Haskell file, I want to configure a comment format `{- -}` such that:
```
{- <cr>
- <cr>
- -}
```
But it doesn't work as expected (but almost there):
```
{- <cr>
- <cr>
- -}
```
notice that after hitting `enter`, the `-` doesn't align.
What option should I use to make it aligned? | Ok. figured it out by looking into [haskell.vim](https://github.com/neovimhaskell/haskell-vim), I found ad slight modification of `indentexpr` would work.
check it out.
first,
```
$ cd ~/.vim/bundle/haskell-vim/
$ vi indent/haskell.vim
```
then find the definition of `GetHaskellIndent` function.
I add following l... |
4,372 | <p>Is is possible to search for a regexp in <strong>only</strong> the <em>current line</em>.</p>
<p>Here is an example line:</p>
<pre><code>This is some text that I have written. Can you find this word?
^
</code></pre>
<p>This line contains many <code>t</code>'s. I... | [
{
"answer_id": 4373,
"author": "PhilippFrank",
"author_id": 1296,
"author_profile": "https://vi.stackexchange.com/users/1296",
"pm_score": 2,
"selected": false,
"text": "<p>How about using <code>:s/this//cI</code>? Substitutes <code>this</code> on the current line by it's own occurrence ... | 2015/08/17 | [
"https://vi.stackexchange.com/questions/4372",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3032/"
] | Is is possible to search for a regexp in **only** the *current line*.
Here is an example line:
```
This is some text that I have written. Can you find this word?
^
```
This line contains many `t`'s. I would like to search forward for `this` so the cursor ends up a... | You can do:
```
:call search('find', '', line('.'))
```
... where `'find'`is the pattern. The cursor will be moved to the start of the match.
Sample interactive mapping (not perfect):
```
:nnoremap <leader>/ :call search(input("Pattern: "), '', line('.'))<cr>
```
---
**Also**: with several plugins that enhance ... |
4,382 | <p>I have a fairly small Javascript project, and when I run <code>ctags -R</code> it seems to generate at least some tags. I get a tags file (no extension?) in the root folder, and when I run <code>wc -l tags</code> it says <code>8214 tags</code>.</p>
<p>However, Ctrl+] never finds any tags, even ones in the same file... | [
{
"answer_id": 4383,
"author": "Georg P.",
"author_id": 3205,
"author_profile": "https://vi.stackexchange.com/users/3205",
"pm_score": 0,
"selected": false,
"text": "<p>You may want to try the <a href=\"http://vim-taglist.sourceforge.net/\" rel=\"nofollow\">taglist</a> plugin. It works p... | 2015/08/17 | [
"https://vi.stackexchange.com/questions/4382",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3210/"
] | I have a fairly small Javascript project, and when I run `ctags -R` it seems to generate at least some tags. I get a tags file (no extension?) in the root folder, and when I run `wc -l tags` it says `8214 tags`.
However, Ctrl+] never finds any tags, even ones in the same file. Right now, I'm using the supergf plugin f... | You should check your current directory to see if its the same as your **tags** file
```
:pwd
```
If not just
```
:cd /to/dir/which/contains/yourtagfile
```
and try again using tags.
Please check [this response](https://stackoverflow.com/questions/11975316/vim-ctags-tag-not-found) for ways to set searching direc... |
4,387 | <p>I'm trying to have a highlighted undo in Vim, like spacemacs default config.
Sometimes when I want quick undo's, I can't realize what changed because it's instantaneous. So I am trying to have something like this when a press undo:</p>
<p><a href="https://i.stack.imgur.com/FWWTU.png" rel="nofollow noreferrer"><img ... | [
{
"answer_id": 4392,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": true,
"text": "<h1>New solution</h1>\n\n<p>You can view your last changes with the <code>:changes</code> command. So you can fecth your most ... | 2015/08/18 | [
"https://vi.stackexchange.com/questions/4387",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2131/"
] | I'm trying to have a highlighted undo in Vim, like spacemacs default config.
Sometimes when I want quick undo's, I can't realize what changed because it's instantaneous. So I am trying to have something like this when a press undo:
[](https://i.stack.imgur.com/FW... | New solution
============
You can view your last changes with the `:changes` command. So you can fecth your most recent line change with a regex and then apply the line to `matchadd()` as suggested by @joeytwiddle.
Here is the code :
```
function! DiffWithPrevious()
call clearmatches()
redir => message
silent ... |
4,394 | <p>I have a graph data in a file with each line containing the source and destination node of an edge. I want to assign a random weight between [1, 10] for each edge to test my graph algorithm. How can I do that in Vim?</p>
<p><strong>Graph data:</strong></p>
<blockquote>
<p>1 2 <br/>2 3 <br/>1 5</p>
</blockquote>
<p><... | [
{
"answer_id": 4395,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 2,
"selected": false,
"text": "<p>As long as you don't mind the quality of the random process generation:</p>\n\n<pre><code>:%s/\\s*$/\\=' ' . (1 + str2n... | 2015/08/18 | [
"https://vi.stackexchange.com/questions/4394",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3213/"
] | I have a graph data in a file with each line containing the source and destination node of an edge. I want to assign a random weight between [1, 10] for each edge to test my graph algorithm. How can I do that in Vim?
**Graph data:**
>
> 1 2
> 2 3
> 1 5
>
>
>
**Data along with weights(Expected Output)**
> ... | You can do it with a macro :
```
:r!echo $RANDOM^Mld$kJ
```
Decomposing the macro :
```
:r!echo $RANDOM^M
```
**Note** : `^M` is the litteral `<CR>`, so you should press `<CR>` instead of `^M` when you record your macro.
This insert in a new line a random number (you should look at [this post](https://stackover... |
4,405 | <p>Is there a way to call vi/vim from the shell to format text? It would be like running a vim-golf sequence from the command line.</p>
<p>It is so easy to compare effects of commands in vim that I can easily test a few options and identify a workable solution. I would like to be able to incorporate those command se... | [
{
"answer_id": 4406,
"author": "philolo1",
"author_id": 3003,
"author_profile": "https://vi.stackexchange.com/users/3003",
"pm_score": 2,
"selected": false,
"text": "<p>You can use vim as a command server as described in here: <a href=\"http://vimdoc.sourceforge.net/htmldoc/remote.html\"... | 2015/08/18 | [
"https://vi.stackexchange.com/questions/4405",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3222/"
] | Is there a way to call vi/vim from the shell to format text? It would be like running a vim-golf sequence from the command line.
It is so easy to compare effects of commands in vim that I can easily test a few options and identify a workable solution. I would like to be able to incorporate those command sequences into... | You can launch vim using two flags to accomplish this. The two flags are `-e` and `-s`. When vim is launched with the `-e` flag, vim automatically enters ex mode, which is just vim's command line and nothing else. The `-s` flag means that vim is silent, which means that nothing is displayed. This wouldn't be very usefu... |
4,412 | <p>I know that if you press <code>n</code> you can hop to the next occurrence of a matching pattern, and that if you want to go to the previous match, you press <code>N</code>.</p>
<p>But if my cursor is already in the middle of a match, how do I tell what number match that is from the top of the document?</p>
| [
{
"answer_id": 4413,
"author": "Steve",
"author_id": 1313,
"author_profile": "https://vi.stackexchange.com/users/1313",
"pm_score": 2,
"selected": false,
"text": "<p>This should just be a comment but as I don't have the reputation to comment here goes.</p>\n\n<p>This won't be accurate fo... | 2015/08/19 | [
"https://vi.stackexchange.com/questions/4412",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1065/"
] | I know that if you press `n` you can hop to the next occurrence of a matching pattern, and that if you want to go to the previous match, you press `N`.
But if my cursor is already in the middle of a match, how do I tell what number match that is from the top of the document? | You can use the `n` flag with the substitution command.
```
:%s/set//gn
```
Or use the current search pattern via `:%s///gn`.
You can also use `:vimgrep` and the quickfix list. Search for your pattern via:
```
:vimgrep/set/ %
```
This searches the current file, `%`, and adds the matches to the quickfix list. Th... |
4,426 | <p>I would like to add to my vimrc a custom command (<code>:customFilter {pattern}</code>) for filtering text and placing result in a new tab.</p>
<p>I tried using <code>:global</code> or <code>:vimgrep /{pattern}/ %</code> but the problem is that I would like to redirect this result of <code>global</code> or content ... | [
{
"answer_id": 4427,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": false,
"text": "<p>First clear an register: <code>qaq</code>\nsecond, append all matching lines using the <code>:g</code> command:</... | 2015/08/20 | [
"https://vi.stackexchange.com/questions/4426",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3254/"
] | I would like to add to my vimrc a custom command (`:customFilter {pattern}`) for filtering text and placing result in a new tab.
I tried using `:global` or `:vimgrep /{pattern}/ %` but the problem is that I would like to redirect this result of `global` or content of `Quickfix list` (without name of file) to a new tab... | You can create a new empty buffer in a new tab and then populate it with the result of a grep search on the previous file:
```
:tabnew|0r!grep -n pattern #
```
In a mapping:
```
nnoremap <key> :tabnew\|0r!grep -n #<Left><Left>
```
Which works like this:
[\n \" Populate splits with... | 2015/08/21 | [
"https://vi.stackexchange.com/questions/4436",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1097/"
] | I majorly use vim over an ssh session using putty. Sometimes I may have to copy code from ssh in a vim session but it's not very convenient. I do the following :
```
<C-w>o
:set nu!
```
This close all splits that I have.
Is there a way just for me to expand the current window to the whole screen temporarily and re... | Here is a safer way to do what you are currently doing:
```
:tabe %|set nonu
```
Once you are done, close that tab page with `:q` to go back to the previous tab page.
--- edit ---
A similar workflow for transient buffers:
```
:tabnew|set nonu|b#
```
--- endedit ---
That said, you should probably try "X forward... |
4,452 | <p>I usually work in a drop-down terminal, running about 25 characters high. Since I prefer tabs to windows<sup>1</sup>, usually a lot of horizontal space is wasted - around half of the terminal width. </p>
<p>On top of that, Vim, with the default setting of <code>helpheight</code>, leaves just about a couple of lines... | [
{
"answer_id": 4453,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 5,
"selected": false,
"text": "<p>You can use <code>:vert h [your topic]</code> to open help vertically.</p>\n\n<p>You can use the following command:</p>\n... | 2015/08/22 | [
"https://vi.stackexchange.com/questions/4452",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | I usually work in a drop-down terminal, running about 25 characters high. Since I prefer tabs to windows1, usually a lot of horizontal space is wasted - around half of the terminal width.
On top of that, Vim, with the default setting of `helpheight`, leaves just about a couple of lines of the file content when I open... | You can use `:vert h [your topic]` to open help vertically.
You can use the following command:
```
cnoreabbrev H vert h
```
To make vim replace `H` by `vert h` automatically in command line.
Also you can use this abbreviation:
```
cnoreabbrev HR vert bo h
```
To open the help window on the right side of the scr... |
4,480 | <p>I have this mapping in my vimrc:</p>
<pre><code>imap <expr> <silent> <cr> neocomplete#mappings#close_popup() .
\ "<Plug>(neosnippet_jump_or_expand)"
</code></pre>
<p>and it's working great. When I press enter in a neocomplete popup it expands neosnippet but the problem is that <code><cr&... | [
{
"answer_id": 4481,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 1,
"selected": false,
"text": "<p>Your question <em>could</em> be more elaborate. Perhaps you need something like:</p>\n\n<pre><code>imap <expr> &l... | 2015/08/23 | [
"https://vi.stackexchange.com/questions/4480",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3285/"
] | I have this mapping in my vimrc:
```
imap <expr> <silent> <cr> neocomplete#mappings#close_popup() .
\ "<Plug>(neosnippet_jump_or_expand)"
```
and it's working great. When I press enter in a neocomplete popup it expands neosnippet but the problem is that `<cr>` will now work only for that and will not do a return lin... | Your question *could* be more elaborate. Perhaps you need something like:
```
imap <expr> <silent> <cr> neosnippet#expandable_or_jumpable() ?
\ "<Plug>(neosnippet_expand_or_jump)" :
\ neocomplete#mappings#close_popup()."\<CR>"
``` |
4,482 | <p>I've got the following line in my <code>_vimrc</code> file which enables folding for my PHP (and other) files:</p>
<pre><code>set foldmethod=indent
</code></pre>
<p>However, whenever I open a file it starts with every fold closed, but I would like the file to start with its folds open.</p>
<p>How can I execute th... | [
{
"answer_id": 4483,
"author": "cbaumhardt",
"author_id": 3282,
"author_profile": "https://vi.stackexchange.com/users/3282",
"pm_score": 3,
"selected": false,
"text": "<p><a href=\"http://vim.wikia.com/wiki/All_folds_open_when_opening_a_file\" rel=\"noreferrer\">Add the <code>foldlevel</... | 2015/08/23 | [
"https://vi.stackexchange.com/questions/4482",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/368/"
] | I've got the following line in my `_vimrc` file which enables folding for my PHP (and other) files:
```
set foldmethod=indent
```
However, whenever I open a file it starts with every fold closed, but I would like the file to start with its folds open.
How can I execute the command `zi` to open up folds when vim 7.4... | `zi` inverts the option `foldenable`. But you don't want to invert it, you want to disable it. So put the following in your .vimrc:
```
set nofoldenable
``` |
4,488 | <p>For example, I have the following <code>autocommand</code> definition:</p>
<pre><code>augroup cursorline
autocmd!
autocmd WinLeave,BufLeave * set nocursorline
autocmd WinEnter,BufEnter * set cursorline
augroup end
</code></pre>
<p>I want to define something that excludes <code>*.tex</code> files:</p>
... | [
{
"answer_id": 4491,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 1,
"selected": false,
"text": "<p>I didn't find anything that seems to support what you want, but you can do quite the same with a little bit of scripting :... | 2015/08/24 | [
"https://vi.stackexchange.com/questions/4488",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1539/"
] | For example, I have the following `autocommand` definition:
```
augroup cursorline
autocmd!
autocmd WinLeave,BufLeave * set nocursorline
autocmd WinEnter,BufEnter * set cursorline
augroup end
```
I want to define something that excludes `*.tex` files:
```
autocmd WinEnter,BufEnter * "except *.tex" set c... | How about:
```
autocmd WinEnter,BufEnter * if &filetype != "latex" && &filetype != "plaintex" | set cursorline | endif
```
better formatted as
```
autocmd WinEnter,BufEnter * if &filetype != "latex" && &filetype != "plaintex"
\ | set cursorline
\ | endif
`... |
4,493 | <p>I've gone through the <code>autocmd.txt</code> help, but the information about this is scattered and not always present (eg. with <code>BufRead</code>). </p>
<p>Could someone who understands this well list the order of these events - with perhaps the conditions marked in parantheses, like </p>
<pre><code>WinEnter ... | [
{
"answer_id": 4495,
"author": "Sundar R",
"author_id": 2374,
"author_profile": "https://vi.stackexchange.com/users/2374",
"pm_score": 5,
"selected": true,
"text": "<p>I tried googling for this with different sets of keywords, and struck gold on one such attempt with this result:\n<a hre... | 2015/08/24 | [
"https://vi.stackexchange.com/questions/4493",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2374/"
] | I've gone through the `autocmd.txt` help, but the information about this is scattered and not always present (eg. with `BufRead`).
Could someone who understands this well list the order of these events - with perhaps the conditions marked in parantheses, like
```
WinEnter
BufEnter (if this window is for a differ... | I tried googling for this with different sets of keywords, and struck gold on one such attempt with this result:
<https://developer.ibm.com/tutorials/l-vim-script-5/>
Specifically, this part is relevant to the current question:
>
> For example, if you start Vim, edit a file named demo.txt, swap into Insert mode, typ... |
4,523 | <p>Is there a way to tell vim not to spell-check part of a latex document?
For instance, code block using the <code>minted</code> environment or URLs in <code>\url{}</code>?</p>
<p>(I'm not sure it's relevant for spell checking but I'm using the <a href="https://github.com/lervag/vimtex" rel="noreferrer">vimtex</a> pl... | [
{
"answer_id": 4524,
"author": "jjaderberg",
"author_id": 1306,
"author_profile": "https://vi.stackexchange.com/users/1306",
"pm_score": 4,
"selected": false,
"text": "<p>You can disable spell checking for syntax items by adding them to a cluster together with <code>@NoSpell</code>. You ... | 2015/08/26 | [
"https://vi.stackexchange.com/questions/4523",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3320/"
] | Is there a way to tell vim not to spell-check part of a latex document?
For instance, code block using the `minted` environment or URLs in `\url{}`?
(I'm not sure it's relevant for spell checking but I'm using the [vimtex](https://github.com/lervag/vimtex) plugin to edit latex files.) | You can disable spell checking for syntax items by adding them to a cluster together with `@NoSpell`. You can read `:help spell-syntax` for some information and look at your tex syntax file which most likely contains several examples already. If you type `:tabe $VIMRUNTIME/syntax/tex.vim` you should get the tex syntax ... |
4,528 | <p>I followed the link <a href="https://superuser.com/questions/844004/creating-a-simple-vim-syntax-highlighting">creating-a-simple-vim-syntax-highlighting</a>, for doing the syntax highlighting for my purpose.
This is really nice., but it's static. So, keywords are to be predefined.</p>
<p>In a situation, where i see... | [
{
"answer_id": 4524,
"author": "jjaderberg",
"author_id": 1306,
"author_profile": "https://vi.stackexchange.com/users/1306",
"pm_score": 4,
"selected": false,
"text": "<p>You can disable spell checking for syntax items by adding them to a cluster together with <code>@NoSpell</code>. You ... | 2015/08/26 | [
"https://vi.stackexchange.com/questions/4528",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3323/"
] | I followed the link [creating-a-simple-vim-syntax-highlighting](https://superuser.com/questions/844004/creating-a-simple-vim-syntax-highlighting), for doing the syntax highlighting for my purpose.
This is really nice., but it's static. So, keywords are to be predefined.
In a situation, where i see lot of pointers or a... | You can disable spell checking for syntax items by adding them to a cluster together with `@NoSpell`. You can read `:help spell-syntax` for some information and look at your tex syntax file which most likely contains several examples already. If you type `:tabe $VIMRUNTIME/syntax/tex.vim` you should get the tex syntax ... |
4,535 | <p>I have the following on my vimrc file to handle custom folding:</p>
<pre><code>" ++ Folding
set foldenable " enable folding
set foldmethod=syntax " global folding method ... | [
{
"answer_id": 4536,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 2,
"selected": true,
"text": "<p>You can do that with a modeline and an autocommand. E.g. </p>\n\n<p>The modeline :</p>\n\n<pre><code>\" vim: set sw=4 ts=4 ... | 2015/08/27 | [
"https://vi.stackexchange.com/questions/4535",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/977/"
] | I have the following on my vimrc file to handle custom folding:
```
" ++ Folding
set foldenable " enable folding
set foldmethod=syntax " global folding method
set foldle... | You can do that with a modeline and an autocommand. E.g.
The modeline :
```
" vim: set sw=4 ts=4 sts=4 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker spell:
```
With this modeline I can fold my vimrc based on `{}` pairs.
The autocommands :
```
augroup FileTypeVim
autocmd!
" Source your vimrc on sav... |
4,541 | <p>I installed vundle yesterday and since I did, the tabwidth I configured in my vimrc is ignored and set back to 4 instead of 2.</p>
<p>I found out that the following line after the vundle paragraph is causing it:</p>
<pre><code>filetype plugin indent on
</code></pre>
<p>My indentation is set up like this:</p>
<pr... | [
{
"answer_id": 4546,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 5,
"selected": true,
"text": "<p>First things first; the line below has absolutely <em>nothing</em> to do with Vundle or plugin management:</p>\n\n<pre><code>... | 2015/08/27 | [
"https://vi.stackexchange.com/questions/4541",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3331/"
] | I installed vundle yesterday and since I did, the tabwidth I configured in my vimrc is ignored and set back to 4 instead of 2.
I found out that the following line after the vundle paragraph is causing it:
```
filetype plugin indent on
```
My indentation is set up like this:
```
set noexpandtab " Make sure that eve... | First things first; the line below has absolutely *nothing* to do with Vundle or plugin management:
```
filetype plugin indent on
```
That command does three things:
* enables filetype detection,
* enables filetype-specific scripts (ftplugins),
* enables filetype-specific indent scripts.
That line is there because... |
4,552 | <p>Let's say I'm a terrible person and I'm thinking about remapping <code><CR></code> to do what <code>:</code> normally does (start command-line mode).</p>
<p>Vim's built-in <code>netrw</code> plugin also remaps <code><CR></code> to open the selected directory or file. Specifically, it appears to map it t... | [
{
"answer_id": 4553,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<p>Netrw's documentation recommends putting your custom mappings in:</p>\n\n<pre><code>~/.vim/after/ftplugin/netrw.vim ... | 2015/08/27 | [
"https://vi.stackexchange.com/questions/4552",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Let's say I'm a terrible person and I'm thinking about remapping `<CR>` to do what `:` normally does (start command-line mode).
Vim's built-in `netrw` plugin also remaps `<CR>` to open the selected directory or file. Specifically, it appears to map it to
```
:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1, <SID... | This is what I ended up doing:
```
function! s:ConfigureNetrw()
let prior = maparg("<CR>", "n")
if prior != ":"
execute "nnoremap <buffer> o " . prior
nnoremap <buffer> <CR> :
endif
endfunction
augroup netrw_configuration
autocmd!
autocmd FileType netrw call s:ConfigureNetrw()
augroup end
```
It t... |
4,554 | <p>I've write myself a function, which receive a motion and perform it in other window. However, a problem raises when I need to map a real motion to a key sequence:</p>
<pre><code>nnoremap <c-p> :call Motion('\<C-F>')<cr>
</code></pre>
<p>Unexpectedly, <code>vim</code> executes <code><C-F></c... | [
{
"answer_id": 4569,
"author": "tokoyami",
"author_id": 20,
"author_profile": "https://vi.stackexchange.com/users/20",
"pm_score": 2,
"selected": false,
"text": "<p>You can pass a literal <code>Ctrl+f</code> by pressing <kbd>Ctrl</kbd><kbd>v</kbd><kbd>Ctrl</kbd><kbd>f</kbd> in insert mod... | 2015/08/27 | [
"https://vi.stackexchange.com/questions/4554",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1097/"
] | I've write myself a function, which receive a motion and perform it in other window. However, a problem raises when I need to map a real motion to a key sequence:
```
nnoremap <c-p> :call Motion('\<C-F>')<cr>
```
Unexpectedly, `vim` executes `<C-F>` for me when I just want `vim` to put `<C-F>` there as string litera... | You can pass a literal `Ctrl+f` by pressing `Ctrl``v``Ctrl``f` in insert mode, but I'm not sure this will work for you.
The other method which I find more correct (or easier and more widely used) is to pass the key/motion as a string and use `:execute` to create the maps inside your function. Here is an example from t... |
4,556 | <p>Is there a command to undo the last operation performed while in insert mode?</p>
<p>I just pasted text from the wrong register using <code><C-r></code>, and I have two options:</p>
<ol>
<li>Delete by hand what I just pasted and start over.</li>
<li>Switch to normal mode, hit <code>u</code> and lose the text... | [
{
"answer_id": 4557,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 3,
"selected": false,
"text": "<p>From insert mode:</p>\n\n<ol>\n<li><p>If your pasted text is smaller than one line (which is what your 2nd point implie... | 2015/08/27 | [
"https://vi.stackexchange.com/questions/4556",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3079/"
] | Is there a command to undo the last operation performed while in insert mode?
I just pasted text from the wrong register using `<C-r>`, and I have two options:
1. Delete by hand what I just pasted and start over.
2. Switch to normal mode, hit `u` and lose the text I typed before hitting `<C-r>`.
Is there a better wa... | Vim offers a limited ability to specify the scope of an undoable change with the `Ctrl-G u` command, which breaks the undo sequence. See
```
:help i_CTRL-G_u
```
In your case, the solution would be to remap `<C-R>` like this:
```
:inoremap <C-R> <C-G>u<C-R>
```
Then typing `<C-O>u` will undo just the changes made... |
4,561 | <p>I am breaking apart some files, and I'd like to paste what I cut into a brand new file, which I specify the name of. Something like:</p>
<pre><code>:c file-that-doesnt-exist.txt
</code></pre>
<p>Where <code>c</code> is a key command.</p>
<p><strong>Edit</strong> I've found <code>:e</code>, but that just takes me ... | [
{
"answer_id": 4562,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 4,
"selected": true,
"text": "<p>A fast way, working on entire lines, is to visually select the lines to move (<code>V</code> ...), then:</p>\n\n<pre><co... | 2015/08/27 | [
"https://vi.stackexchange.com/questions/4561",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3344/"
] | I am breaking apart some files, and I'd like to paste what I cut into a brand new file, which I specify the name of. Something like:
```
:c file-that-doesnt-exist.txt
```
Where `c` is a key command.
**Edit** I've found `:e`, but that just takes me to a new buffer with the same clipboard. I would just like to magica... | A fast way, working on entire lines, is to visually select the lines to move (`V` ...), then:
```
:'<,'>write! >> the_other_file.txt
```
... where `'<,'>` is automatically appended by Vim after you press `:`. This will append the range to that file, creating it if it doesn't exist. Then, a `gv` in normal mode will r... |
4,566 | <p>Is there a way to search files with netrw similar to find command in linux?</p>
<p>So in command line I can do</p>
<pre><code>find . -name "pattern"
</code></pre>
<p>Is there something similar in netrw?</p>
| [
{
"answer_id": 4568,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": true,
"text": "<p>You have plugins to do so :</p>\n\n<ul>\n<li><a href=\"http://kien.github.io/ctrlp.vim/\" rel=\"nofollow\">Ctrl-P</a></li>\... | 2015/08/28 | [
"https://vi.stackexchange.com/questions/4566",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2710/"
] | Is there a way to search files with netrw similar to find command in linux?
So in command line I can do
```
find . -name "pattern"
```
Is there something similar in netrw? | You have plugins to do so :
* [Ctrl-P](http://kien.github.io/ctrlp.vim/)
* [Command-T](http://www.vim.org/scripts/script.php?script_id=3025)
Or you can do by hand :
With a unix command from vim :
```
:!find . -name "pattern"
```
With the `Explore` command :
```
:Explore pattern
```
Based on [this post](http://... |
4,572 | <p>I am trying to make vim auto indent with tabs, and align with whitespaces, but actually, vim indent with tabs and fill the alignment with tabs + white spaces.</p>
<p>Vim does it :</p>
<p><a href="https://i.stack.imgur.com/RLVtl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RLVtl.png" alt="ente... | [
{
"answer_id": 5862,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": false,
"text": "<p>Doing this truly automatically is difficult. Vim doesn't know what is \"indentation\" and what is \"alignment\"; and... | 2015/08/29 | [
"https://vi.stackexchange.com/questions/4572",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2131/"
] | I am trying to make vim auto indent with tabs, and align with whitespaces, but actually, vim indent with tabs and fill the alignment with tabs + white spaces.
Vim does it :
[](https://i.stack.imgur.com/RLVtl.png)
(each block is a tab)
```
{
>--long... | Doing this truly automatically is difficult. Vim doesn't know what is "indentation" and what is "alignment"; and some people may disagree on what exactly constitutes indentation and alignment.
That being said, the [Smart Tabs plugin](http://www.vim.org/scripts/script.php?script_id=231) is designed to do what you want;... |
4,575 | <p>Is there a dedicated way to merge two blocks of text by interleaving lines, like passing from this:</p>
<pre><code>a1
a2
a3
a4
b1
b2
b3
b4
</code></pre>
<p>to that:</p>
<pre><code>a1
b1
a2
b2
a3
b3
a4
b4
</code></pre>
<p>in a few commands?</p>
<p><strong>EDIT</strong>: I really like <a href="htt... | [
{
"answer_id": 4576,
"author": "Sato Katsura",
"author_id": 2313,
"author_profile": "https://vi.stackexchange.com/users/2313",
"pm_score": 4,
"selected": true,
"text": "<p>There is no dedicated way to do that (as far as I know), but yeah, it can be done with a few commands:</p>\n\n<pre><... | 2015/08/29 | [
"https://vi.stackexchange.com/questions/4575",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2978/"
] | Is there a dedicated way to merge two blocks of text by interleaving lines, like passing from this:
```
a1
a2
a3
a4
b1
b2
b3
b4
```
to that:
```
a1
b1
a2
b2
a3
b3
a4
b4
```
in a few commands?
**EDIT**: I really like [Sato Katsura's solution](https://vi.stackexchange.com/a/4576/1841), here is how ... | There is no dedicated way to do that (as far as I know), but yeah, it can be done with a few commands:
```
function! Interleave(start, end, where)
if a:start < a:where
for i in range(0, a:end - a:start)
execute a:start . 'm' . (a:where + i)
endfor
else
for i in range(a:end -... |
4,577 | <p>If I want to go to the next <code>,</code> on the line then I type <code>t,</code>. If I wanted to go to the previous <code>,</code> I could use <code>/n</code>, enter, <code>N</code> but this is a bit of a fiddle. What is the best way to go to reverse the <code>t</code> command and go to the previous <code>,</code>... | [
{
"answer_id": 4578,
"author": "jjaderberg",
"author_id": 1306,
"author_profile": "https://vi.stackexchange.com/users/1306",
"pm_score": 3,
"selected": false,
"text": "<p>Just scroll down one paragraph in the help from <code>:help t</code> to find <code>T</code>, which moves </p>\n\n<blo... | 2015/08/29 | [
"https://vi.stackexchange.com/questions/4577",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3155/"
] | If I want to go to the next `,` on the line then I type `t,`. If I wanted to go to the previous `,` I could use `/n`, enter, `N` but this is a bit of a fiddle. What is the best way to go to reverse the `t` command and go to the previous `,`? | You can just use `T,` and `F,` instead of `t,` and `f,`. The lowercase commands go forward; the uppercase ones go backwards.
**Example**:
```
foo, b|ar, baz
```
With the cursor on the first `a`, `t,` would move forward to `r` (the character before the next comma). Now if you use `T,` you will go backwards to the ch... |
4,580 | <p>Is there a way to call Vim in such a way that it opens a buffer with some content specified on the terminal, i.e. not saved in a file?</p>
<p>For example, I would like to run <code>vim</code> and have it open a buffer with <code>foo, bar, baz and qux</code> written on it.</p>
<p>Is there an option that does this?<... | [
{
"answer_id": 4581,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 5,
"selected": true,
"text": "<p>Did you try something like this?</p>\n\n<pre><code>$ echo \"foo, bar, baz, and qux\" | vim -\n</code></pre>\n\n<p>Or like tha... | 2015/08/29 | [
"https://vi.stackexchange.com/questions/4580",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | Is there a way to call Vim in such a way that it opens a buffer with some content specified on the terminal, i.e. not saved in a file?
For example, I would like to run `vim` and have it open a buffer with `foo, bar, baz and qux` written on it.
Is there an option that does this? | Did you try something like this?
```
$ echo "foo, bar, baz, and qux" | vim -
```
Or like that?
```
$ vim -c "put='foo, bar, baz, and qux'"
``` |
4,584 | <p>How do I create my own list of auto-completion for certain filetypes? </p>
<p>For example I would like css and html to autocomplete from the list of css classes in <a href="https://fortawesome.github.io/Font-Awesome/">FontAwesome</a>.</p>
| [
{
"answer_id": 4585,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": false,
"text": "<p><strong>EDIT</strong> Thanks to romainl's comment I've edited my answer to show how to create a user-defined completion f... | 2015/08/30 | [
"https://vi.stackexchange.com/questions/4584",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/237/"
] | How do I create my own list of auto-completion for certain filetypes?
For example I would like css and html to autocomplete from the list of css classes in [FontAwesome](https://fortawesome.github.io/Font-Awesome/). | Dictionary completion would be a cheap and non-intrusive solution:
1. save [fontawesome.txt](https://gist.github.com/romainl/8bfc2ab1b565c19cb6b9) somewhere on your machine,
2. put this in `after/ftplugin/css.vim` (create the file if it doesn't exist):
```
setlocal complete+=k
setlocal dictionary+=/path/to/fontawesom... |
4,600 | <p>I'm using Linux system. Two vims are opened in two terminals. Now I'd like to copy text from A to B. One way to do so is to select text in A, use mouse to copy, then switch to B, in the insert mode, command <code><c-r>+</code> will paste the text.</p>
<p>Is there anyway to perform it without using mouse? like... | [
{
"answer_id": 4604,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>I think the solution you already mention in your question is the correct one. If you want to reduce the number of ... | 2015/09/02 | [
"https://vi.stackexchange.com/questions/4600",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1080/"
] | I'm using Linux system. Two vims are opened in two terminals. Now I'd like to copy text from A to B. One way to do so is to select text in A, use mouse to copy, then switch to B, in the insert mode, command `<c-r>+` will paste the text.
Is there anyway to perform it without using mouse? like `"+yy` in A, when switch t... | You can check if Vim is built with clipboard support with:
```
:echo has('clipboard')
```
If the output is `1`, the following should be enough to achieve your goal:
```
"*y in source Vim
"*p in destination Vim
```
You can make it all a lot more seamless by synchronizing the clipboard register and the defaul... |
4,612 | <p>Is there a vimscript function that wraps text in a similar manner like <code>gqgq</code> does?</p>
<p>For example, if I have the following string variable:</p>
<pre><code>let txt = 'One foo, two bars and three bazes went up the hill'
</code></pre>
<p>I'd like to call something like:</p>
<pre><code>let indent = 4
l... | [
{
"answer_id": 4619,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 0,
"selected": false,
"text": "<p>No there is no such function and it wouldn't make much sense.</p>\n"
},
{
"answer_id": 4930,
"author"... | 2015/09/02 | [
"https://vi.stackexchange.com/questions/4612",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | Is there a vimscript function that wraps text in a similar manner like `gqgq` does?
For example, if I have the following string variable:
```
let txt = 'One foo, two bars and three bazes went up the hill'
```
I'd like to call something like:
```
let indent = 4
let textwith = 12
let wrapped = wrap(txt, indent, te... | This function does what I need
```
fu! TextWrap(text, width, indent)
let l:line = ''
let l:ret = ''
for word in split(a:text)
if len(l:line) + len(word) + 1 > a:width
if len(l:ret)
let l:ret .= "\n"
endif
let l:ret .= repeat(' ', a:indent) . l:line
let l:line = ''... |
4,613 | <p>I just discovered that vim obviously allows division by zero:</p>
<pre><code>:let a=42/0
:echo a
</code></pre>
<p>prints <code>2147483647</code> (which is the value of <code>a</code>).</p>
<p>Is this documented somewhere and why does vim allow division by zero?</p>
| [
{
"answer_id": 4614,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 4,
"selected": false,
"text": "<p>Here is why :</p>\n\n<pre><code>42 / 0 tends to +infinity\n</code></pre>\n\n<p>And how does Vim represent the largest numb... | 2015/09/02 | [
"https://vi.stackexchange.com/questions/4613",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | I just discovered that vim obviously allows division by zero:
```
:let a=42/0
:echo a
```
prints `2147483647` (which is the value of `a`).
Is this documented somewhere and why does vim allow division by zero? | This behavior is documented under [eval section](http://vimdoc.sourceforge.net/htmldoc/eval.html):
```
When dividing a Number by zero the result depends on the value:
0 / 0 = -0x80000000 (like NaN for Float)
>0 / 0 = 0x7fffffff (like positive infinity)
<0 / 0 = -0x7fffffff (like negative infinit... |
4,616 | <p>I currently run a series of commands on any file I am working on to compress the lines. That series is -</p>
<pre><code>G:a
PRESS ENTER KEY
.
:g/^./ .,/^$/-1 join
</code></pre>
<p>So I press <code>S-g</code>, <code>S-:</code>, <code>a</code>, <code>enter</code>, <code>.</code>, then run that regular expression. Th... | [
{
"answer_id": 4617,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": true,
"text": "<p>If you want to run a command from a vim function you can do so with the normal command : </p>\n\n<pre><code>normal! dd \n</... | 2015/09/02 | [
"https://vi.stackexchange.com/questions/4616",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1417/"
] | I currently run a series of commands on any file I am working on to compress the lines. That series is -
```
G:a
PRESS ENTER KEY
.
:g/^./ .,/^$/-1 join
```
So I press `S-g`, `S-:`, `a`, `enter`, `.`, then run that regular expression. This joins my lines.
```
function! CrunchLines()
exec G
exec :
exec a
exec return... | If you want to run a command from a vim function you can do so with the normal command :
```
normal! dd
```
This act as `dd` in normal mode.
The `!` prevent using user mapping, to you get the basic vim functionalities.
Now to compress your file you can go to the last line with `G` and then joins every lines with ... |
4,622 | <p>From time to time I want to search on the list of my currents mappings. I search either for mapped keys <em>(what <code>/<Space>a</code> does?)</em> or for a command <em>(What keys are mapped on <code>/MyFunction()<CR></code>?)</em></p>
<p>I know that I can output these mappings with <code>:map</code> (... | [
{
"answer_id": 4617,
"author": "nobe4",
"author_id": 1821,
"author_profile": "https://vi.stackexchange.com/users/1821",
"pm_score": 3,
"selected": true,
"text": "<p>If you want to run a command from a vim function you can do so with the normal command : </p>\n\n<pre><code>normal! dd \n</... | 2015/09/02 | [
"https://vi.stackexchange.com/questions/4622",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1841/"
] | From time to time I want to search on the list of my currents mappings. I search either for mapped keys *(what `/<Space>a` does?)* or for a command *(What keys are mapped on `/MyFunction()<CR>`?)*
I know that I can output these mappings with `:map` (or `:nmap`, `:vmap`, etc...) but this open a window where I can only ... | If you want to run a command from a vim function you can do so with the normal command :
```
normal! dd
```
This act as `dd` in normal mode.
The `!` prevent using user mapping, to you get the basic vim functionalities.
Now to compress your file you can go to the last line with `G` and then joins every lines with ... |
4,627 | <p>When I create a fold with <code>zfap</code>, vim displays something like:</p>
<pre><code>+-- 15 lines: myFunctionPrototype :: Test -> Test -> Bool
</code></pre>
<p>However, I would like vim not to display this number of lines.
I find this distracting, and not adding sufficient information in my case.</p>
... | [
{
"answer_id": 4628,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 2,
"selected": false,
"text": "<p>The text that is displayed for a closed fold is determined by the <code>'foldtext'</code> option. See</p>\n\n<pre><code... | 2015/09/02 | [
"https://vi.stackexchange.com/questions/4627",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1682/"
] | When I create a fold with `zfap`, vim displays something like:
```
+-- 15 lines: myFunctionPrototype :: Test -> Test -> Bool
```
However, I would like vim not to display this number of lines.
I find this distracting, and not adding sufficient information in my case.
I'd prefer:
```
+-- : myFunctionPrototype :: T... | to put in `.vimrc`:
```
set foldtext=MyFoldText()
function MyFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
return v:folddashes . sub
endfunction
```
`MyFoldText` is now the function that is responsible for displaying some text, when some lines have been fol... |
4,637 | <p>When I am recording a macro with <code>q</code> and I am done, I can type:</p>
<ul>
<li><code>q</code> to stop recording if I am in normal or visual mode.</li>
<li><code><c-o>q</code> to stop recording if I am in insert mode.</li>
<li><p>..</p>
<p>How do I stop recording if my macro ends in command mode? </p... | [
{
"answer_id": 4638,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 4,
"selected": false,
"text": "<p>One way to do it:</p>\n\n<ul>\n<li>start your macro as usual (e.g. <code>qq</code> ... other chars)</li>\n<li>when you ... | 2015/09/04 | [
"https://vi.stackexchange.com/questions/4637",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2978/"
] | When I am recording a macro with `q` and I am done, I can type:
* `q` to stop recording if I am in normal or visual mode.
* `<c-o>q` to stop recording if I am in insert mode.
* ..
How do I stop recording if my macro ends in command mode? | Another solution is when in command line mode, use `Ctrl-f`, and press `q` to stop recording.
`Ctrl-f` allows you to open the command line window, in which you can edit the command in normal mode. To validate the command, simply use enter.
---
Therefore, after having added something like:
```
cnoremap <c-q> <c-f>i... |
4,653 | <p>I have the following lines in my <code>.vimrc</code>:</p>
<pre><code>" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
</code></pre>
<p>Which I believe should disable all visual/audio bells and flashes. However, vim still flashes when I'm on the first line and try to move up (<co... | [
{
"answer_id": 4655,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 4,
"selected": true,
"text": "<p>Recent Vims have the <a href=\"http://vimhelp.appspot.com/options.txt.html#%27belloff%27\" rel=\"noreferrer\"><cod... | 2015/09/06 | [
"https://vi.stackexchange.com/questions/4653",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3354/"
] | I have the following lines in my `.vimrc`:
```
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
```
Which I believe should disable all visual/audio bells and flashes. However, vim still flashes when I'm on the first line and try to move up (`k`) or on the last line and try to move... | Recent Vims have the [`'belloff'`](http://vimhelp.appspot.com/options.txt.html#%27belloff%27) setting. Simply set it to all to disable all bells:
```
:set belloff=all
```
That should fix the flashing issue for you. This needs a [Vim 7.4 > 793 patchlevel](http://ftp.vim.org/vim/patches/7.4/7.4.793).
Read the help at... |
4,669 | <p>Text marked as<code>__bold__</code> or <code>_italic_</code> appears in the same color as normal text.</p>
<p>Headings and code do show up in different colors, so vim correctly recognizes the file as markdown.</p>
<p>This is no matter what colorscheme I use.</p>
<p>Is it possible to make text marked as bold or it... | [
{
"answer_id": 4734,
"author": "zool",
"author_id": 3079,
"author_profile": "https://vi.stackexchange.com/users/3079",
"pm_score": 0,
"selected": false,
"text": "<p>Looks like Vim default color schemes don't have the best support for markdown and use the HTML syntax file instead. That's ... | 2015/09/07 | [
"https://vi.stackexchange.com/questions/4669",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4446/"
] | Text marked as`__bold__` or `_italic_` appears in the same color as normal text.
Headings and code do show up in different colors, so vim correctly recognizes the file as markdown.
This is no matter what colorscheme I use.
Is it possible to make text marked as bold or italic in Markdown, highlighted in their own col... | Try something like that:
```
highlight htmlBold gui=bold guifg=#af0000 ctermfg=124
highlight htmlItalic gui=italic guifg=#ff8700 ctermfg=214
``` |
4,673 | <p>I am using the <a href="https://github.com/tpope/vim-fugitive" rel="nofollow">vim-fugitive</a> plugin and I encounter a strange behaviour. I don't know if it's really related to the plugin or not.</p>
<p>I am trying to open the <code>Gstatus</code> page in a new tab. So I am creating a new tab and call Gstatus on t... | [
{
"answer_id": 4680,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 3,
"selected": false,
"text": "<p>I'll just quote from the official plugin FAQ:</p>\n\n<blockquote>\n <p>FAQ</p>\n \n <p>Q: I installed the plugin and... | 2015/09/08 | [
"https://vi.stackexchange.com/questions/4673",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I am using the [vim-fugitive](https://github.com/tpope/vim-fugitive) plugin and I encounter a strange behaviour. I don't know if it's really related to the plugin or not.
I am trying to open the `Gstatus` page in a new tab. So I am creating a new tab and call Gstatus on the new tab :
```
:tabnew | Gstatus
```
And ... | I'll just quote from the official plugin FAQ:
>
> FAQ
>
>
> Q: I installed the plugin and started Vim. Why don't any of the commands
> exist?
>
>
> A: Fugitive cares about the current file, not the current working
> directory. Edit a file from the repository.
>
>
> Q: I opened a new tab. Why don't any of the ... |
4,682 | <p>When using Vim to read from stdin, it prints a informative message:</p>
<pre><code>$ echo foo | vim -
Vim: Reading from stdin...
$
</code></pre>
<p><strong>This is just an example. The actual use doesn't allow shell constructs.</strong> <a href="https://groups.google.com/forum/#!topic/vim_dev/MATXOzr2AdM"><code>v... | [
{
"answer_id": 4687,
"author": "zmo",
"author_id": 4434,
"author_profile": "https://vi.stackexchange.com/users/4434",
"pm_score": 4,
"selected": false,
"text": "<p>The answer to your <em>exact</em> question:</p>\n\n<blockquote>\n <p>Can I suppress that using only Vim options and/or vimr... | 2015/09/08 | [
"https://vi.stackexchange.com/questions/4682",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | When using Vim to read from stdin, it prints a informative message:
```
$ echo foo | vim -
Vim: Reading from stdin...
$
```
**This is just an example. The actual use doesn't allow shell constructs.** [`vim <(echo foo)`](https://groups.google.com/forum/#!topic/vim_dev/MATXOzr2AdM) is not an option.
Can I suppress t... | Starting with Vim 8.0.1308 (Nov 2017), you can use the "--not-a-term" option
with "quit":
```
$ echo hello | vi - --not-a-term -esc '%p|q!'
hello
```
Or with "exit":
```
$ echo hello | vi - --not-a-term -esc 'x!/dev/stdout'
hello
```
<http://github.com/vim/vim/issues/1552> |
4,695 | <p>I'm writing down a markdown table which looks like this:</p>
<pre><code>| 13/05/15 | 09:30-16:00 | 6.5 |
| 14/05/15 | 10:00-16:30 | 6.5 |
| 16/05/15 | 15:30-01:00 | 9.5 |
| 21/05/15 | 09:00-16:30 | 7.5 |
| 22/05/15 | 08:30-17:00 | 8.5 |
| 28/05/15 | 09:30-15:30 | 6 |
| 02/06/15 | 09:00-20:00 | 11 |
| 03/0... | [
{
"answer_id": 4696,
"author": "Kent",
"author_id": 1569,
"author_profile": "https://vi.stackexchange.com/users/1569",
"pm_score": 5,
"selected": true,
"text": "<p>I wrote a plugin: <a href=\"https://github.com/sk1418/HowMuch\" rel=\"noreferrer\">https://github.com/sk1418/HowMuch</a> wh... | 2015/09/10 | [
"https://vi.stackexchange.com/questions/4695",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3079/"
] | I'm writing down a markdown table which looks like this:
```
| 13/05/15 | 09:30-16:00 | 6.5 |
| 14/05/15 | 10:00-16:30 | 6.5 |
| 16/05/15 | 15:30-01:00 | 9.5 |
| 21/05/15 | 09:00-16:30 | 7.5 |
| 22/05/15 | 08:30-17:00 | 8.5 |
| 28/05/15 | 09:30-15:30 | 6 |
| 02/06/15 | 09:00-20:00 | 11 |
| 03/06/15 | 08:30-2... | I wrote a plugin: <https://github.com/sk1418/HowMuch> which supports visual selection and does math calculations.
By default the plugin supports three math-expression evaluation engines: Gnu bc, python, and vimscript. You can do the calculations on a certain one or let the plugin automatically choose one for you.
It... |
4,700 | <p>Indexing a Latex document, I added a lot of <code>\index[]{}</code> commands in \footcite prenotes. It's stupid! Anyway, in my code I have a lot of :</p>
<pre><code>\footcite[blabla blabla\index[n]{something} blabla.][postnote]{Reference}
</code></pre>
<p>or sometimes :</p>
<pre><code>\footcite[blabla blabla\inde... | [
{
"answer_id": 4701,
"author": "Hovercouch",
"author_id": 978,
"author_profile": "https://vi.stackexchange.com/users/978",
"pm_score": 3,
"selected": true,
"text": "<p>If the <code>\\footcite</code> is always one line, you could do something like this:</p>\n\n<ul>\n<li><code>%g/\\footcit... | 2015/09/10 | [
"https://vi.stackexchange.com/questions/4700",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4492/"
] | Indexing a Latex document, I added a lot of `\index[]{}` commands in \footcite prenotes. It's stupid! Anyway, in my code I have a lot of :
```
\footcite[blabla blabla\index[n]{something} blabla.][postnote]{Reference}
```
or sometimes :
```
\footcite[blabla blabla\index[n]{something} blabla\index[n]{otherthing} blab... | If the `\footcite` is always one line, you could do something like this:
* `%g/\footcite[/s/\index.\{-}[}]//cg` Select every line with "footcite" on it, and *only* on those lines take every string of the form "\index any characters ]" and remove it.
The `c` ensures that if some of the `index`s are outside of the cite... |
4,717 | <p>I am trying to achieve the following : </p>
<ol>
<li>Having a set of predefined functions in my script</li>
<li>Having a map of relation between the functions and their argument</li>
<li>Calling the functions with their argument dynamically </li>
</ol>
<p>Here is the code that I have :</p>
<pre><code>function! s:... | [
{
"answer_id": 4718,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 4,
"selected": true,
"text": "<p>You defined the function <code>s:A</code>, but tried to call <code>function('A')</code> - they are not the same: functio... | 2015/09/12 | [
"https://vi.stackexchange.com/questions/4717",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1821/"
] | I am trying to achieve the following :
1. Having a set of predefined functions in my script
2. Having a map of relation between the functions and their argument
3. Calling the functions with their argument dynamically
Here is the code that I have :
```
function! s:A(a) abort
return 'A'.a:a
endfunction
function! ... | You defined the function `s:A`, but tried to call `function('A')` - they are not the same: function `A()` doesn't exist. (`:h E700` points directly to the `function()` call)
You'll probably have to use `'<SID>A'` in place of `'A'` as key (same for B, of course).
Also, `:h call()` (with braces; not `call`) might help ... |
4,728 | <p>I want to record a macro within a macro, like so:</p>
<pre><code>qa
[ first macro ... ]
qb
[ second macro ... ]
q
[ some more stuff, involving @b ... ]
q
</code></pre>
<p>However, the second <code>q</code> is interpreted as a request to stop the first macro, and the rest is interpreted as c... | [
{
"answer_id": 4729,
"author": "Kent",
"author_id": 1569,
"author_profile": "https://vi.stackexchange.com/users/1569",
"pm_score": 4,
"selected": false,
"text": "<p>AFAIK, you cannot record two macros by <code>qx...q</code> in one shot. For your requirement, you have to create macro <cod... | 2015/09/13 | [
"https://vi.stackexchange.com/questions/4728",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/88/"
] | I want to record a macro within a macro, like so:
```
qa
[ first macro ... ]
qb
[ second macro ... ]
q
[ some more stuff, involving @b ... ]
q
```
However, the second `q` is interpreted as a request to stop the first macro, and the rest is interpreted as commands.
Is there any way to begin r... | AFAIK, you cannot record two macros by `qx...q` in one shot. For your requirement, you have to create macro `b` by `qb....q`, then `qa...@bq`.
If you don't want to "record" `b` you can do `let @b='whatever'` then `@b` will replay the macro. E.g. `let @b='ggdG'` define a macro `b` to remove all content of your current ... |
4,735 | <p>This is a noob question, so basically in vim I want to run <code>ctags -R</code> when I am writing to my source or header files (<code>*.h</code> or <code>*.cpp</code>) so I tried the following:</p>
<pre><code>autocmd BufWritePost *.cpp :!ctags -R
autocmd BufWritePost *.h :!ctags -R
</code></pre>
<p>It seems to wo... | [
{
"answer_id": 4738,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 4,
"selected": true,
"text": "<p>When you execute an external command with <code>:!</code>, Vim doesn't know what the external command might have written... | 2015/09/14 | [
"https://vi.stackexchange.com/questions/4735",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3050/"
] | This is a noob question, so basically in vim I want to run `ctags -R` when I am writing to my source or header files (`*.h` or `*.cpp`) so I tried the following:
```
autocmd BufWritePost *.cpp :!ctags -R
autocmd BufWritePost *.h :!ctags -R
```
It seems to work, but every time I save, it wants a confirmation, so I ha... | When you execute an external command with `:!`, Vim doesn't know what the external command might have written to the terminal, so it waits for you to confirm that you are ready to continue.
To avoid that, you can use the `system()` function like this:
```
autocmd BufWritePost *.cpp call system("ctags -R")
autocmd Buf... |
4,753 | <p>I have created a few mappings like so:</p>
<pre><code>:nnoremap <buffer> <leader>xyzABC :call SomeFunc('ABC')<CR>
:nnoremap <buffer> <leader>xyzDE :call SomeFunc('DE')<CR>
:nnoremap <buffer> <leader>xyzFoo18 :call SomeFunc('Foo18')<CR>
:nnoremap <buffer&... | [
{
"answer_id": 4754,
"author": "René Nyffenegger",
"author_id": 985,
"author_profile": "https://vi.stackexchange.com/users/985",
"pm_score": 3,
"selected": false,
"text": "<p>Thanks to Peter Rincker's comment, I have found the answer:</p>\n\n<pre><code>:nnoremap <buffer> <leader... | 2015/09/17 | [
"https://vi.stackexchange.com/questions/4753",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | I have created a few mappings like so:
```
:nnoremap <buffer> <leader>xyzABC :call SomeFunc('ABC')<CR>
:nnoremap <buffer> <leader>xyzDE :call SomeFunc('DE')<CR>
:nnoremap <buffer> <leader>xyzFoo18 :call SomeFunc('Foo18')<CR>
:nnoremap <buffer> <leader>xyzBar22 :call SomeFunc('Bar22')<CR>
```
which works as desi... | As @peter-rinckler said, it is probably easier to do it with a command:
```
command! -nargs=* Xyz :call SomeFunc(<q-args>)
```
Makes it possible to do (in normal mode)
```
:Xyz ABC
```
I don't really like the `input()` because you can't repeat those kinds of things easily. |
4,758 | <p>I sometimes need to write Greek words, but when I am using the Greek keyboard, hitting, say, <code><C-p></code> will be understood as <code><C-π></code> and not as the command I intend. This can be fixed with <code>:map <C-p> <C-π></code>. Can I do this for all letters without making a list o... | [
{
"answer_id": 4759,
"author": "Alexander Myshov",
"author_id": 500,
"author_profile": "https://vi.stackexchange.com/users/500",
"pm_score": 1,
"selected": false,
"text": "<p>I type in two languages too: Russian and English. And now I use this plugin <a href=\"https://github.com/lyokha/v... | 2015/09/18 | [
"https://vi.stackexchange.com/questions/4758",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4505/"
] | I sometimes need to write Greek words, but when I am using the Greek keyboard, hitting, say, `<C-p>` will be understood as `<C-π>` and not as the command I intend. This can be fixed with `:map <C-p> <C-π>`. Can I do this for all letters without making a list of all?
PS. Making a list of all does not produce a perfect ... | I would recommend `keymap`, which can solve your trouble. Put these in your vimrc
```
" set keymap=greek_utf-8
set iminsert=0
set imsearch=-1
```
to disable Greek as a default.You can toggle the option on (Greek) and off (English) using `<ctrl>+^` (you can also use `<ctrl>+6`, it is mapped on key, not on symbol) in ... |
4,767 | <p>I'd like to quickly replace all non word characters up to first word <code>\w</code> character with a space.</p>
<pre><code>----So that this line becomes
So that this line becomes
----------------And this line looks like this
And this line looks like this
--=======--^^---Likewise this becomes
... | [
{
"answer_id": 4769,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>Here is a possible solution which correct all the lines of your file in one command. <em>(Warning: might cause eye bleedi... | 2015/09/19 | [
"https://vi.stackexchange.com/questions/4767",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1132/"
] | I'd like to quickly replace all non word characters up to first word `\w` character with a space.
```
----So that this line becomes
So that this line becomes
----------------And this line looks like this
And this line looks like this
--=======--^^---Likewise this becomes
Likewise ... | ```
nnoremap <leader>! 0v<S-Right>hr<Space>
```
---
This possible solution may be also useful
```
:%s/^.\{-}\</\=repeat(' ',strlen(submatch(0)))/g
```
Read more
```
:h functions
:h function-list
``` |
4,773 | <p>What is the fastest sequence to delete to the end of line <strong>after</strong> the cursor position?</p>
<p>Example:</p>
<blockquote>
<p>I want to delete this line in a faster way</p>
</blockquote>
<p>Sequence: <code>5eD</code> will delete the last character of the word <code>line</code> </p>
<blockquote>
... | [
{
"answer_id": 4775,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": true,
"text": "<p><code>D</code> is an <em>inclusive</em> command that works over a motion that includes the cursor at one end and the last pri... | 2015/09/20 | [
"https://vi.stackexchange.com/questions/4773",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4599/"
] | What is the fastest sequence to delete to the end of line **after** the cursor position?
Example:
>
> I want to delete this line in a faster way
>
>
>
Sequence: `5eD` will delete the last character of the word `line`
>
> I want to delete this lin
>
>
>
Moving around with vim often put me on the first or l... | `D` is an *inclusive* command that works over a motion that includes the cursor at one end and the last printable character on the line at the other end. There is AFAIK no built-in way to turn an *inclusive* command into an *exclusive* command and vice versa.
The heaviest solution would be to define your own operators... |
4,774 | <p>Consider the following text:</p>
<pre><code>long foobar=(test);
int barbar=(something);
char foofoo=();
</code></pre>
<p>Suppose I have yanked some chunk of code which I want to place before each opening parenthesis, e.g. <code>funcName</code>. What I currently have to do is just manually enter the addition after... | [
{
"answer_id": 4776,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": true,
"text": "<p>In insert mode, you can use <code><C-r>\"</code> to insert the content of the unnamed register (replace <code>\"</code>... | 2015/09/20 | [
"https://vi.stackexchange.com/questions/4774",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1081/"
] | Consider the following text:
```
long foobar=(test);
int barbar=(something);
char foofoo=();
```
Suppose I have yanked some chunk of code which I want to place before each opening parenthesis, e.g. `funcName`. What I currently have to do is just manually enter the addition after selecting e.g. all the `(` via `Ctrl... | In insert mode, you can use `<C-r>"` to insert the content of the unnamed register (replace `"` with `b` if what you want to insert is stored in register `b`):
```
<C-v>jjI<C-r>"
``` |
4,777 | <p>Sometimes I want to try a pattern with <code>/</code> before doing <code>:%s/ …</code>; can I reuse it without having to type it all over? (or use the mouse.)</p>
| [
{
"answer_id": 4778,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 4,
"selected": true,
"text": "<p>Sure, just leave the pattern in the substitution empty:</p>\n\n<pre><code>:%s//replacement/\n</code></pre>\n"
},
{
... | 2015/09/20 | [
"https://vi.stackexchange.com/questions/4777",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4505/"
] | Sometimes I want to try a pattern with `/` before doing `:%s/ …`; can I reuse it without having to type it all over? (or use the mouse.) | Sure, just leave the pattern in the substitution empty:
```
:%s//replacement/
``` |
4,790 | <p>As the title. Basically I want to apply <code>set linebreak</code> to the <code>gundo</code> window.</p>
| [
{
"answer_id": 4791,
"author": "ryuichiro",
"author_id": 2961,
"author_profile": "https://vi.stackexchange.com/users/2961",
"pm_score": 1,
"selected": false,
"text": "<p>Before you get better answer, you can go to <code>/autoload/gundo.vim</code> (or wherever it is), there should be two ... | 2015/09/21 | [
"https://vi.stackexchange.com/questions/4790",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3316/"
] | As the title. Basically I want to apply `set linebreak` to the `gundo` window. | Try this:
```
augroup MyGundo
au!
au BufWinEnter __Gundo_Preview__ :setl linebreak wrap
augroup end
``` |
4,809 | <p>Say I entered <code>:e bla/bla/bla.txt</code> and I realize I want to put a <code>!</code> after the <code>e</code>. Can I get there without using the arrow keys?</p>
| [
{
"answer_id": 4810,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 4,
"selected": true,
"text": "<h3>Command Line Window</h3>\n\n<p>You can use <code>cmdline-window</code> to edit the command line the same way as you ... | 2015/09/22 | [
"https://vi.stackexchange.com/questions/4809",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4505/"
] | Say I entered `:e bla/bla/bla.txt` and I realize I want to put a `!` after the `e`. Can I get there without using the arrow keys? | ### Command Line Window
You can use `cmdline-window` to edit the command line the same way as you would any other window. Enter into this window by pressing `<c-f>` while on the command line or use `q:` in normal mode.
There is a similar [Vimcasts](http://vimcasts.org/) episode on the subject: [Refining search patter... |
4,815 | <p>For some reason I get, what I call an "uneven" output from Ack/Ag in the quickfix list window. </p>
<p>My project directory structure is the following:</p>
<pre><code>/home/user/projects/myproject
|
---- llvm-or1k
|
---- clang-or1k
</code></pre>
<p>I did a search with Ag using the following command:</p>
<pre... | [
{
"answer_id": 4816,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 4,
"selected": true,
"text": "<p>Yes, it is annoying.</p>\n\n<p>When Vim creates a quickfix list from the output of a program such as Ack, it creates a b... | 2015/09/23 | [
"https://vi.stackexchange.com/questions/4815",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2865/"
] | For some reason I get, what I call an "uneven" output from Ack/Ag in the quickfix list window.
My project directory structure is the following:
```
/home/user/projects/myproject
|
---- llvm-or1k
|
---- clang-or1k
```
I did a search with Ag using the following command:
```
:ag --nogroup --nocolor --column -S -... | Yes, it is annoying.
When Vim creates a quickfix list from the output of a program such as Ack, it creates a buffer for each file in the quickfix list using the name provided by the other program. This is often a full path name. Vim simplifies or resolves those names to relative path names upon certain events. The pro... |
4,817 | <p>Is there a way to run vim from command line to edit the last edited file?</p>
<p>Let say I first edit file <code>giorgio.sh</code>:</p>
<pre><code>$ vi giorgio.sh
</code></pre>
<p>Afterwards, I exit back to terminal</p>
<pre><code>$ do something...
$ do something else...
$ do something else again...
</code></pre... | [
{
"answer_id": 4818,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": false,
"text": "<p>For this purpose, I have definde the following alias in my shell:</p>\n\n<pre><code>alias lvim=\"vim -c \\\"norma... | 2015/09/23 | [
"https://vi.stackexchange.com/questions/4817",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/983/"
] | Is there a way to run vim from command line to edit the last edited file?
Let say I first edit file `giorgio.sh`:
```
$ vi giorgio.sh
```
Afterwards, I exit back to terminal
```
$ do something...
$ do something else...
$ do something else again...
```
Is there a way to edit again the file in vim, maybe using som... | **An heavy solution: the sessions**
Another possible option is to use the sessions mechanism:
First your vim version has to be compiled with the `+mksession` option. *(Use `:echo has('mksession')` to check that).*
Now when you are about to leave vim, use the following command:
```
:mksession!
```
This will create... |
4,820 | <p>For example I've the following text:</p>
<pre><code>This is my first line, but longer.
This is my first line
This is my second line, but longer.
This is my second line
This is my third line, but longer.
This is my third line
This
</code></pre>
<p>and I expect to remove the shorter lines which share the same (from ... | [
{
"answer_id": 4821,
"author": "VanLaser",
"author_id": 1800,
"author_profile": "https://vi.stackexchange.com/users/1800",
"pm_score": 3,
"selected": true,
"text": "<p>Probably not exactly the solution you expect, but I'd rather use something like this:</p>\n\n<pre><code>:g/^/ if search(... | 2015/09/23 | [
"https://vi.stackexchange.com/questions/4820",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | For example I've the following text:
```
This is my first line, but longer.
This is my first line
This is my second line, but longer.
This is my second line
This is my third line, but longer.
This is my third line
This
```
and I expect to remove the shorter lines which share the same (from beginning of the line) con... | Probably not exactly the solution you expect, but I'd rather use something like this:
```
:g/^/ if search('^' . getline('.'), 'wn') != line('.') | delete | endif
```
This will also remove duplicates (since you do mention *unique sentences*), e.g.
```
This
This is my first line, but longer.
This is my first line, bu... |
4,829 | <p>I have a giant html file which is a mess (not my fault). I want to add to some nodes (about 400) a unique id. They all have are of the same class, so I can add the id like this</p>
<pre><code>:% s/class="some-class"/& id=<some id>/
</code></pre>
<p>My problem is generating the id - its has to be unique f... | [
{
"answer_id": 4832,
"author": "jjaderberg",
"author_id": 1306,
"author_profile": "https://vi.stackexchange.com/users/1306",
"pm_score": 3,
"selected": true,
"text": "<p>Could you use the expression replacement (<code>:help sub-replace-expression</code>) and a simple counter function? So... | 2015/09/23 | [
"https://vi.stackexchange.com/questions/4829",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/342/"
] | I have a giant html file which is a mess (not my fault). I want to add to some nodes (about 400) a unique id. They all have are of the same class, so I can add the id like this
```
:% s/class="some-class"/& id=<some id>/
```
My problem is generating the id - its has to be unique for each match.
Any ideas? | Could you use the expression replacement (`:help sub-replace-expression`) and a simple counter function? Something like
```
function! MyCount()
if exists('w:count')
let w:count = w:counter + 1
else
let w:count = 1
endif
return w:count
endfunc
:%s/class="some-class"/\=submatch(0) . ' "... |
4,835 | <p>Has anyone used GNU global with vim? I'm navigating through a large C++ code base and have some trouble figuring out how to use it. I want to use its gtags-cscope functionality but I can't figure out how to generate a cross reference database which later I can connect to vim. </p>
<p>Any help in finding the solutio... | [
{
"answer_id": 4900,
"author": "user4688",
"author_id": 4688,
"author_profile": "https://vi.stackexchange.com/users/4688",
"pm_score": 1,
"selected": false,
"text": "<p>In the source code directory use the following command:</p>\n\n<pre><code>find . -name '*.cpp' -o -name '*.h' > gtag... | 2015/09/23 | [
"https://vi.stackexchange.com/questions/4835",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2865/"
] | Has anyone used GNU global with vim? I'm navigating through a large C++ code base and have some trouble figuring out how to use it. I want to use its gtags-cscope functionality but I can't figure out how to generate a cross reference database which later I can connect to vim.
Any help in finding the solution is appre... | GNU Global's distribution already has a couple of vim scripts that are pretty handy.
Look for 'gtags.vim' and 'gtags-cscope.vim' (the most adequate probably for what you want) in Global's installation directory, and just copy the one you prefer to your 'plugins' dir inside vim's config. The second script will do a
``... |
4,836 | <p>I'd like to replace the following code:</p>
<pre><code>ThisIsALoooongNameOfATwoDArray[100-rowIndex][j-2]-ThisIsALoooongNameOfATwoDArray[100+rowIndex][j+2];
</code></pre>
<p>by</p>
<pre><code>Ptr[j-2]-Ptr[j+2];
</code></pre>
<p>I tried the command <code>:%s/This.*ex\]/Ptr/g</code> (and <code>/gc</code> variation)... | [
{
"answer_id": 4900,
"author": "user4688",
"author_id": 4688,
"author_profile": "https://vi.stackexchange.com/users/4688",
"pm_score": 1,
"selected": false,
"text": "<p>In the source code directory use the following command:</p>\n\n<pre><code>find . -name '*.cpp' -o -name '*.h' > gtag... | 2015/09/24 | [
"https://vi.stackexchange.com/questions/4836",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1080/"
] | I'd like to replace the following code:
```
ThisIsALoooongNameOfATwoDArray[100-rowIndex][j-2]-ThisIsALoooongNameOfATwoDArray[100+rowIndex][j+2];
```
by
```
Ptr[j-2]-Ptr[j+2];
```
I tried the command `:%s/This.*ex\]/Ptr/g` (and `/gc` variation), It turns out the regular expression performs the longest matching and... | GNU Global's distribution already has a couple of vim scripts that are pretty handy.
Look for 'gtags.vim' and 'gtags-cscope.vim' (the most adequate probably for what you want) in Global's installation directory, and just copy the one you prefer to your 'plugins' dir inside vim's config. The second script will do a
``... |
4,844 | <p>I find <code>:set hlsearch</code> useful while I am entering the pattern; but I want the effect of <code>:noh</code> as soon as I press enter. Is that possible?</p>
| [
{
"answer_id": 4866,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>I think you can achieve what you want through the mapping</p>\n\n<pre><code>cnoremap <silent> <cr> <... | 2015/09/24 | [
"https://vi.stackexchange.com/questions/4844",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4505/"
] | I find `:set hlsearch` useful while I am entering the pattern; but I want the effect of `:noh` as soon as I press enter. Is that possible? | I think you can achieve what you want through the mapping
```
cnoremap <silent> <cr> <cr>:nohl<cr>
```
The above mapping should turn of highlighted searches after you have pressed enter to accept the search pattern.
Note, though, that the highlighting is turned back on with for instance `n` and `N`, i.e. when repea... |