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 |
|---|---|---|---|---|---|---|
257 | <p>I use Vi as my preferred (and, in fact, only) text editor on Linux Systems. I know how to change modes from normal to insert, and vice-versa.</p>
<p>Is it possible to have Vi automatically load into Insert Mode rather than Normal Mode?</p>
<p>I want this because I can only access my Linux over SSH, and my computer t... | [
{
"answer_id": 259,
"author": "OrangeTux",
"author_id": 153,
"author_profile": "https://vi.stackexchange.com/users/153",
"pm_score": 4,
"selected": false,
"text": "<pre><code>$ vim -y <file>\n</code></pre>\n\n<blockquote>\n <p>-y Easy mode. Implied for |evim| and |eview|. ... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/257",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I use Vi as my preferred (and, in fact, only) text editor on Linux Systems. I know how to change modes from normal to insert, and vice-versa.
Is it possible to have Vi automatically load into Insert Mode rather than Normal Mode?
I want this because I can only access my Linux over SSH, and my computer that I can use f... | You can use the `+startinsert` option (or `+star` for short) to start Vim with insert mode.
```
vim +star myfile.txt
```
If you want this to happen by default when starting Vim, you can make an alias (in your `.bashrc` or `.zshrc` for example) as follows:
```
alias vim="vim +startinsert"
```
However, that works o... |
258 | <p>I'm aiming to make scripts I write in a certain directory (or of a certain extension) automatically executable on creation. I can do this whenever a file is written to, using <a href="https://askubuntu.com/a/546239/158442">the following <code>autocmd</code></a>:</p>
<pre><code>autocmd BufWritePost *.py silent execu... | [
{
"answer_id": 270,
"author": "Dhruva Sagar",
"author_id": 74,
"author_profile": "https://vi.stackexchange.com/users/74",
"pm_score": 4,
"selected": true,
"text": "<p>This would set the file to be executable after writing to the file if it's not already executable</p>\n\n<pre><code>autoc... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/258",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | I'm aiming to make scripts I write in a certain directory (or of a certain extension) automatically executable on creation. I can do this whenever a file is written to, using [the following `autocmd`](https://askubuntu.com/a/546239/158442):
```
autocmd BufWritePost *.py silent execute "! chmod +x %"
```
What I don't... | This would set the file to be executable after writing to the file if it's not already executable
```
autocmd BufWritePost *.py
\ if getfperm(expand('%')) !~# 'x'
\| silent execute "! chmod +x %"
\| endif
```
I think this should be the better approach.
To make only a new file executable:
```
autocmd... |
265 | <p>The <a href="http://vim-latex.sourceforge.net/" rel="nofollow">Vim LaTeX-suite</a> includes a number of predefined LaTeX environments, including the obsolete¹ <code>eqnarray</code> and <code>eqnarray*</code> environments. I want to get rid of every last shadow of these environments in the LaTeX-suite. How do I do th... | [
{
"answer_id": 453,
"author": "jyalim",
"author_id": 44,
"author_profile": "https://vi.stackexchange.com/users/44",
"pm_score": 0,
"selected": false,
"text": "<p>If you just want to remove all the eqnarray's in the source, first run an <code>ack</code> or a recursive <code>grep</code> or... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/265",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/211/"
] | The [Vim LaTeX-suite](http://vim-latex.sourceforge.net/) includes a number of predefined LaTeX environments, including the obsolete¹ `eqnarray` and `eqnarray*` environments. I want to get rid of every last shadow of these environments in the LaTeX-suite. How do I do that (and replace them by other environments)?
---
... | While infuriating, a number of vim-latex's features can be customised without editing the source code.
Disable the `EEA` mapping
-------------------------
In `.vim/after/ftplugin/tex.vim`, add
```
call IMAP('EEA', 'EEA', 'tex')
```
Typing `EEA` in insert mode will no longer insert the `eqnarray` environment.
`F5`... |
268 | <p>One of the first things you learn in vimtutor is to follow links in the vim help files with <kbd>Ctrl</kbd>-<kbd>]</kbd>. I'm interested in creating my own tags/linking system in arbitrary files. For the sake of this question, let's say I'm creating a sort of TODO list in markdown.</p>
<p>Suppose that we have the f... | [
{
"answer_id": 275,
"author": "Dhruva Sagar",
"author_id": 74,
"author_profile": "https://vi.stackexchange.com/users/74",
"pm_score": 1,
"selected": false,
"text": "<p>VIM's <code>:find</code> and <code>gf</code> are quite awesome, I use them all the time, they rely on the vim setting <c... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/268",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/130/"
] | One of the first things you learn in vimtutor is to follow links in the vim help files with `Ctrl`-`]`. I'm interested in creating my own tags/linking system in arbitrary files. For the sake of this question, let's say I'm creating a sort of TODO list in markdown.
Suppose that we have the following minifile:
```
TODO... | I've implemented something like this using [Exuberant Ctags](http://ctags.sourceforge.net/) and a `.ctags` file
in the directory (should also work with `.ctags` in the home directory).
You can read up on using Ctags with arbitrary regex, but the gist of it is that you'll
be able to use that same `Ctrl`-`]` to go to th... |
269 | <p>When I'm editing English text, I need to work with full sentences instead of lines of text in the file. Using the default Vim commands for this kind of text manipulation is very awkward, because I may have to join and split lines redundantly in order to copy a given sentence in the file. As an example, I might want ... | [
{
"answer_id": 273,
"author": "Dhruva Sagar",
"author_id": 74,
"author_profile": "https://vi.stackexchange.com/users/74",
"pm_score": 4,
"selected": true,
"text": "<p>You already seem to be aware of the 'ap' text-object that represents a paragraph, similar to that there exist 2 text-obje... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/269",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/261/"
] | When I'm editing English text, I need to work with full sentences instead of lines of text in the file. Using the default Vim commands for this kind of text manipulation is very awkward, because I may have to join and split lines redundantly in order to copy a given sentence in the file. As an example, I might want to ... | You already seem to be aware of the 'ap' text-object that represents a paragraph, similar to that there exist 2 text-objects to deal with sentences, 'is' & 'as' for inner sentence & a (or around) sentence. You should use these along with sentence motions '(', ')' for moving them around if need be.
eg.) For moving sent... |
281 | <p>How can I figure out which key is set as my <code><Leader></code>, and how do I remap it?</p>
| [
{
"answer_id": 282,
"author": "OrangeTux",
"author_id": 153,
"author_profile": "https://vi.stackexchange.com/users/153",
"pm_score": 8,
"selected": true,
"text": "<p>By default your <code><leader></code> is <code>\\</code>, backslash. You can check it with:</p>\n\n<pre><code>:echo ... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/281",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/176/"
] | How can I figure out which key is set as my `<Leader>`, and how do I remap it? | By default your `<leader>` is `\`, backslash. You can check it with:
```
:echo mapleader
```
If this gives you an `E121: Undefined variable: mapleader`, it means it's set to the default of `\`. If it gives you something else, then it's that :-)
You can easily remap it. I mapped it to the space-bar:
```
:let maplea... |
285 | <p>For a long time now I've been using <a href="https://github.com/VundleVim/Vundle.vim" rel="noreferrer">Vundle</a> to manage my vim plugins. As best I can make out this basically just organizes plugins in an isolated directory structure and keeps track of updating them against source URLs where normally the plugin wo... | [
{
"answer_id": 291,
"author": "poxar",
"author_id": 127,
"author_profile": "https://vi.stackexchange.com/users/127",
"pm_score": 2,
"selected": false,
"text": "<p>I probably don't know all plugin managers, but most (including vundle), if not all, build on the plugin system that tpope inv... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/285",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/267/"
] | For a long time now I've been using [Vundle](https://github.com/VundleVim/Vundle.vim) to manage my vim plugins. As best I can make out this basically just organizes plugins in an isolated directory structure and keeps track of updating them against source URLs where normally the plugin would be manually arranged side b... | For a plugin to be Pathogen/Vundle/NeoBundle/Plug/VAM-compatible, it needs to follow the standard structure expected by Vim in your `~/.vim/` directory:
```
STANDARD STRUCTURE PLUGIN STRUCTURE
~/.vim/autoload/... ~/.vim/bundle/pluginname/autoload/...
/doc/... ... |
294 | <p>When I use <code>:cd</code> command in gvim it allows to complete the directories with a simple <code>Tab</code> press. However with <code>:o</code> command I only get <code>^I</code>.</p>
<p>How can I migrate the same bahavior from <code>:cd</code> to <code>:o</code>?</p>
| [
{
"answer_id": 295,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 4,
"selected": true,
"text": "<p>The <code>:o</code> command does something completely different, where tabs wouldn't really make sense:</p>\n\n<pre><code>Thi... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/294",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/245/"
] | When I use `:cd` command in gvim it allows to complete the directories with a simple `Tab` press. However with `:o` command I only get `^I`.
How can I migrate the same bahavior from `:cd` to `:o`? | The `:o` command does something completely different, where tabs wouldn't really make sense:
```
This command is in Vi, but Vim only simulates it:
*:o* *:op* *:open*
:[range]o[pen] Works like |:visual|: end Ex mode.
{Vi: star... |
298 | <p>I often have to edit various XML files with vim, which vary wildly in size - from configuration files containing a few hunded lines to production data files with sizes up to 2GB. Having syntax highlighting enabled is of course a very bad idea when dealing with huge files, thus I want to disable it if the file is big... | [
{
"answer_id": 299,
"author": "Dhruva Sagar",
"author_id": 74,
"author_profile": "https://vi.stackexchange.com/users/74",
"pm_score": 0,
"selected": false,
"text": "<p>This <code>autocmd BufReadPre * if getfsize(expand(\"%\")) > 10000000 | syntax off | endif</code> is what you need.</... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/298",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/117/"
] | I often have to edit various XML files with vim, which vary wildly in size - from configuration files containing a few hunded lines to production data files with sizes up to 2GB. Having syntax highlighting enabled is of course a very bad idea when dealing with huge files, thus I want to disable it if the file is bigger... | [This comment](https://vi.stackexchange.com/questions/298/disable-syntax-highlighting-depending-on-file-size-and-type#comment291_299) by [derobert](https://vi.stackexchange.com/users/31/derobert) led me to the solution:
```
autocmd Filetype xml if getfsize(@%) > 1000000 | setlocal syntax=OFF | endif
```
This seems t... |
300 | <p>The primary reason I like vim over emacs is that my hand movement distance away from the home row is very low (even as a programmer). However, the one main time that I do this is leaving insert mode, by pressing Escape.</p>
<p>I recently learned that I can use Ctrl+C to leave insert mode as well. However, this isn'... | [
{
"answer_id": 301,
"author": "shmup",
"author_id": 287,
"author_profile": "https://vi.stackexchange.com/users/287",
"pm_score": 8,
"selected": true,
"text": "<p>A common binding you'll see is <strong>jj</strong>, because it works well for QWERTY layouts if you use home row positioning.<... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/300",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/134/"
] | The primary reason I like vim over emacs is that my hand movement distance away from the home row is very low (even as a programmer). However, the one main time that I do this is leaving insert mode, by pressing Escape.
I recently learned that I can use Ctrl+C to leave insert mode as well. However, this isn't really a... | A common binding you'll see is **jj**, because it works well for QWERTY layouts if you use home row positioning.
```
inoremap jj <ESC>
```
In that case, to type a literal `jj` - you should wait for 1 sec (by default) between typing the second character. (see [`:help 'timeout'`](http://vimhelp.appspot.com/options.txt... |
310 | <p>When I open <code>vim</code> with multiple files (<code>vim f1 f2 ...</code>), how can I make it open them in tabs directly, without using <code>-p</code>?</p>
<p>I'm looking to separate out shell behaviour from vim behaviour, removing <code>vim</code>-based aliases, etc. That's why I'd prefer not to use aliases, e... | [
{
"answer_id": 544,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<p>I think adding something like this to your <code>.vimrc</code> may solve your problems (note, however, that I don't actuall... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/310",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | When I open `vim` with multiple files (`vim f1 f2 ...`), how can I make it open them in tabs directly, without using `-p`?
I'm looking to separate out shell behaviour from vim behaviour, removing `vim`-based aliases, etc. That's why I'd prefer not to use aliases, etc. (hence, no `-p`).
I'm pretty sure this one has be... | After some experimentation I've found this to be the best way; it should behave the same as `vim -p`:
```
augroup open-tabs
au!
au VimEnter * ++nested if !&diff | tab all | tabfirst | endif
augroup end
```
`tab all` opens all the entries in the argument list (`:args`) in a tab. The argument list is a list of... |
317 | <p>Some applications have the notion of a <em>"session"</em>, where you can run a command to load a file in an existing instance of an application.</p>
<p>For example, when I type:</p>
<pre><code>$ firefox http://vi.stackexchange.com
</code></pre>
<p>Firefox re-uses an existing Firefox process, rather than creating ... | [
{
"answer_id": 318,
"author": "craigp",
"author_id": 248,
"author_profile": "https://vi.stackexchange.com/users/248",
"pm_score": 6,
"selected": true,
"text": "<p>You need vim compiled with <code>+clientserver</code>, and then you can use the command:</p>\n\n<p><code>vim --servername SER... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/317",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | Some applications have the notion of a *"session"*, where you can run a command to load a file in an existing instance of an application.
For example, when I type:
```
$ firefox http://vi.stackexchange.com
```
Firefox re-uses an existing Firefox process, rather than creating a new one.
Is this possible with Vim? | You need vim compiled with `+clientserver`, and then you can use the command:
`vim --servername SERVER` to start a vim instance, and
`vim --servername SERVER --remote FILE` to open the file in the named vim instance.
---
### macOS only
MacVim runs a server by default - you can use
`mvim --remote-tab-silent` to ... |
319 | <p>Something I've found useful in other editors is the ability to:</p>
<ul>
<li>take the selected text</li>
<li>run an external command and pass the selection to its <code>stdin</code></li>
<li>take the external commands <code>stdout</code> and replace the current selection with it.</li>
</ul>
<p><em>This way you can... | [
{
"answer_id": 321,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": false,
"text": "<p>I find that often the easiest way is to use visual mode with <kbd>v</kbd> (or capital <kbd>V</kbd> to select whole li... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/319",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | Something I've found useful in other editors is the ability to:
* take the selected text
* run an external command and pass the selection to its `stdin`
* take the external commands `stdout` and replace the current selection with it.
*This way you can write useful text tools which operate on the selection using any l... | I find that often the easiest way is to use visual mode with `v` (or capital `V` to select whole lines), and select the text you want to pipe.
Then type:
```
:!cat
```
This doesn't do anything useful, as such. A useful command I use often is:
```
:!python -m json.tool
```
to format JSON.
You can also just type ... |
324 | <p>Many answers make reference to a "paste buffer" or a "search buffer". Can someone provide a quick primer on what types of buffer there are? Are they interchangeable? Or is it something different?</p>
| [
{
"answer_id": 326,
"author": "aharris88",
"author_id": 226,
"author_profile": "https://vi.stackexchange.com/users/226",
"pm_score": 3,
"selected": false,
"text": "<p>From the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#windows-intro\" rel=\"noreferrer\">vim help</a>:</p... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/324",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/69/"
] | Many answers make reference to a "paste buffer" or a "search buffer". Can someone provide a quick primer on what types of buffer there are? Are they interchangeable? Or is it something different? | From the [vim help](http://vimdoc.sourceforge.net/htmldoc/windows.html#windows-intro):
```
Summary:
A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.
A window is a viewport onto a buffer. You can use multiple windows on one
buffer, or severa... |
328 | <p>I want to have a quick way of setting the Vim <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#'paste'"><code>'paste'</code></a> option, inserting some text, and reverting to the previous value of <code>'paste'</code>.</p>
<p>A typical use case insert the OS clipboard content literally, regardles... | [
{
"answer_id": 331,
"author": "jamessan",
"author_id": 15,
"author_profile": "https://vi.stackexchange.com/users/15",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>except that I want to end up with the <code>'paste'</code> still active if it was active beforehand.</p>\n</... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/328",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8/"
] | I want to have a quick way of setting the Vim [`'paste'`](http://vimdoc.sourceforge.net/htmldoc/options.html#'paste') option, inserting some text, and reverting to the previous value of `'paste'`.
A typical use case insert the OS clipboard content literally, regardless of any insert mode rewriting that may be active, ... | Give this a try:
```
function! Paste_Func()
let s:inPaste = &paste
if !s:inPaste
set paste
endif
echom s:inPaste
augroup paste_callback
autocmd!
autocmd InsertLeave <buffer> call Paste_End()
augroup END
startinsert
endfunction
function! Paste_End()
augroup pas... |
338 | <p>I've heard rumours about Vim having some hidden "easter eggs" and jokes. Is this true? What are they?</p>
| [
{
"answer_id": 446,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>You can't do the dishes with Vim. From <a href=\"http://vimhelp.appspot.com/howto.txt.html\" rel=\"nofollow\"><code>:help howd... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/338",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | I've heard rumours about Vim having some hidden "easter eggs" and jokes. Is this true? What are they? | You can't do the dishes with Vim. From [`:help howdoi`](http://vimhelp.appspot.com/howto.txt.html):
```
|You can't! (yet)| do dishes using Vim
``` |
340 | <p>I just noticed that my trackpad scroll works in Vim, inertia and all. I'd like to change this to work horizontally - so I can scroll up and down to make the cursor move left-and-right instead of holding down the right arrow key for huge amounts of time.</p>
<p>How can I map my scrolling to left/right movement?</p>
| [
{
"answer_id": 350,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 2,
"selected": false,
"text": "<p>According to <code>:help scroll-mouse-wheel</code> the answer is no if you are using the Win32 GUI.</p>\n\n<p>On the othe... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/340",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2/"
] | I just noticed that my trackpad scroll works in Vim, inertia and all. I'd like to change this to work horizontally - so I can scroll up and down to make the cursor move left-and-right instead of holding down the right arrow key for huge amounts of time.
How can I map my scrolling to left/right movement? | According to `:help scroll-mouse-wheel` the answer is no if you are using the Win32 GUI.
On the other hand, using X11 GUI or console vim with mouse support, the wheel sends key presses that you can remap.
So, you could get the behaviour you describe by
```
:nmap <ScrollWheelUp> h
:nmap <ScrollWheelDown> l
```
Note... |
341 | <p>On some unixes sometime I found a command named <code>nvi</code>. It was a vi-like editor, without much of its functionality. Maybe it was a fork of the old <code>vi</code>?</p>
<p>Anyways, which <code>vi</code> versions are a fork of the others, and which are independent developments? Do they have a "family tree",... | [
{
"answer_id": 346,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 6,
"selected": true,
"text": "<p>From <code>nvi(1)</code>:</p>\n\n<pre><code>HISTORY\n The ex editor first appeared in 1BSD. The nex/nvi replacemen... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/341",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28/"
] | On some unixes sometime I found a command named `nvi`. It was a vi-like editor, without much of its functionality. Maybe it was a fork of the old `vi`?
Anyways, which `vi` versions are a fork of the others, and which are independent developments? Do they have a "family tree", similar to the unixes? | From `nvi(1)`:
```
HISTORY
The ex editor first appeared in 1BSD. The nex/nvi replacements for the
ex/vi editor first appeared in 4.4BSD.
```
Some background, from memory, so I hope got the details correct:
In the beginning, UNIX was free. Everyone could request a copy from Ken, and he
would send you a tape... |
343 | <p>Is there a way to edit binary files in some kind of hexadecimal mode?</p>
<p>For example if I have some binary data shown by <code>xxd</code> or <code>hexdump -C</code> like this:</p>
<pre><code>$ hexdump -C a.bin | head -n 5
00000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00 |................|
00000010 ... | [
{
"answer_id": 344,
"author": "janos",
"author_id": 135,
"author_profile": "https://vi.stackexchange.com/users/135",
"pm_score": 5,
"selected": false,
"text": "<p>To view the content of a binary file in a hex view,\nopen the file, switch on binary mode, and filter the buffer through the ... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/343",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/135/"
] | Is there a way to edit binary files in some kind of hexadecimal mode?
For example if I have some binary data shown by `xxd` or `hexdump -C` like this:
```
$ hexdump -C a.bin | head -n 5
00000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00 |................|
00000010 12 00 00 00 40 05 00 00 85 00 20 00 00 00 ... | The simplest way is to use the `binary` option. From `:help binary`:
```
This option should be set before editing a binary file. You can also
use the -b Vim argument. When this option is switched on a few
options will be changed (also when it already was on):
'textwidth' will be set to 0
'wrapmargin... |
356 | <p>When coding in different languages, I tend to need to restrict my lines to a specific length (usually 79 or 80 characters).</p>
<p>I've seen this done in other editors through the use of a ruler (solid line displayed at the column) or by changing the color of the text to indicate that it has gone over.</p>
<p>How ... | [
{
"answer_id": 357,
"author": "Kevin Brown-Silva",
"author_id": 89,
"author_profile": "https://vi.stackexchange.com/users/89",
"pm_score": 8,
"selected": true,
"text": "<p>You can display a ruler at a specific line using the <code>:set colorcolumn</code> (<code>:set cc</code> for short) ... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/356",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/89/"
] | When coding in different languages, I tend to need to restrict my lines to a specific length (usually 79 or 80 characters).
I've seen this done in other editors through the use of a ruler (solid line displayed at the column) or by changing the color of the text to indicate that it has gone over.
How can I have Vim in... | You can display a ruler at a specific line using the `:set colorcolumn` (`:set cc` for short) option which is only available in Vim 7.3 or later.
```
set colorcolumn=80
```
This will set the background color of that column to red, giving you a visual ruler to work from.
 a table I use in some documentation:</p>
<pre><code>+---------------+------------------------+---------------------------------------+
| TASK NAME | WHEN | DESCRIPTION |
+---------------+------------------------+--------------------------------------... | [
{
"answer_id": 381,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 3,
"selected": false,
"text": "<p>If you can use <code>sed</code> and <code>column</code>, a command-line solution that comes close would be:</p>\n\n<pre><code>... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/363",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Here is (part of) a table I use in some documentation:
```
+---------------+------------------------+---------------------------------------+
| TASK NAME | WHEN | DESCRIPTION |
+---------------+------------------------+---------------------------------------+
| db:seed ... | I am the author of the plugin
[vim-table-mode](https://github.com/dhruvasagar/vim-table-mode).
I've spent quite a lot of time building & improving this, especially with
community feedback and it caters exactly to this use case.
A short quickstart: You enter 'table mode' with the `:TableModeEnable` command,
you can the... |
365 | <p>I am looking for a possible solution for applying two different background colors inside a single vim buffer depending on context <a href="https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/light.png">like in this sublime text example</a>.</p>
<p>One use case of that is to color code sni... | [
{
"answer_id": 429,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": false,
"text": "<p>It's certainly possible to use a different background colour for syntax-highlighted elements. Just define the <code>guibg</cod... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/365",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/307/"
] | I am looking for a possible solution for applying two different background colors inside a single vim buffer depending on context [like in this sublime text example](https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/light.png).
One use case of that is to color code snippets inside markup f... | Because I was curious how well this would work, I've hacked something together
that sort of works.

As mentioned in the comments on the earlier answer, the only way to do this is
to fill up regions with spaces; which is exactly what we do; before wri... |
366 | <p>If I encrypt a file with <code>:set cryptmethod=blowfish</code> or <code>:set cryptmethod=blowfish2</code>, and open the file in Vim, it asks for my password on startup. I type in the <em>correct</em> password and continue happily.</p>
<p>However, if I enter the <em>wrong</em> password, Vim will show me something l... | [
{
"answer_id": 367,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": true,
"text": "<p>The best I've managed to do is use a wrapper script, I've named this <code>svim</code> and\nput it in <code>~/bin</cod... | 2015/02/04 | [
"https://vi.stackexchange.com/questions/366",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | If I encrypt a file with `:set cryptmethod=blowfish` or `:set cryptmethod=blowfish2`, and open the file in Vim, it asks for my password on startup. I type in the *correct* password and continue happily.
However, if I enter the *wrong* password, Vim will show me something like this:
```
<1f>íW><00>©?<11>·Á<91>´!<98>!... | The best I've managed to do is use a wrapper script, I've named this `svim` and
put it in `~/bin`:
```
#!/bin/sh
[ -z "$1" ] && (echo "We need a file"; exit 1)
[ -f "$1" ] || (echo "File needs to exist"; exit 1)
[ "$(head -c8 "$1")" = "VimCrypt" ] || (echo "File needs to be encrypted"; exit 1)
while :; do
vim -c... |
373 | <p>Sometimes I use <code>:s</code> with a complicated regexp which may or may not be correct, or I'm not sure if I want to replace <em>all</em> matches.</p>
<p>Is there any way I can tell Vim to confirm every match it finds before it actually replaces the text?</p>
| [
{
"answer_id": 374,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 6,
"selected": true,
"text": "<p>Yes! Use the <code>c</code> flag for <code>:substitute</code>. From <code>:help substitute</code>:</p>\n\n<pre><code>[... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/373",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Sometimes I use `:s` with a complicated regexp which may or may not be correct, or I'm not sure if I want to replace *all* matches.
Is there any way I can tell Vim to confirm every match it finds before it actually replaces the text? | Yes! Use the `c` flag for `:substitute`. From `:help substitute`:
```
[c] Confirm each substitution. Vim highlights the matching string (with
hl-IncSearch). You can type: :s_c
'y' to substitute this match
'l' to substitute this match and then quit... |
388 | <p>I have been looking at the different package managers for Vim, and the one I decided to use is <a href="https://github.com/junegunn/vim-plug" rel="noreferrer">vim-plug</a>.</p>
<p>However, I have seen others like <a href="https://github.com/tpope/vim-pathogen" rel="noreferrer">pathogen</a> and <a href="https://githu... | [
{
"answer_id": 390,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 6,
"selected": false,
"text": "<p><a href=\"https://github.com/tpope/vim-pathogen\">Pathogen</a> is simple. Essentially it just does:</p>\n\n<ul>\n<li>autoload ... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/388",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/326/"
] | I have been looking at the different package managers for Vim, and the one I decided to use is [vim-plug](https://github.com/junegunn/vim-plug).
However, I have seen others like [pathogen](https://github.com/tpope/vim-pathogen) and [vundle](https://github.com/gmarik/Vundle.vim), and I honestly don't know what the diff... | [vim-plug](https://github.com/junegunn/vim-plug) is a nice alternative to Vundle, it does things a bit different from a technical point of view which should make it faster ([see this](http://junegunn.kr/2013/09/writing-my-own-vim-plugin-manager/)). It has most (or all?) of the features of Vundle.
* Parallel update pro... |
410 | <p>I've sometimes tried invoking Vim using <code>xargs</code>, like this:</p>
<pre><code>find . -name '*.java' | xargs vim
</code></pre>
<p>… which kind of works:</p>
<ol>
<li><p>As Vim launches, I see the following warning flash briefly:</p>
<blockquote>
<pre><code>Vim: Warning: Input is not from a terminal
</code... | [
{
"answer_id": 412,
"author": "akshay",
"author_id": 246,
"author_profile": "https://vi.stackexchange.com/users/246",
"pm_score": 4,
"selected": false,
"text": "<h3>Workaround suggestion: use a buffer as a filesystem navigator</h3>\n\n<p>Use the <code>vim -</code> command to read a list ... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/410",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/24/"
] | I've sometimes tried invoking Vim using `xargs`, like this:
```
find . -name '*.java' | xargs vim
```
… which kind of works:
1. As Vim launches, I see the following warning flash briefly:
>
>
> ```
> Vim: Warning: Input is not from a terminal
>
> ```
>
>
2. Editing works — `:files` correctly enumerates all of ... | This happens when vim is invoked and it's connected to the previous pipeline's output, instead of the terminal and it's receiving different unexpected input (like NULs).
The same happens when you run: `vim < /dev/null`, so `reset` command in this case helps. This is explained well by [grawity at superuser](https://supe... |
415 | <p>For some reason or another I often divide the code into subsections separated by headers like these:</p>
<pre><code>################################################################################
#################################### LOAD ######################################
######################################... | [
{
"answer_id": 417,
"author": "200_success",
"author_id": 24,
"author_profile": "https://vi.stackexchange.com/users/24",
"pm_score": 3,
"selected": false,
"text": "<p>First, you need to <code>:set expandtab</code>.</p>\n\n<ol>\n<li><code>80</code><kbd>i</kbd><kbd>#</kbd><kbd>Esc</kbd> to... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/415",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/307/"
] | For some reason or another I often divide the code into subsections separated by headers like these:
```
################################################################################
#################################### LOAD ######################################
####################################################... | Here's a slightly more efficient / easier method. Type it with the cursor at the beginning of the line of text (i.e. `LOAD`) that you want to center.
* `:center 80<cr>`: center the text with Vim's built in function
* `hhv0r#`: add the `#`s on the left
* `A<space><esc>40A#<esc>`: add plenty of `#`s on the right
* `d80|... |
422 | <p>When I work on files in python, I sometimes mistake tabs for spaces and vice versa. Is there a way I can get Vim to display a character for a tab instead of a tab?</p>
| [
{
"answer_id": 423,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 9,
"selected": true,
"text": "<p>Yes, use listchars:</p>\n\n<pre><code>set list\nset listchars=tab:>-\n</code></pre>\n\n<p>If you put these two lines in yo... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/422",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25/"
] | When I work on files in python, I sometimes mistake tabs for spaces and vice versa. Is there a way I can get Vim to display a character for a tab instead of a tab? | Yes, use listchars:
```
set list
set listchars=tab:>-
```
If you put these two lines in your .vimrc, tabs will be shown as `>` for the start position and `-` through the rest of the tab.
(Sidenote: listchars can also show trailing spaces with `trail:x` (replace `x` with the character you want to use for a trailing ... |
432 | <p>If I do:</p>
<pre><code>$ less file
</code></pre>
<p>And press <code>q</code> to exit <code>less</code>, I stil see the same text as I had on the screen when <code>less</code> was still running.</p>
<p>However, if I do</p>
<pre><code>$ vim file
</code></pre>
<p>And <code>:q</code>, my terminal is blanked...</p>... | [
{
"answer_id": 435,
"author": "toro2k",
"author_id": 13,
"author_profile": "https://vi.stackexchange.com/users/13",
"pm_score": 6,
"selected": true,
"text": "<p>By default VIM, when terminating, sends the string configured with the option <code>t_te</code> to the hosting terminal to tell... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/432",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | If I do:
```
$ less file
```
And press `q` to exit `less`, I stil see the same text as I had on the screen when `less` was still running.
However, if I do
```
$ vim file
```
And `:q`, my terminal is blanked...
Screenshots of my terminal after quiting `less` and `vim`:
.</p>
<p>H... | [
{
"answer_id": 441,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>Setting names are always surrounded by quotes, so use:</p>\n\n<pre><code>:help 'display'\n</code></pre>\n\n<p>to get t... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/438",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/126/"
] | Occasionally, when I'm searching the help system for a particular topic, it will be shadowed by a different topic.
For example, if I do `:h display` I get help for something involving "GUI Resources", when I wanted help for the "display" setting (as in `set display=lastline`).
How can I find these "shadowed" topics, ... | Setting names are always surrounded by quotes, so use:
```
:help 'display'
```
to get the page you want.
You get some useful completions when pressing `Ctrl`+`D`, ie:
```
:help display<^D>
```
Will give you:
```
-display :display 'display' :syn-display strdisplaywidth()
```
As completions :-)
Bonus tip: ... |
439 | <p>The standard <kbd>J</kbd> command for joining lines replaces the newline character(s) with a space. It's useful when editing 'literature' but can be troublesome if I, say, edit a hex dump by hand if I forget to remove the superfluous space.</p>
<p>Is there a quick & easy method to join two lines without produci... | [
{
"answer_id": 440,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 8,
"selected": true,
"text": "<p>The <code>gJ</code> mapping does this; from <code>:help gJ</code>:</p>\n\n<blockquote>\n <p>Join [count] lines, with ... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/439",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/351/"
] | The standard `J` command for joining lines replaces the newline character(s) with a space. It's useful when editing 'literature' but can be troublesome if I, say, edit a hex dump by hand if I forget to remove the superfluous space.
Is there a quick & easy method to join two lines without producing a space between them... | The `gJ` mapping does this; from `:help gJ`:
>
> Join [count] lines, with a minimum of two lines. Don't insert or remove any spaces.
>
>
>
You could rebind it to `J`, if you want to save a keystroke:
```
:nnoremap J gJ
```
Note that this doesn't *remove* any spaces, so if either the current line ends with a s... |
454 | <p>It's pretty common when programming or opening text files to encounter files with trailing whitespace at the end of a line. vim has a way to show this by setting the <code>trail</code> option in the <code>listchars</code> option and then turning <code>list</code> on.</p>
<p>However, what's the easiest way to elimin... | [
{
"answer_id": 456,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 8,
"selected": false,
"text": "<p>The "simplest" way is to just use <code>:substitute</code>:</p>\n<pre><code>:%s/\\s\\+$//e\n</code></pre>\n... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/454",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | It's pretty common when programming or opening text files to encounter files with trailing whitespace at the end of a line. vim has a way to show this by setting the `trail` option in the `listchars` option and then turning `list` on.
However, what's the easiest way to eliminate that trailing whitespace globally acros... | Use a keybinding to strip all trailing whitespace
-------------------------------------------------
Since some pages that I edit actually need trailing whitespaces (e.g. markdown) and others don't, I set up a keybinding to `F5` so that it's trivial to do without being automatic. To do so, add the [code below (from vim... |
457 | <p>Vim has an Ex mode that can be entered by entering <kbd>Q</kbd>, and a command line mode that can be entered with <kbd>q</kbd><kbd>:</kbd>. A common complaint amongst new vim users is that they enter these modes accidentally when trying to quit vim. As such, I disable these keys in my <code>~/.vimrc</code> to stop m... | [
{
"answer_id": 461,
"author": "jamessan",
"author_id": 15,
"author_profile": "https://vi.stackexchange.com/users/15",
"pm_score": 8,
"selected": true,
"text": "<p><code>Q</code> is, as you found, ex mode. It's not entirely useful to use interactively, but it exists because Vim can be us... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/457",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | Vim has an Ex mode that can be entered by entering `Q`, and a command line mode that can be entered with `q``:`. A common complaint amongst new vim users is that they enter these modes accidentally when trying to quit vim. As such, I disable these keys in my `~/.vimrc` to stop myself hitting them accidentally (particul... | `Q` is, as you found, ex mode. It's not entirely useful to use interactively, but it exists because Vim can be used to emulate the old `ex` binary. In fact, many systems provide the `ex` command by simply symlinking it to `vim`.
`q:`, or `:<C-f>`, instead provides a way to browse your command-line history and edit it ... |
458 | <p>When working on a feature branch in <code>git</code>, I frequently need to stash my changes to commit a bug fix to the main branch. When I'm done working on the changes, I <code>git stash pop</code>, which updates the timestamps on the files.</p>
<p>Even though the files are identical, the next time I try to save, ... | [
{
"answer_id": 462,
"author": "Matthew S",
"author_id": 109,
"author_profile": "https://vi.stackexchange.com/users/109",
"pm_score": 7,
"selected": true,
"text": "<p>See <code>:help bufdo</code> for what you want to do. It will execute a command in each buffer in the buffer list. For e... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/458",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/323/"
] | When working on a feature branch in `git`, I frequently need to stash my changes to commit a bug fix to the main branch. When I'm done working on the changes, I `git stash pop`, which updates the timestamps on the files.
Even though the files are identical, the next time I try to save, I get:
>
> WARNING: The file h... | See `:help bufdo` for what you want to do. It will execute a command in each buffer in the buffer list. For example:
```
:bufdo e
```
You may also want to look at `:help noconfirm` to disable the confirmation dialog before issueing the `bufdo` command
```
:set noconfirm
```
and reenabling it after the `bufdo` com... |
475 | <p>Sometimes it happens that I open a file and make some modifications as my own
user, without noticing or "forgetting" to noticing the <code>[read-only]</code> warning in
the status line (ie. some random <code>/etc</code> config file like <code>/etc/resolv.conf</code>).</p>
<p><code>:w!</code> obviously fails in this... | [
{
"answer_id": 476,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 6,
"selected": true,
"text": "<p>The trick is to use an external call to <code>sudo</code>:</p>\n\n<pre><code>:w !sudo tee %\n</code></pre>\n\n<p>How t... | 2015/02/05 | [
"https://vi.stackexchange.com/questions/475",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/188/"
] | Sometimes it happens that I open a file and make some modifications as my own
user, without noticing or "forgetting" to noticing the `[read-only]` warning in
the status line (ie. some random `/etc` config file like `/etc/resolv.conf`).
`:w!` obviously fails in this case because my user has no write permission
anyway. ... | The trick is to use an external call to `sudo`:
```
:w !sudo tee %
```
How this works:
* `:w !<command>` executes `<command>` with the contents of the buffer as stdin.
* `tee` duplicates stdin to a file & stdout; `%` expands to the current filename..
* You prefix this with `sudo` for root permissions.
You're not *... |
478 | <p>Is there a way to make Vim fold functions based on the syntax of a function declaration? </p>
<p>For example having vim turn a function like this:</p>
<pre><code>def foobar(foo,bar):
if foo > bar:
print "foo"
elif foo < bar:
print "bar"
elif foo == bar:
print "foobar"
</code></pre>
<p>Into... | [
{
"answer_id": 480,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 3,
"selected": false,
"text": "<p>Sure:</p>\n\n<pre><code>set foldmethod=syntax\n</code></pre>\n\n<p>You can then use <code>zc</code> to close a fold, <code>z... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/478",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25/"
] | Is there a way to make Vim fold functions based on the syntax of a function declaration?
For example having vim turn a function like this:
```
def foobar(foo,bar):
if foo > bar:
print "foo"
elif foo < bar:
print "bar"
elif foo == bar:
print "foobar"
```
Into this:
```
+----- 7 lines: def foobar(... | Given that your example is in Python, which relies on correct indentation of code blocks it is enough to base folding on that:
```
:set foldmethod=indent
```
For more information on the varieties of folding available see [:help foldmethod](http://vimhelp.appspot.com/options.txt.html#%27foldmethod%27) |
484 | <h1>Intro</h1>
<p>When programming in C and C++ you usually split your function prototypes and actual functions into a <code>.h</code>/<code>.hpp</code> and <code>.c</code>/<code>.cpp</code> file. Sadly it's very tedious to transfer the function prototypes from one file to another, and requires opening both files at t... | [
{
"answer_id": 480,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 3,
"selected": false,
"text": "<p>Sure:</p>\n\n<pre><code>set foldmethod=syntax\n</code></pre>\n\n<p>You can then use <code>zc</code> to close a fold, <code>z... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/484",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/359/"
] | Intro
=====
When programming in C and C++ you usually split your function prototypes and actual functions into a `.h`/`.hpp` and `.c`/`.cpp` file. Sadly it's very tedious to transfer the function prototypes from one file to another, and requires opening both files at the same time (or a good memory), as well as a lot ... | Given that your example is in Python, which relies on correct indentation of code blocks it is enough to base folding on that:
```
:set foldmethod=indent
```
For more information on the varieties of folding available see [:help foldmethod](http://vimhelp.appspot.com/options.txt.html#%27foldmethod%27) |
485 | <p>Many CLI programs output nicely-highlighted text. While most of them check if the output is going to a file, some include the terminal escape codes. I like the output with the escape codes, but viewing these files in Vim is painful.</p>
<p>Can Vim interpret these escape codes into the expected colors? If not, can V... | [
{
"answer_id": 486,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 6,
"selected": false,
"text": "<p>There are various plugins which allow you to view ANSI colours through escape codes:</p>\n\n<ul>\n<li><p><a href=\"ht... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/485",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/323/"
] | Many CLI programs output nicely-highlighted text. While most of them check if the output is going to a file, some include the terminal escape codes. I like the output with the escape codes, but viewing these files in Vim is painful.
Can Vim interpret these escape codes into the expected colors? If not, can Vim be set ... | There are various plugins which allow you to view ANSI colours through escape codes:
* [AnsiEsc.vim](http://www.vim.org/scripts/script.php?script_id=302) – `:AnsiEsc`.
* [Colorizer](https://github.com/chrisbra/Colorizer) – `:ColorToggle`.
---
If you want to *remove* all escape codes, you could use:
```
:%s/<1b>\[[0... |
487 | <p>I am writing some documentation (a user guide),
in markdown in Vim.</p>
<p>I now realise what I thought should be one page, really should be 2.
But I've already written a lot of of both halves.</p>
<p>How can I split the file at the cursor (or some other marker), into two separate files?</p>
<h3>For Example:</h3>
<p... | [
{
"answer_id": 488,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 5,
"selected": true,
"text": "<ol>\n<li><p>Move the cursor to the last line of Part 1.</p></li>\n<li><p>Type <code>Vgg</code> to select the first part, and <c... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/487",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/360/"
] | I am writing some documentation (a user guide),
in markdown in Vim.
I now realise what I thought should be one page, really should be 2.
But I've already written a lot of of both halves.
How can I split the file at the cursor (or some other marker), into two separate files?
### For Example:
Wholefile.md:
```
But I... | 1. Move the cursor to the last line of Part 1.
2. Type `Vgg` to select the first part, and `:w Part1.md<cr>` to save that section to the first file.
3. Press ``>j`, which will move the cursor to the first line of Part 2.
4. Type `VG` to select the second part, and `:w Part2.md<cr>` to save that section to the second fi... |
501 | <p>If I open vim with multiple files on the command line, for example <code>vim debug.log*</code> which loads <code>debug.log</code>, <code>debug.log.1</code> and <code>debug.log.2</code>, can I navigate between them, assign them to multiple windows (<code>:split</code>/<code>:vsplit</code>) or such?</p>
<p>The only s... | [
{
"answer_id": 502,
"author": "200_success",
"author_id": 24,
"author_profile": "https://vi.stackexchange.com/users/24",
"pm_score": 5,
"selected": true,
"text": "<p>The most relevant help topic is <a href=\"https://vimhelp.appspot.com/windows.txt.html#%3Als\"><code>:ls</code></a>, also ... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/501",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/351/"
] | If I open vim with multiple files on the command line, for example `vim debug.log*` which loads `debug.log`, `debug.log.1` and `debug.log.2`, can I navigate between them, assign them to multiple windows (`:split`/`:vsplit`) or such?
The only shortcut I know for this mode of operation is `:n`, which loads the next file... | The most relevant help topic is [`:ls`](https://vimhelp.appspot.com/windows.txt.html#%3Als), also known as
[`:files`](https://vimhelp.appspot.com/windows.txt.html#%3Afiles) or
[`:buffers`](https://vimhelp.appspot.com/windows.txt.html#%3Abuffers).
In your `vim debug.log*` example, if you gave the `:ls` command, you w... |
510 | <p>I know I can <code>:!</code> or <code>:r!</code> to execute external command and optionally insert its output into text. I can even perform <code>:!sh</code> and I'll spawn a shell that will live until I exit it - but while the shell is active, Vim is 'asleep' and inaccessible. I must quit the shell, and spawn a new... | [
{
"answer_id": 517,
"author": "Bambu",
"author_id": 192,
"author_profile": "https://vi.stackexchange.com/users/192",
"pm_score": 5,
"selected": true,
"text": "<p>There are a couple of vim plugins that allow for this. I use <a href=\"https://code.google.com/p/conque/\">Conque</a> (<a href... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/510",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/351/"
] | I know I can `:!` or `:r!` to execute external command and optionally insert its output into text. I can even perform `:!sh` and I'll spawn a shell that will live until I exit it - but while the shell is active, Vim is 'asleep' and inaccessible. I must quit the shell, and spawn a new one if I want to return to Vim for ... | There are a couple of vim plugins that allow for this. I use [Conque](https://code.google.com/p/conque/) ([Github](https://github.com/jewes/Conque-Shell)).
After putting it in your plugins directory all you have to do is:
```
:ConqueTermSplit bash
```
And you will have an interactive bash shell in vim. You can the... |
528 | <p>It is easy to move to a specific character on the same line with <code>t</code> or <code>f</code>.</p>
<p>However often it is useful to move to the specific character that is positioned on a different line.</p>
<p>Consider this example:</p>
<pre><code>smth smth smth
bla bla bla
|
more bla bla bla
maybe some mo... | [
{
"answer_id": 515,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 9,
"selected": true,
"text": "<p>There are several window commands that allow you to do this:</p>\n\n<ul>\n<li><kbd>Ctrl+W</kbd> <kbd>+/-</kbd>: increase/decr... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/528",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/307/"
] | It is easy to move to a specific character on the same line with `t` or `f`.
However often it is useful to move to the specific character that is positioned on a different line.
Consider this example:
```
smth smth smth
bla bla bla
|
more bla bla bla
maybe some more bla
the end ```
```
here `|` represents the ... | There are several window commands that allow you to do this:
* `Ctrl+W` `+/-`: increase/decrease height (ex. `20<C-w>+`)
* `Ctrl+W` `>/<`: increase/decrease width (ex. `30<C-w><`)
* `Ctrl+W` `\_`: set height (ex. `50<C-w>_`)
* `Ctrl+W` `|`: set width (ex. `50<C-w>|`)
* `Ctrl+W` `=`: equalize width and height of all wi... |
534 | <p>I'm trying to fold some PHP code, and I have included a cut-down version of some of the code I'm trying to fold at the end of the post.</p>
<p>I've tried the following vim commands, but only the ex commands below work. The non-ex commands don't work and produce a white-on-red message in the status line saying: I ca... | [
{
"answer_id": 535,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 4,
"selected": true,
"text": "<p>Vim doesn't come with PHP syntax folding built-in. However, if all of your code is properly indented (as your example is), yo... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/534",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/368/"
] | I'm trying to fold some PHP code, and I have included a cut-down version of some of the code I'm trying to fold at the end of the post.
I've tried the following vim commands, but only the ex commands below work. The non-ex commands don't work and produce a white-on-red message in the status line saying: I can't find a... | Vim doesn't come with PHP syntax folding built-in. However, if all of your code is properly indented (as your example is), you can use a different fold method:
```
:set foldmethod=indent
``` |
538 | <p>Here is a simple text-based flowchart I made in Vim for a weblog post:</p>
<pre><code> [DNS request]
|
|
[Adsuck]
|
|
<block?>
|
/ \
... | [
{
"answer_id": 539,
"author": "Quincy Bowers",
"author_id": 93,
"author_profile": "https://vi.stackexchange.com/users/93",
"pm_score": -1,
"selected": false,
"text": "<p>You might try the <a href=\"https://github.com/vim-scripts/DrawIt\" rel=\"nofollow\">DrawIt</a> plugin.</p>\n\n<blockq... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/538",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Here is a simple text-based flowchart I made in Vim for a weblog post:
```
[DNS request]
|
|
[Adsuck]
|
|
<block?>
|
/ \
/ \
... | Rather than use vim to directly attempt to manipulate ASCII art, why not use vim to edit a file format that defines a graph?
The [dot format](http://www.graphviz.org/pdf/dotguide.pdf) is a fairly compact way to represent graphs. A rough approximation of the graph you outlined in your example would look like this:
``... |
543 | <p>I know many people store their .vimrc on GitHub to make it easier to get right to work on new machines, and that makes complete sense to me. Including plugins, however, is problematic, because the plugins I use are already git repositories. How does one create a repo that will track both their .vimrc and any plugins... | [
{
"answer_id": 545,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": false,
"text": "<p>You don't need to store plugins in your VCS; you can also use a Vim package manager. Since yesterday, I use <a href=\... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/543",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/163/"
] | I know many people store their .vimrc on GitHub to make it easier to get right to work on new machines, and that makes complete sense to me. Including plugins, however, is problematic, because the plugins I use are already git repositories. How does one create a repo that will track both their .vimrc and any plugins th... | How to deal with repositories-within-repositories has been an ongoing question with git. Git's [submodules](http://git-scm.com/docs/git-submodule) are one way of addressing the situation, at the expense of adding a little more complexity to keep track of. The git site has [an introduction to submodules](http://git-scm.... |
562 | <p>From time to time while working on multiple projects, and / or what ever, it leaves me with (too) many Vim instances open – as happens, I open a file which already is opened elsewhere, leaving me with the option of:</p>
<pre><code>[O]pen Read-only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort
</code></pre>
<p>Is ther... | [
{
"answer_id": 641,
"author": "user50136",
"author_id": 233,
"author_profile": "https://vi.stackexchange.com/users/233",
"pm_score": 2,
"selected": false,
"text": "<p>One solution would be to use a single instance of vim per project, which would prevent this issue unless your multiple pr... | 2015/02/06 | [
"https://vi.stackexchange.com/questions/562",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/220/"
] | From time to time while working on multiple projects, and / or what ever, it leaves me with (too) many Vim instances open – as happens, I open a file which already is opened elsewhere, leaving me with the option of:
```
[O]pen Read-only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort
```
Is there some built in way to rai... | One solution would be to use a single instance of vim per project, which would prevent this issue unless your multiple projects had overlapping files.
I'm going to assume that you are looking for a automated solution, instead of a suggestion on changing your behavior though.
There is the possibility of another solut... |
570 | <p>I know that Vim keeps history for ex commands, searches, jump locations, changes, and possibly others.</p>
<p>With <code>showcmd</code> set, Vim also shows you what keys you have entered so far for a normal mode command, until that command is executed.</p>
<p>Sometimes, when in normal mode, I mistype and actions o... | [
{
"answer_id": 584,
"author": "Collin Peters",
"author_id": 19,
"author_profile": "https://vi.stackexchange.com/users/19",
"pm_score": -1,
"selected": false,
"text": "<p>There is <code>q:</code> which shows a command history. </p>\n\n<p>I also find it useful that you can press up in a p... | 2015/02/07 | [
"https://vi.stackexchange.com/questions/570",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/227/"
] | I know that Vim keeps history for ex commands, searches, jump locations, changes, and possibly others.
With `showcmd` set, Vim also shows you what keys you have entered so far for a normal mode command, until that command is executed.
Sometimes, when in normal mode, I mistype and actions occur. I can undo these actio... | Following the link from @WChargin a bit further, I found this:
You can start vim with the [`-w`](http://vimdoc.sourceforge.net/htmldoc/starting.html#-w) or [`-W`](http://vimdoc.sourceforge.net/htmldoc/starting.html#-W) option as follows:
```
vim -w keys.txt my_file
```
>
> All the characters that you type are reco... |
574 | <p>The code standard that I use indicates that lines should have less than 80 chars. I want to indicate this automatically while I write to avoid raising the error later.</p>
<p>What is a good way of showing it?</p>
| [
{
"answer_id": 576,
"author": "OrangeTux",
"author_id": 153,
"author_profile": "https://vi.stackexchange.com/users/153",
"pm_score": 5,
"selected": false,
"text": "<p>If you have Vim 7.3 or later, you can set <code>colorcolumn</code>, or <code>cc</code>.</p>\n\n<pre><code>:set colorcolum... | 2015/02/07 | [
"https://vi.stackexchange.com/questions/574",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/403/"
] | The code standard that I use indicates that lines should have less than 80 chars. I want to indicate this automatically while I write to avoid raising the error later.
What is a good way of showing it? | If you have Vim 7.3 or later, you can set `colorcolumn`, or `cc`.
```
:set colorcolumn=80
```
From [`:help colorcolumn`](http://vimdoc.sourceforge.net/htmldoc/options.html#'colorcolumn'):
>
> 'colorcolumn' is a comma separated list of screen columns that are
> highlighted with ColorColumn hl-ColorColumn. Useful t... |
580 | <p>Assigning every useful function to a key works well for frequently used tools, but there are some operations I use so rarely, that I would prefer to assign them to some popup menu defined in my <code>vimrc</code>.</p>
<p>I've seen plugins like CtrlP open a popup list so this should be possible.</p>
<p>So my questi... | [
{
"answer_id": 591,
"author": "tommcdo",
"author_id": 64,
"author_profile": "https://vi.stackexchange.com/users/64",
"pm_score": 4,
"selected": false,
"text": "<p>Doing this out-of-the-box would require a fair amount of work, but I think you can do something fairly straight-forward using... | 2015/02/07 | [
"https://vi.stackexchange.com/questions/580",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | Assigning every useful function to a key works well for frequently used tools, but there are some operations I use so rarely, that I would prefer to assign them to some popup menu defined in my `vimrc`.
I've seen plugins like CtrlP open a popup list so this should be possible.
So my question is:
How to define a cust... | Since vim 8.2 there are native popups. The above may now be achieved without any plugins:
```
func! s:lines_count()
echom line('$') . ' lines in buffer'
endfunc
func! s:cmdMenu()
" variation of command-types
let cmds = [
\ "echom 'vim-version' version",
\ 'call s:lines_count()',
... |
588 | <p>Is there any way to use a non-monospace font in either <code>vim</code> or <code>gvim</code>?</p>
<p>I tried changing the font for gVim with:</p>
<pre><code>:set guifont=Dejavu\ Serif\ 12
</code></pre>
<p>But this gives me some rather ugly results:</p>
<p><img src="https://i.stack.imgur.com/rS5am.png" alt="enter... | [
{
"answer_id": 652,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": false,
"text": "<p>It's definitely not supported in GUI Vim, and I'd be surprised if there were more than handful of terminal emulators that supp... | 2015/02/07 | [
"https://vi.stackexchange.com/questions/588",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Is there any way to use a non-monospace font in either `vim` or `gvim`?
I tried changing the font for gVim with:
```
:set guifont=Dejavu\ Serif\ 12
```
But this gives me some rather ugly results:

I get the same results if I use the menu (Edit ->... | I found [`mlterm`](http://mlterm.sourceforge.net/), which supports this. Aside from Emacs' built-in terminal (M-x term) this is the *only* terminal I've found that supports this (I've tried about 15-20 different ones).
I've found that `mlterm` works better than Emacs due to the sceen ratio settings, and you also avo... |
594 | <p>If I have a text file like this:</p>
<pre><code>alpha: 1
beta: 2
gamma: 3
delta: 4
epsilon: 5
</code></pre>
<p>Is there a way to align the numbers like so?:</p>
<pre><code>alpha: 1
beta: 2
gamma: 3
delta: 4
epsilon: 5
</code></pre>
| [
{
"answer_id": 595,
"author": "Jay Thompson",
"author_id": 411,
"author_profile": "https://vi.stackexchange.com/users/411",
"pm_score": 3,
"selected": false,
"text": "<p>You can do this with the <a href=\"https://github.com/tommcdo/vim-lion\">vim-lion</a> plugin.</p>\n\n<p>Install it, th... | 2015/02/07 | [
"https://vi.stackexchange.com/questions/594",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/409/"
] | If I have a text file like this:
```
alpha: 1
beta: 2
gamma: 3
delta: 4
epsilon: 5
```
Is there a way to align the numbers like so?:
```
alpha: 1
beta: 2
gamma: 3
delta: 4
epsilon: 5
``` | See accepted answer to [Align a block of code on the basis of a single character](https://vi.stackexchange.com/questions/20658/align-a-block-of-code-on-the-basis-of-a-single-character)
To recap
1. `ggVG` to select all
2. `:'<,'>normal f:5a` you don't have to enter `'<,'>` and also note space at the end. For each line... |
598 | <p>Here's how I usually copy a block of text or code:</p>
<ol>
<li>Select the block with Visual mode (<kbd>V</kbd>) and delete it with
<kbd>d</kbd>; or if it's just a single line, just use
<kbd>d</kbd><kbd>d</kbd>.</li>
<li>Go to where I want the text to be, I am too stupid to remember the difference
between <kbd>p</k... | [
{
"answer_id": 601,
"author": "Jay Thompson",
"author_id": 411,
"author_profile": "https://vi.stackexchange.com/users/411",
"pm_score": 5,
"selected": true,
"text": "<p>There's a plugin for that: <a href=\"https://github.com/atweiden/vim-dragvisuals\" rel=\"nofollow noreferrer\">dragvisu... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/598",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Here's how I usually copy a block of text or code:
1. Select the block with Visual mode (`V`) and delete it with
`d`; or if it's just a single line, just use
`d``d`.
2. Go to where I want the text to be, I am too stupid to remember the difference
between `p` and `P`, so I get this right about 50% of time.
(if I get it... | There's a plugin for that: [dragvisuals.vim](https://github.com/atweiden/vim-dragvisuals).
It doesn't bind any keys by default, so you'll have to do that yourself. I like to map them to `Control`+`Arrow key`:
```
xmap <expr> <C-Left> DVB_Drag('left')
xmap <expr> <C-Right> DVB_Drag('right')
xmap <expr> <C-Down> DVB_Dr... |
605 | <p>When using ctags, one can move back through the tag stack by using [count]<kbd>CTRL-T</kbd> or <code>:[count]pop</code>, and forward using <code>:[count]tag</code></p>
<p>However, when using cscope instead of ctags and setting <code>'cscopetag'</code>, only the backwards direction works (that is, <code>:[count]pop<... | [
{
"answer_id": 13541,
"author": "Vicky",
"author_id": 14232,
"author_profile": "https://vi.stackexchange.com/users/14232",
"pm_score": 2,
"selected": false,
"text": "<p>Ensure setting the cscope using the following in your <code>~/.vimrc</code> file:</p>\n\n<pre><code>set cscopetag\nset ... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/605",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/227/"
] | When using ctags, one can move back through the tag stack by using [count]`CTRL-T` or `:[count]pop`, and forward using `:[count]tag`
However, when using cscope instead of ctags and setting `'cscopetag'`, only the backwards direction works (that is, `:[count]pop` works, but `:[count]tag` gives `E433: No tags file` and ... | Ensure setting the cscope using the following in your `~/.vimrc` file:
```
set cscopetag
set cst
set csto=0
set tags=./tags,tags;/
cs add cscope.out
```
Once it is done, re-login into the terminal to run cscope.
Jump to a tag: `Ctrl``]`
Jump back: `Ctrl``O`
Jump to a tag again: `Ctrl``I` |
609 | <p>When refactoring code it would be useful to be able to swap function arguments.</p>
<p>Changing for eg:</p>
<pre><code>func(foo[0], bar(), baz.spam)
</code></pre>
<p>into</p>
<pre><code>func(baz.spam, foo[0], bar())
</code></pre>
<p>Is there some way to swap arguments to the left/right, keeping function parenth... | [
{
"answer_id": 610,
"author": "akshay",
"author_id": 246,
"author_profile": "https://vi.stackexchange.com/users/246",
"pm_score": 5,
"selected": false,
"text": "<h3>Without plugins</h3>\n\n<blockquote>\n <p>| indicates cursor position</p>\n</blockquote>\n\n<pre><code>func(foo[0], bar(),... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/609",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | When refactoring code it would be useful to be able to swap function arguments.
Changing for eg:
```
func(foo[0], bar(), baz.spam)
```
into
```
func(baz.spam, foo[0], bar())
```
Is there some way to swap arguments to the left/right, keeping function parentheses and commas in place?
---
Note, this *could* becom... | ### Without plugins
>
> | indicates cursor position
>
>
>
```
func(foo[0], bar(), |baz.spam)
```
Steps:
1. `dt)` will delete `baz.spam`
2. `Ff` will move the cursor to the character f in `foo[0]`
3. `vt,p` will delete foo[0] and replace it with `baz.spam`
4. `$P` will paste the foo[0] before the parens
5. Repe... |
621 | <p>I am familiar with the <code>y</code>, <code>p</code> method of copying and pasting a line within Vim; however, I have been unsuccessful in finding a straight forward method for copying multiple lines which have been yanked in visual mode. </p>
<p>the idea would be:</p>
<pre><code>Shift + v
down arrow n times
y
:q... | [
{
"answer_id": 614,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 7,
"selected": true,
"text": "<p>To install a plugin, we need to know what form it comes in. It can be:</p>\n\n<ul>\n<li>a single <code>.vim</code> file</li>\n<... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/621",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/416/"
] | I am familiar with the `y`, `p` method of copying and pasting a line within Vim; however, I have been unsuccessful in finding a straight forward method for copying multiple lines which have been yanked in visual mode.
the idea would be:
```
Shift + v
down arrow n times
y
:q!
open new file, or switch buffer
p
```
W... | To install a plugin, we need to know what form it comes in. It can be:
* a single `.vim` file
* a Vimball file
* a set of files in directories that follow an expected structure (`plugin/*`, `syntax/*`, etc.) ([What makes a plugin Vundle compatible and are other plugin managers interchangeable?](https://vi.stackexchang... |
625 | <p>I use Vim as my primary editor.</p>
<p>I would also like to use vim to diff files and modify the files while doing the diff to fix easy changes (rather than most diff techniques which are a cycle of diff, fix, diff, fix).</p>
<p>Additionally are there easy ways to integrate Vim into diff tools used by source control... | [
{
"answer_id": 626,
"author": "Martin York",
"author_id": 383,
"author_profile": "https://vi.stackexchange.com/users/383",
"pm_score": 8,
"selected": false,
"text": "<p>vim has this functionality built in (with the correct command line flag).</p>\n\n<pre><code>vim -d <file1> <fi... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/625",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/383/"
] | I use Vim as my primary editor.
I would also like to use vim to diff files and modify the files while doing the diff to fix easy changes (rather than most diff techniques which are a cycle of diff, fix, diff, fix).
Additionally are there easy ways to integrate Vim into diff tools used by source control tools/sites?
... | vim has this functionality built in (with the correct command line flag).
```
vim -d <file1> <file2>
```
This opens each file in a view and highlights the differences.
Any code that is identical is `folded` away so you do not need to look at identical code or scroll through huge chunks of identical code.
But th... |
627 | <p>When I start Vim without any files, I always see this:</p>
<pre><code> VIM - Vi IMproved
version 7.4.580
by Bram Moolenaar et al.
Vim is open source and freely distributable
Become a registered Vim user!
type :help register<Enter> for information
type :q&... | [
{
"answer_id": 628,
"author": "johannes",
"author_id": 59,
"author_profile": "https://vi.stackexchange.com/users/59",
"pm_score": 3,
"selected": false,
"text": "<p>Actually the answer is in startify. In <a href=\"https://github.com/mhinz/vim-startify/blob/master/plugin/startify.vim\" rel... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/627",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | When I start Vim without any files, I always see this:
```
VIM - Vi IMproved
version 7.4.580
by Bram Moolenaar et al.
Vim is open source and freely distributable
Become a registered Vim user!
type :help register<Enter> for information
type :q<Enter> ... | Here's the code that I extracted from `vim-startify`; the key parts are creating a new buffer on the `VimEnter` autocmd, putting some text in that, and then mapping the `i` to start a new buffer and then go to insert mode.
I put the below in a [little plugin](https://github.com/Carpetsmoker/startscreen.vim) which adds... |
631 | <p>I often use <code>:Ex</code> or <code>:Sex</code> to explore the filesystem from an opened file directory, or just invoke vim passing a directory to start exploring the filesystem and then opening a file.</p>
<p>In any case, while navigating the directory tree, using the <code>:edit {file}</code> command to open ne... | [
{
"answer_id": 632,
"author": "Giovanni Maggiorani",
"author_id": 311,
"author_profile": "https://vi.stackexchange.com/users/311",
"pm_score": 4,
"selected": true,
"text": "<p>It is possible by setting the netrw configuration variable <code>g:netrw_keepdir</code> to 0 (default is 1).<br... | 2015/02/08 | [
"https://vi.stackexchange.com/questions/631",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/188/"
] | I often use `:Ex` or `:Sex` to explore the filesystem from an opened file directory, or just invoke vim passing a directory to start exploring the filesystem and then opening a file.
In any case, while navigating the directory tree, using the `:edit {file}` command to open new files always takes paths relative to the ... | It is possible by setting the netrw configuration variable `g:netrw_keepdir` to 0 (default is 1).
To make it permanent, add in the .vimrc file this line:
```
let g:netrw_keepdir=0
``` |
663 | <p>While fonts can be manually selected in GVim from the menu, I have a few preferred fonts I would like to switch between depending on the task at hand <em>(small bitmap, larger OTF... etc)</em>.</p>
<p>Is there a way I can setup key-binding to cycle over a list of fonts predefined in my vimrc?</p>
| [
{
"answer_id": 664,
"author": "Quincy Bowers",
"author_id": 93,
"author_profile": "https://vi.stackexchange.com/users/93",
"pm_score": 3,
"selected": false,
"text": "<p>I have the following defined in my .vimrc file.</p>\n\n<pre><code>set guifont=DejaVu\\ Sans\\ Mono\\ for\\ Powerline\\ ... | 2015/02/09 | [
"https://vi.stackexchange.com/questions/663",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | While fonts can be manually selected in GVim from the menu, I have a few preferred fonts I would like to switch between depending on the task at hand *(small bitmap, larger OTF... etc)*.
Is there a way I can setup key-binding to cycle over a list of fonts predefined in my vimrc? | The basic idea could be something like:
```
" Define a list of the fonts you want to use, and the index in the
" list of the default font. See :help Lists
let g:fc_list = [
\ "DejaVu Sans Mono 9",
\ "Source Code Pro 12",
\ "GohuFont 11"
\ ]
let g:fc_current = 0
" Set default font
let &guifont = g:fc_list[g:f... |
666 | <p>In Sublime Text 2, you get vertical guides where your indentation is, like this:</p>
<p><img src="https://i.stack.imgur.com/nxPrP.png" alt="Sublime Text screenshot" /></p>
<p>but Vim doesn't:</p>
<p><img src="https://i.stack.imgur.com/LEnqM.png" alt="vim screenshot" /></p>
<p>Is there a way to show lines like that i... | [
{
"answer_id": 667,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 7,
"selected": true,
"text": "<p>Unified answer:</p>\n\n<h2>If you are using tabs</h2>\n\n<p>I'd try using listchars:</p>\n\n<pre><code>:set listchars=tab:... | 2015/02/09 | [
"https://vi.stackexchange.com/questions/666",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/226/"
] | In Sublime Text 2, you get vertical guides where your indentation is, like this:

but Vim doesn't:

Is there a way to show lines like that in Vim?
By the way, my indentation is 2 spaces.
```
:set t... | Unified answer:
If you are using tabs
---------------------
I'd try using listchars:
```
:set listchars=tab:\|\
:set list
```
note: there is a space after the last `\` above.
This method is good because it uses Vim's built-in support for showing this kind of thing.
Example output:
```
| if (1) {
| ... |
678 | <p>Suppose I start Vim to edit a new file in a directory that is not yet created:</p>
<pre><code>vim nonExisitingDirectory/newFile.txt
</code></pre>
<p>Vim will happily show me an empty buffer and I can start writing my new file. But when I want to write the file to disk I get this error: </p>
<pre><code>E212: Can't... | [
{
"answer_id": 679,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 7,
"selected": true,
"text": "<p>As far as I know there is no setting or some such to do this. But not all is lost, we can of course use the <code>BufW... | 2015/02/10 | [
"https://vi.stackexchange.com/questions/678",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12/"
] | Suppose I start Vim to edit a new file in a directory that is not yet created:
```
vim nonExisitingDirectory/newFile.txt
```
Vim will happily show me an empty buffer and I can start writing my new file. But when I want to write the file to disk I get this error:
```
E212: Can't Open file for writing.
```
I presu... | As far as I know there is no setting or some such to do this. But not all is lost, we can of course use the `BufWritePre` autocommand.
This is executed before the buffer is written to the disk. So we can create the directory there if it doesn't exist yet.
For example:
```
augroup Mkdir
autocmd!
autocmd BufWriteP... |
684 | <p>Vim spell check feature works great in most cases - it is even smart enough to distinguish code from literals and comments in most languages. However I have problems with HTML spell check:</p>
<pre><code> <div title="text with mistaek #1" data-text="text with mistaek #2">text with mistaek #3</div>
</co... | [
{
"answer_id": 685,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<p>The syntax items within which Vim will highlight spelling mistakes are defined using the <code>@Spell</code> and <code>@NoSpell... | 2015/02/11 | [
"https://vi.stackexchange.com/questions/684",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/362/"
] | Vim spell check feature works great in most cases - it is even smart enough to distinguish code from literals and comments in most languages. However I have problems with HTML spell check:
```
<div title="text with mistaek #1" data-text="text with mistaek #2">text with mistaek #3</div>
```
In example above only mi... | The syntax items within which Vim will highlight spelling mistakes are defined using the `@Spell` and `@NoSpell` clusters. See `:help spell-syntax` (and the rest of the `:help spell` and `:help syntax` files) for full details.
The quick and dirty fix to get your desired result is to create a new file in your Vim confi... |
688 | <p>I have a text file like this (using gVim on Windows)</p>
<pre><code>foo bar baz quux
corge grault garply
waldo fred plugh
[...150 more lines...]
xyzzy thud
</code></pre>
<p>I want to add a number to each line in the file. Not using <code>:set number</code>, but to add the number as text preceding each line, as fo... | [
{
"answer_id": 690,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 6,
"selected": true,
"text": "<p>In pure Vim fashion:</p>\n\n<pre><code>:%s/^/\\=line('.').\". \"\n</code></pre>\n\n<p>Explanation:</p>\n\n<pre><code>:%s/^/ ... | 2015/02/11 | [
"https://vi.stackexchange.com/questions/688",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/398/"
] | I have a text file like this (using gVim on Windows)
```
foo bar baz quux
corge grault garply
waldo fred plugh
[...150 more lines...]
xyzzy thud
```
I want to add a number to each line in the file. Not using `:set number`, but to add the number as text preceding each line, as follows, so the number is part of the... | In pure Vim fashion:
```
:%s/^/\=line('.').". "
```
Explanation:
```
:%s/^/ " the substitution will be applied to the beginning of every line
\= " the rest of the replacement part is an expression
line('.').". " " the expression returns the current line number concatenated with a dot an... |
698 | <p>In my .vimrc I have <code>set backspace=eol,start</code>, which allows me to backspace over line breaks and the start of what I wrote since I entered Insert mode. This does not allow me to backspace over autoindents though. For that one can add <code>indent</code> to the <code>backspace</code> list.</p>
<p>If one d... | [
{
"answer_id": 699,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": false,
"text": "<p>You can do <code>0<C-d></code> to delete all indent in the current line in insert mode.</p>\n\n<p>-- edit --</p>\n\n<p>... | 2015/02/11 | [
"https://vi.stackexchange.com/questions/698",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | In my .vimrc I have `set backspace=eol,start`, which allows me to backspace over line breaks and the start of what I wrote since I entered Insert mode. This does not allow me to backspace over autoindents though. For that one can add `indent` to the `backspace` list.
If one doesn't use `indent` they may be unable to d... | I like to use `Ctrl+U`. If there are any characters on the line, it deletes to the beginning of the text. Press again to delete to column 1 (the indentation), and again to remove the line and put the cursor at the end of the line above. This is quicker than `Ctrl+D` when there are several levels of indent.
This requir... |
716 | <p>In NERDTree, if I select a file node and hit <kbd>o</kbd>, it opens the file in a window in the current tab. However, if that particular file is already open in another tab, NERDTree switches to that tab. I find this quite disorienting in my workflow.</p>
<p>Is there an option to tell NERDTree to stay in the curren... | [
{
"answer_id": 717,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 3,
"selected": true,
"text": "<p>There is currently no way to do this.</p>\n\n<p>From the source code (ref. <a href=\"https://github.com/scrooloose/nerdtree/b... | 2015/02/11 | [
"https://vi.stackexchange.com/questions/716",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/333/"
] | In NERDTree, if I select a file node and hit `o`, it opens the file in a window in the current tab. However, if that particular file is already open in another tab, NERDTree switches to that tab. I find this quite disorienting in my workflow.
Is there an option to tell NERDTree to stay in the current tab?
---
Update... | There is currently no way to do this.
From the source code (ref. [lib/nerdtree/opener.vim line 238](https://github.com/scrooloose/nerdtree/blob/c2dd750860288b8cf81f6bd5ff49dc5ee76a34d5/lib/nerdtree/opener.vim#L238)):
```
function! s:Opener._openFile()
if self._reuse && self._reuseWindow()
return
endif... |
718 | <p>I have a file with a line that looks like this:</p>
<pre><code>foofoo.xy.barbar
</code></pre>
<p>I want to change the <code>xy</code> to <code>gh</code>. I tried to do <kbd>2</kbd><kbd>r</kbd> -> <kbd>g</kbd><kbd>h</kbd>, but obviously that didn't work, as it replaced the <code>xy</code> with <code>gg</code> and ... | [
{
"answer_id": 719,
"author": "alxndr",
"author_id": 67,
"author_profile": "https://vi.stackexchange.com/users/67",
"pm_score": 6,
"selected": true,
"text": "<p>If the new text is the same length as the old text, Vim's <strong>replace mode</strong> is an option. From normal mode, <kbd>R<... | 2015/02/12 | [
"https://vi.stackexchange.com/questions/718",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/134/"
] | I have a file with a line that looks like this:
```
foofoo.xy.barbar
```
I want to change the `xy` to `gh`. I tried to do `2``r` -> `g``h`, but obviously that didn't work, as it replaced the `xy` with `gg` and then moved my cursor one spot to the left.
Is there a way to do this without entering insert mode, or with... | If the new text is the same length as the old text, Vim's **replace mode** is an option. From normal mode, `R` (that's a capital "r") brings you into replace mode. This is similar to "overwrite" in some other text editors: instead of inserting new characters like in insert mode, typing will replace the character under ... |
727 | <p>My goal were to somehow make visible, if a whitespace is space, tab, or even newline (and, ideally, in case of newline I would be happy to see <code>\r\n</code> and <code>\n</code> differently).</p>
<p>I am thinking to a similar thing as the GUI text editors can do.</p>
<p>Is it somehow with Vim also possible?</p>
| [
{
"answer_id": 728,
"author": "l4mpi",
"author_id": 117,
"author_profile": "https://vi.stackexchange.com/users/117",
"pm_score": 3,
"selected": false,
"text": "<p>This can be done with <code>:set list</code>. The Characters displayed for the different whitespace chars can be controlled b... | 2015/02/12 | [
"https://vi.stackexchange.com/questions/727",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28/"
] | My goal were to somehow make visible, if a whitespace is space, tab, or even newline (and, ideally, in case of newline I would be happy to see `\r\n` and `\n` differently).
I am thinking to a similar thing as the GUI text editors can do.
Is it somehow with Vim also possible? | Yes, look at [`:help listchars`](http://vimhelp.appspot.com/options.txt.html#%27listchars%27).
`listchars` is a string that will be parsed when `list` is set to determine what to render for certain special characters. You can set `listchars` in your `.vimrc` like so:
```
set listchars=eol:!,tab:>=,trail:.
set list
`... |
730 | <p>How I paste now:</p>
<ol>
<li>Right-click/Copy or simply highlight.</li>
<li>Right-click/Paste or Middle Click or CTRL+SHFT+V</li>
<li>Indents appear at increasing intervals: 0, 2, 4, 6, +</li>
</ol>
<p>Question at hand:</p>
<p>From prior research, I found that the quick and dirty solution is entering the followi... | [
{
"answer_id": 731,
"author": "Jay Thompson",
"author_id": 411,
"author_profile": "https://vi.stackexchange.com/users/411",
"pm_score": 3,
"selected": false,
"text": "<p>If you are using a fairly modern terminal emulator, you can install the <a href=\"https://github.com/ConradIrwin/vim-b... | 2015/02/12 | [
"https://vi.stackexchange.com/questions/730",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | How I paste now:
1. Right-click/Copy or simply highlight.
2. Right-click/Paste or Middle Click or CTRL+SHFT+V
3. Indents appear at increasing intervals: 0, 2, 4, 6, +
Question at hand:
From prior research, I found that the quick and dirty solution is entering the following in my `.vimrc` file: `set paste`. However, ... | OK, here is a "yank & put" primer…
In Vim, the primary commands for yanking (copying) and putting (pasting) are `y` and `p`.
Yanking places the yanked text in a register. That register is the unnamed register, `"`, by default but one can use other registers:
```
"ay " yank into register a
"by " yank into regis... |
737 | <p>I would like to edit content in vim which was dynamically generated from the command-line without having the file yet.</p>
<p>In example:</p>
<pre><code>$ echo This is example. | vim /dev/stdin
$ cat /etc/hosts | vim /dev/stdin
</code></pre>
<p>but it's failing with the errors:</p>
<blockquote>
<p>Vim: Warning: Inpu... | [
{
"answer_id": 738,
"author": "toro2k",
"author_id": 13,
"author_profile": "https://vi.stackexchange.com/users/13",
"pm_score": 6,
"selected": true,
"text": "<p>You have to use <code>-</code> in place of the file name on the command line:</p>\n\n<pre><code>echo This is example. | vim -\n... | 2015/02/12 | [
"https://vi.stackexchange.com/questions/737",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I would like to edit content in vim which was dynamically generated from the command-line without having the file yet.
In example:
```
$ echo This is example. | vim /dev/stdin
$ cat /etc/hosts | vim /dev/stdin
```
but it's failing with the errors:
>
> Vim: Warning: Input is not from a terminal
>
>
> Vim: Error ... | You have to use `-` in place of the file name on the command line:
```
echo This is example. | vim -
```
The above command will open an unnamed buffer filled with the text read from the standard input. |
742 | <p>When using <code>set showcmd</code> Vim shows partial commands in the last line of the screen. For example, in Normal mode when typing the command <code>dt.</code> the last line shows <code>dt</code> and then, when you hit <code>.</code> the command is complete and therefore nothing is shown.</p>
<p>Is there a way ... | [
{
"answer_id": 786,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 4,
"selected": true,
"text": "<p>I couldn't find any way to do this in a regular Vim. However, if you are willing to patch Vim, the following may work for ... | 2015/02/12 | [
"https://vi.stackexchange.com/questions/742",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | When using `set showcmd` Vim shows partial commands in the last line of the screen. For example, in Normal mode when typing the command `dt.` the last line shows `dt` and then, when you hit `.` the command is complete and therefore nothing is shown.
Is there a way to show full commands? For example when typing `dt.gU(... | I couldn't find any way to do this in a regular Vim. However, if you are willing to patch Vim, the following may work for you.
The very simple patch (applied against Vim-7.4.052) disables the actual update to the screen that clears the history at the end of a normal command. It does this by returning whether or not `s... |
747 | <p>Quotation marks in LaTeX are different than in normal text, in that they're formatted <code>``like this''</code> (or <code>`like this'</code> for single quotes). This makes it difficult to navigate through them in Vim.</p>
<p>I usually use something like <code>T`ct'</code> (backwards until <code>`</code>, change un... | [
{
"answer_id": 750,
"author": "superjer",
"author_id": 195,
"author_profile": "https://vi.stackexchange.com/users/195",
"pm_score": 3,
"selected": false,
"text": "<p>I don't know LaTeX but this seems to work:</p>\n\n<pre><code>vnoremap iq :<C-U>silent! normal! t'vT`<CR>\nomap... | 2015/02/12 | [
"https://vi.stackexchange.com/questions/747",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/88/"
] | Quotation marks in LaTeX are different than in normal text, in that they're formatted ```like this''` (or ``like this'` for single quotes). This makes it difficult to navigate through them in Vim.
I usually use something like `T`ct'` (backwards until ```, change until `'`). However, this is clunky and unnatural. I wou... | I don't know LaTeX but this seems to work:
```
vnoremap iq :<C-U>silent! normal! t'vT`<CR>
omap iq :normal viq<CR>
```
I based this off the information over here: <http://vim.wikia.com/wiki/Creating_new_text_objects>
You can add support for `aq` as well:
```
vnoremap aq :<C-U>silent! normal! f'vF`<CR>
omap aq :nor... |
756 | <p>I have installed a plugin that doesn't provide a mechanism to disable the key mappings it defines. I want to redefine one of the mappings (<code><leader>cc</code>) defined by the plugin for my own pursope, I've tried to put the following line in my <code>.vimrc</code>:</p>
<pre><code>noremap <leader>cc ... | [
{
"answer_id": 763,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 6,
"selected": true,
"text": "<p>Plugins are sourced <em>after</em> your <code>vimrc</code> so there's no way to override a plugin mapping in your <code>vimrc<... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/756",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13/"
] | I have installed a plugin that doesn't provide a mechanism to disable the key mappings it defines. I want to redefine one of the mappings (`<leader>cc`) defined by the plugin for my own pursope, I've tried to put the following line in my `.vimrc`:
```
noremap <leader>cc echo "my purpose"
```
But this doesn't work, `... | Plugins are sourced *after* your `vimrc` so there's no way to override a plugin mapping in your `vimrc` if the plugin doesn't provide a way to do so.
Placing your custom mapping in `~/.vim/after/plugin/mystuff.vim` (the name of the file doesn't matter) should allow you to override the plugin mapping. |
758 | <p>It is possible to convert all windows into different split mode while editing? Instead of <a href="https://vi.stackexchange.com/questions/514/how-to-change-the-current-splits-width-and-height">one by one</a>?</p>
<p>In example (having multiple windows) from horizontal to vertical split and opposite, or from tab spl... | [
{
"answer_id": 762,
"author": "tommcdo",
"author_id": 64,
"author_profile": "https://vi.stackexchange.com/users/64",
"pm_score": 4,
"selected": true,
"text": "<p>You could accomplish something like this using the argument list. The general idea is to collect all of the open windows into ... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/758",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | It is possible to convert all windows into different split mode while editing? Instead of [one by one](https://vi.stackexchange.com/questions/514/how-to-change-the-current-splits-width-and-height)?
In example (having multiple windows) from horizontal to vertical split and opposite, or from tab split all files into hor... | You could accomplish something like this using the argument list. The general idea is to collect all of the open windows into the argument list, then close all the splits, then use the argument list to open everything in a new way.
First, clear the argument list, in case it's already populated.
```
:argdelete *
```
... |
759 | <p>I'm using complex repeats to record my operations (<kbd>qq</kbd> to record, <em>some operations</em>, <kbd>q</kbd> to stop) and I did a mistake.</p>
<p>It is possible to see what I've recorded and correct the mistake, instead of doing it again?</p>
<p>Invoking recorded characters by <kbd>@q</kbd> works, but I can'... | [
{
"answer_id": 760,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 7,
"selected": true,
"text": "<p><em>Note: I'm assuming you're using the <code>a</code> register for the entirety of this answer, but you can use any r... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/759",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I'm using complex repeats to record my operations (`qq` to record, *some operations*, `q` to stop) and I did a mistake.
It is possible to see what I've recorded and correct the mistake, instead of doing it again?
Invoking recorded characters by `@q` works, but I can't see it in my mappings (`:map q` - `No mapping fou... | *Note: I'm assuming you're using the `a` register for the entirety of this answer, but you can use any register*
*Note2: `<1b>` is `Esc`; you can insert this with `Ctrl+v` and then `Esc`. It may also show up as `^[` (depending on the `display` setting).*
---
It's not a mapping; so it makes sense that `:map` doesn't ... |
764 | <p>I've been receiving logged data in a text file that is just one long line with each value separated by a space. Is there a command or set of commands that will split one line into multiple lines?</p>
| [
{
"answer_id": 765,
"author": "toro2k",
"author_id": 13,
"author_profile": "https://vi.stackexchange.com/users/13",
"pm_score": 5,
"selected": false,
"text": "<p>You could simply replace any consecutive space on the line with a newline using the command <code>:s/\\s\\+/\\r/g</code>. <cod... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/764",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25/"
] | I've been receiving logged data in a text file that is just one long line with each value separated by a space. Is there a command or set of commands that will split one line into multiple lines? | You could simply replace any consecutive space on the line with a newline using the command `:s/\s\+/\r/g`. `\s\+` mean one or more whitespace characters, and `\r` is a newline, see [`:help :substitute`](http://vimhelp.appspot.com/change.txt.html#%3Asubstitute) and [`:help regexp`](http://vimhelp.appspot.com/pattern.tx... |
766 | <p>I am writing a VimL function that, in insert mode, allows a <code><BS></code> through the opening part of a pair (<code>[</code>, <code>{</code>, etc.) to delete the closing part of the pair if it is the next character after the cursor (much like <a href="https://github.com/jiangmiao/auto-pairs" rel="noreferre... | [
{
"answer_id": 765,
"author": "toro2k",
"author_id": 13,
"author_profile": "https://vi.stackexchange.com/users/13",
"pm_score": 5,
"selected": false,
"text": "<p>You could simply replace any consecutive space on the line with a newline using the command <code>:s/\\s\\+/\\r/g</code>. <cod... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/766",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I am writing a VimL function that, in insert mode, allows a `<BS>` through the opening part of a pair (`[`, `{`, etc.) to delete the closing part of the pair if it is the next character after the cursor (much like [auto-pairs](https://github.com/jiangmiao/auto-pairs) and [vim-autoclose](https://github.com/Townk/vim-aut... | You could simply replace any consecutive space on the line with a newline using the command `:s/\s\+/\r/g`. `\s\+` mean one or more whitespace characters, and `\r` is a newline, see [`:help :substitute`](http://vimhelp.appspot.com/change.txt.html#%3Asubstitute) and [`:help regexp`](http://vimhelp.appspot.com/pattern.tx... |
773 | <p>I'm using the Taglist and NerdTree plugins quite often. Usually the window that opens in the left side is too small and I need to extend it.</p>
<p>I usually do: <kbd>10</kbd> <kbd>CTRL</kbd>+<kbd>w</kbd> <kbd>></kbd></p>
<p>Is there a way to change the default width of the window of NerdTree and Taglist?</p>
| [
{
"answer_id": 775,
"author": "Andrew",
"author_id": 446,
"author_profile": "https://vi.stackexchange.com/users/446",
"pm_score": 2,
"selected": false,
"text": "<p>I have this problem all the time with splits not being tall enough so I've added this key binding to my <code>.vimrc</code>:... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/773",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/496/"
] | I'm using the Taglist and NerdTree plugins quite often. Usually the window that opens in the left side is too small and I need to extend it.
I usually do: `10` `CTRL`+`w` `>`
Is there a way to change the default width of the window of NerdTree and Taglist? | The examples below set the width to 60 columns. Adjust to your preferences.
NERDTree
--------
NERDTree uses a variable for just this:
```
:let g:NERDTreeWinSize=60
```
This will set the width to 60. You can put this line into your vimrc.
Taglist
-------
For taglist, you set a similar option:
```
:let g:Tlist_Wi... |
778 | <p>I know that <a href="https://vi.stackexchange.com/questions/625/how-do-i-use-vim-as-a-diff-tool">Vim's diff mode</a> (<code>vimdiff</code>) allows us to compare the contents of two (or more) files.</p>
<p>But it is possible to compare content of multiple files across directories in order to merge two directories re... | [
{
"answer_id": 787,
"author": "akshay",
"author_id": 246,
"author_profile": "https://vi.stackexchange.com/users/246",
"pm_score": 2,
"selected": false,
"text": "<p>I've wanted the same for a while. The best solution I found was to use <a href=\"https://github.com/Osse/vdwrap\" rel=\"nofo... | 2015/02/13 | [
"https://vi.stackexchange.com/questions/778",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I know that [Vim's diff mode](https://vi.stackexchange.com/questions/625/how-do-i-use-vim-as-a-diff-tool) (`vimdiff`) allows us to compare the contents of two (or more) files.
But it is possible to compare content of multiple files across directories in order to merge two directories recursively (like DiffMerge and si... | There is [DirDiff.vim](https://github.com/will133/vim-dirdiff) plugin to diff and merge two directories recursively.
>
> It performs a recursive diff on two directories and generate a diff
> "window". Based on that window you can perform various diff operations
> such as opening two files in Vim's diff mode, copy the... |
792 | <p>I've a file of source code written in a programming language (e.g. PHP) and I would like to convert it into a HTML file, so I can publish it on web in order to share my code.</p>
<p>By conversion I mean, for example, converting new lines into <code><br></code> tags so that the text will keep the same formatti... | [
{
"answer_id": 793,
"author": "Alexander Myshov",
"author_id": 500,
"author_profile": "https://vi.stackexchange.com/users/500",
"pm_score": 3,
"selected": false,
"text": "<p>As I understood you, you want to convert content of current window to HTML.\nTry to run this command:</p>\n\n<pre>... | 2015/02/14 | [
"https://vi.stackexchange.com/questions/792",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I've a file of source code written in a programming language (e.g. PHP) and I would like to convert it into a HTML file, so I can publish it on web in order to share my code.
By conversion I mean, for example, converting new lines into `<br>` tags so that the text will keep the same formatting both in the text editor ... | The following vim command would creates an html rendering of the current file.
```
:TOhtml
```
It saves the file in the same folder (with .html extension) and it will include styles, foreground/background colours and [syntax highlighting](https://en.wikipedia.org/wiki/Syntax_highlighting), so the file can be straigh... |
795 | <p>In example, I would like to paste the current time or date into editor by using external commands (such as <code>date</code>) without leaving vim.</p>
<p>How this can be achieved?</p>
| [
{
"answer_id": 796,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 4,
"selected": true,
"text": "<p>Simply run</p>\n\n<pre><code>:%!date\n</code></pre>\n\n<p>(or whatever command you wish to dump into the current buffer).</p>... | 2015/02/14 | [
"https://vi.stackexchange.com/questions/795",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | In example, I would like to paste the current time or date into editor by using external commands (such as `date`) without leaving vim.
How this can be achieved? | Simply run
```
:%!date
```
(or whatever command you wish to dump into the current buffer).
This will replace the entire buffer with the command's output. If you don't want this, use `read` instead:
```
:read !date
```
Or, you can replace a certain line with the output of an external command:
```
:2!date replac... |
798 | <p>I would like to write whole buffer into standard output (<code>/dev/stdout</code>) instead of the file and the following command works as expected while editing the file:</p>
<pre><code>:w >> /dev/stdout
</code></pre>
<p><sup>Hint: Press <kbd>Control</kbd>+<kbd>L</kbd> to refresh the screen.</sup></p>
<p>Bu... | [
{
"answer_id": 799,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"http://manpages.ubuntu.com/vipe.1\" rel=\"nofollow\"><code>vipe</code></a> is a convenient tool for editing pipeline... | 2015/02/14 | [
"https://vi.stackexchange.com/questions/798",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I would like to write whole buffer into standard output (`/dev/stdout`) instead of the file and the following command works as expected while editing the file:
```
:w >> /dev/stdout
```
Hint: Press `Control`+`L` to refresh the screen.
But it doesn't work as expected when I'm trying to do the same from the command l... | To print buffer to shell standard output, `vim` needs to start in Ex mode, otherwise it'll open "normal" way with its own window and clear any output buffers on quit.
Here is the simplest working example:
```
$ echo foo | vim -e '+%print' '+q!' /dev/stdin
foo
```
or even shorter:
```
$ echo foo | ex +%p -cq! /dev/... |
803 | <p>I am using a keyboard layout in which the backtick (<code>`</code>) is a <a href="http://en.wikipedia.org/wiki/Keyboard_layout#Dead_keys" rel="noreferrer">dead key</a>.</p>
<p>This means that when I type a backtick followed by a vowel (for example <code>`a</code>) what Vim sees is an accented character (<code>à</co... | [
{
"answer_id": 804,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 5,
"selected": true,
"text": "<p>Try making it a mapping:</p>\n\n<pre><code>\" Mapping dead keys in normal mode\nnmap á 'a\n</code></pre>\n\n<p>That way, w... | 2015/02/14 | [
"https://vi.stackexchange.com/questions/803",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | I am using a keyboard layout in which the backtick (```) is a [dead key](http://en.wikipedia.org/wiki/Keyboard_layout#Dead_keys).
This means that when I type a backtick followed by a vowel (for example ``a`) what Vim sees is an accented character (`à`). So if I set a mark with `ma` I can jump to the line of the mark w... | Try making it a mapping:
```
" Mapping dead keys in normal mode
nmap á 'a
```
That way, when Vim gets the accented a, it interprets it as ```+`a`
Using `nmap` allows this to happen in normal mode only; in insert mode or command mode, you'll get the accented `a` as you'd expect.
It is possible to apply this to othe... |
805 | <p>Is there a way to exclude specific files and directories from Vim's <code>path</code>?</p>
<p>I was hoping a syntax like this would work:</p>
<pre><code>set path+=./**,!./ignoredirectory,!./ignoredirectory2,!./ignorefile.txt
</code></pre>
<p>I would use <code>wildignore</code> but I don't think it supports relati... | [
{
"answer_id": 809,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 1,
"selected": false,
"text": "<p>Why do you think such a syntax should work?</p>\n\n<p><code>:h :set</code> is your entry point to Vim's documentation on <cod... | 2015/02/14 | [
"https://vi.stackexchange.com/questions/805",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Is there a way to exclude specific files and directories from Vim's `path`?
I was hoping a syntax like this would work:
```
set path+=./**,!./ignoredirectory,!./ignoredirectory2,!./ignorefile.txt
```
I would use `wildignore` but I don't think it supports relative path expansion if I used something like `set wildign... | I did a bit of experimentation with `wildignore`. I don't think it supports relative paths, or even absolute paths.
Here's what I have:
1. A file at `~/devel/scratchpad/c++/ms.cpp`
2. Vim opened with current directory `~/devel`
3. `:set path=~/devel/**`
I tried:
```
set wildignore=scratchpad/**/*
set wildignore=~/d... |
807 | <p>I would like to generate one or few random numbers separated by new line.</p>
<p>How this can be done?</p>
| [
{
"answer_id": 810,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>I don't think there's a native function for random numbers in Vimscript.</p>\n\n<p>A way using <code>:python</code> (use it in... | 2015/02/14 | [
"https://vi.stackexchange.com/questions/807",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I would like to generate one or few random numbers separated by new line.
How this can be done? | Starting with Vim [8.1.2342](https://github.com/vim/vim/releases/tag/v8.1.2342), you can make use of the `rand()` and `srand()` functions.
Here is an example:
```
let g:seed = srand()
echo rand(g:seed) % 100 " to echo a random number between 0-99
```
For older Vims, you'll have to fall back to calling some extern... |
830 | <p>From <code>:help swap-file</code>:</p>
<blockquote>
<p><strong>Updating the swapfile</strong></p>
<p>The swap file is updated after typing 200 characters or when you have
not typed anything for four seconds. This only happens if the buffer
was changed, not when you only moved around. The reason why it ... | [
{
"answer_id": 833,
"author": "Runium",
"author_id": 220,
"author_profile": "https://vi.stackexchange.com/users/220",
"pm_score": 5,
"selected": true,
"text": "<ol>\n<li>Yes it saves to swap file.</li>\n</ol>\n\n<p>You can do a quick test to get a <em>feel</em> of this. Go to a directory... | 2015/02/15 | [
"https://vi.stackexchange.com/questions/830",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | From `:help swap-file`:
>
> **Updating the swapfile**
>
>
> The swap file is updated after typing 200 characters or when you have
> not typed anything for four seconds. This only happens if the buffer
> was changed, not when you only moved around. The reason why it is not
> kept up to date all the time is that t... | 1. Yes it saves to swap file.
You can do a quick test to get a *feel* of this. Go to a directory. Say `vim notest.txt` and write some text. You do not even have to save the file.
If you list files in the working directory you will find a swap file. Copy it to a different directory (where you have no "notes.txt" file,... |
831 | <p>After running <code>:make</code>, the quickfix window displays the compile command and other <code>stdout</code> messages from the makefile, but it doesn't display any errors. Everything but <code>stderr</code> messages are displaying. How do I enable <code>stderr</code> messages?</p>
| [
{
"answer_id": 833,
"author": "Runium",
"author_id": 220,
"author_profile": "https://vi.stackexchange.com/users/220",
"pm_score": 5,
"selected": true,
"text": "<ol>\n<li>Yes it saves to swap file.</li>\n</ol>\n\n<p>You can do a quick test to get a <em>feel</em> of this. Go to a directory... | 2015/02/15 | [
"https://vi.stackexchange.com/questions/831",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/133/"
] | After running `:make`, the quickfix window displays the compile command and other `stdout` messages from the makefile, but it doesn't display any errors. Everything but `stderr` messages are displaying. How do I enable `stderr` messages? | 1. Yes it saves to swap file.
You can do a quick test to get a *feel* of this. Go to a directory. Say `vim notest.txt` and write some text. You do not even have to save the file.
If you list files in the working directory you will find a swap file. Copy it to a different directory (where you have no "notes.txt" file,... |
835 | <p>When doing spell checking, keying <kbd>z</kbd><kbd>=</kbd>, brings up a selection list, as shown bellow.</p>
<p><img src="https://i.stack.imgur.com/GA3Eh.png" alt="select correct"></p>
<p>As you can see the correct spelling; "i.e." is not shown as any of the options.
I would like to enhance this menu, so that I ca... | [
{
"answer_id": 852,
"author": "Quincy Bowers",
"author_id": 93,
"author_profile": "https://vi.stackexchange.com/users/93",
"pm_score": 2,
"selected": false,
"text": "<p>Without adding any plugins you can add a known good word to your spell file. Rather than <kbd>z</kbd><kbd>=</kbd> to b... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/835",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/360/"
] | When doing spell checking, keying `z``=`, brings up a selection list, as shown bellow.

As you can see the correct spelling; "i.e." is not shown as any of the options.
I would like to enhance this menu, so that I can instead just type in "i.e." and press enter and... | Looking at the `spell_suggest()` function in `spell.c` this doesn't seem possible with `z=`. After getting & displaying all the possible suggestions, it does:
```
/* Ask for choice. */
selected = prompt_for_number(&mouse_used);
```
`prompt_for_number()` lives in `misc1.c`, and does exactly what you would expect it t... |
838 | <p>I know how to remove trailing white spaces at the end of lines.
Does anyone know how to remove white spaces in the middle of a line?
The white space I mean is before tab and after tab characters.</p>
<p>For instance (tabs are shown as <code>^I</code>):</p>
<pre><code>struct {
^Iint a;
^I int b; // Here we've got a... | [
{
"answer_id": 841,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>This command will remove all whitespaces on both sides of one or more tabs in every line of the current buffer:</p>... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/838",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/496/"
] | I know how to remove trailing white spaces at the end of lines.
Does anyone know how to remove white spaces in the middle of a line?
The white space I mean is before tab and after tab characters.
For instance (tabs are shown as `^I`):
```
struct {
^Iint a;
^I int b; // Here we've got an extra whitespace after the tab... | This command will remove all whitespaces on both sides of one or more tabs in every line of the current buffer:
```
:%s/ *\([\t]\+\) */\1/g
``` |
839 | <p>Let's assume I am editing some Python code in Vim that looks a bit like:</p>
<pre><code>myobj.myfunc("Some string parameter that goes on and on and on and on and sometimes doesn't"
"split very"
"neatly over different lines so that"
"it is form... | [
{
"answer_id": 2390,
"author": "Sukima",
"author_id": 544,
"author_profile": "https://vi.stackexchange.com/users/544",
"pm_score": 3,
"selected": false,
"text": "<p>Oh that's a tough one. I think the best approach is possibly a macro but more likely a plugin. Here is an example I whipped... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/839",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | Let's assume I am editing some Python code in Vim that looks a bit like:
```
myobj.myfunc("Some string parameter that goes on and on and on and on and sometimes doesn't"
"split very"
"neatly over different lines so that"
"it is formatted attractively")
```
I would prefer to ref... | Oh that's a tough one. I think the best approach is possibly a macro but more likely a plugin. Here is an example I whipped up (I need a better hobby). It seemed to work for me but would need the python indenting plugin to indent properly. Try it out.
```
function ReformatMultiLines()
let brx = '^\s*"'
let erx = '... |
846 | <p>In my <code>~/.vimrc</code>, I have a command defined approximately like this:</p>
<pre><code>nnoremap <expr> <Leader>n ':new ~/Notes/' . strftime('%F') . '-'
</code></pre>
<p>It is designed for creating notes files that contain the current date in the filename. The keybinding is designed to leave my c... | [
{
"answer_id": 847,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": false,
"text": "<p><code>-c</code> doesn't execute keybinds in normal mode; it executes commands (what you normally do with <kbd>:</kbd>... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/846",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | In my `~/.vimrc`, I have a command defined approximately like this:
```
nnoremap <expr> <Leader>n ':new ~/Notes/' . strftime('%F') . '-'
```
It is designed for creating notes files that contain the current date in the filename. The keybinding is designed to leave my cursor on the command line so that I can type the ... | You could make a function that creates the new entry, and then use the function as part of your mapping:
```
nnoremap <leader>t :call NewEntry()<cr>
function! NewEntry()
let title = expand('~/Notes/') . strftime('%F') . '-' . input("Title: ")
execute 'edit ' . title
endfunction
```
The mapping may be called as d... |
848 | <p>I've the following sample html code:</p>
<pre><code>vim http://example.com/
</code></pre>
<p>Is there any way to actually render html inside vim editor?
In example using markdown formatting or something similar?</p>
<p>Example scenario: I'm logged on remote machine when I don't have access to GUI and I'd like to ... | [
{
"answer_id": 1872,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<p>Not really. Vim's rendering engine is not designed for this sort of thing. It just renders text.</p>\n\n<p>However, you co... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/848",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I've the following sample html code:
```
vim http://example.com/
```
Is there any way to actually render html inside vim editor?
In example using markdown formatting or something similar?
Example scenario: I'm logged on remote machine when I don't have access to GUI and I'd like to check how the html code looks lik... | Rendering html can be implemented by using a text-based web browser which can extract a formatted view of the text from an html file or a web page.
In example:
```
:!links -dump %
:!elinks -dump %
:!lynx -dump %
:!w3m -dump %
```
To define your own html preview command, try:
```
:command! ViewHtml execute ':!links... |
849 | <p>I've the following sample code which modifies the current line using Python statement:</p>
<pre><code>:py import vim; vim.current.line="["+vim.current.line+"]"
</code></pre>
<p>How I can execute this statement for each line in the current file?</p>
<p>Related: <a href="https://stackoverflow.com/questions/501585/h... | [
{
"answer_id": 850,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": false,
"text": "<p>You can get the current buffer with <code>vim.current.buffer</code>, which is an iterable; you can use use a <code>fo... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/849",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I've the following sample code which modifies the current line using Python statement:
```
:py import vim; vim.current.line="["+vim.current.line+"]"
```
How I can execute this statement for each line in the current file?
Related: [How can you use Python in Vim?](https://stackoverflow.com/questions/501585/how-can-yo... | You can use the `pydo` command available since Vim 7.4, the manual describe how it works better than I could:
>
> :[range]pydo {body}
>
>
> Execute Python function "def \_vim\_pydo(line, linenr): {body}" for each
> line in the [range], with the function arguments being set to the text
> of each line in turn, wit... |
862 | <p>I use <code>:r !uuidgen</code> frequently to insert a new uuid into the buffer. This works, but I am generally attempting to insert the uuid between quotes, and <code>:r !uuidgen</code> prints the uuid on a new line.</p>
<p>To get around this issue, I am currently using a simple keymap:</p>
<pre><code>nnoremap <... | [
{
"answer_id": 863,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": true,
"text": "<p>You can use the expression register <code>\"=</code> and <code>system()</code>:</p>\n\n<pre><code><C-r>=system(\"uuidgen... | 2015/02/16 | [
"https://vi.stackexchange.com/questions/862",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I use `:r !uuidgen` frequently to insert a new uuid into the buffer. This works, but I am generally attempting to insert the uuid between quotes, and `:r !uuidgen` prints the uuid on a new line.
To get around this issue, I am currently using a simple keymap:
```
nnoremap <C-u> mm:r!uuidgen<CR>dW"_dd`mp
```
This mac... | You can use the expression register `"=` and `system()`:
```
<C-r>=system("uuidgen | tr -d '\n'")<CR>
```
It would look like that in an insert mode mapping:
```
inoremap <key> <C-r>=system("uuidgen | tr -d '\n'")<CR>
```
or, with an expression mapping:
```
inoremap <expr> <key> system("uuidgen \| tr -d '\n'")
`... |
1,874 | <p>If I have windows arranged into four quadrants, as from the following sequence of commands:</p>
<ul>
<li><code>:tabnew</code></li>
<li><code>:vsplit</code></li>
<li><code>:split</code></li>
<li><code><C-W>l</code></li>
<li><code>:split</code></li>
</ul>
<p>then entering a command like <code><C-W>J</cod... | [
{
"answer_id": 863,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": true,
"text": "<p>You can use the expression register <code>\"=</code> and <code>system()</code>:</p>\n\n<pre><code><C-r>=system(\"uuidgen... | 2015/02/17 | [
"https://vi.stackexchange.com/questions/1874",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/142/"
] | If I have windows arranged into four quadrants, as from the following sequence of commands:
* `:tabnew`
* `:vsplit`
* `:split`
* `<C-W>l`
* `:split`
then entering a command like `<C-W>J` will cause these to no longer be square; in this case, it will force one window to float at the bottom.
How can I do the opposite—... | You can use the expression register `"=` and `system()`:
```
<C-r>=system("uuidgen | tr -d '\n'")<CR>
```
It would look like that in an insert mode mapping:
```
inoremap <key> <C-r>=system("uuidgen | tr -d '\n'")<CR>
```
or, with an expression mapping:
```
inoremap <expr> <key> system("uuidgen \| tr -d '\n'")
`... |
1,887 | <p>I have a list of words, like this:</p>
<pre><code>these are
some
words that I want
to convert to
camel case
</code></pre>
<p>I need a way to turn, for example, <code>camel case</code> into <code>camelCase</code> within a macro (or a way to turn every line of a visual line selection into camel case).</p>
<p>I coul... | [
{
"answer_id": 1888,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 5,
"selected": true,
"text": "<h2>A One Liner</h2>\n\n<p>I found a simple regular expression replacement (assuming 'magic' is set):</p>\n\n<pre><code>:s/ ... | 2015/02/18 | [
"https://vi.stackexchange.com/questions/1887",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/88/"
] | I have a list of words, like this:
```
these are
some
words that I want
to convert to
camel case
```
I need a way to turn, for example, `camel case` into `camelCase` within a macro (or a way to turn every line of a visual line selection into camel case).
I could use something like `wgUlhx` as many times as necessar... | A One Liner
-----------
I found a simple regular expression replacement (assuming 'magic' is set):
```
:s/ \([a-zA-Z]\)/\u\1/g
```
This match any single letter after a space, saving the letter. Then, it replaces it with the saved letter made upper case (`\u` = upper case, `\1` = first saved match), for every match ... |
1,889 | <p>I get this problem when I start Vim with <code>-p</code> option. Suppose, I started out with</p>
<pre><code>vim -p first.txt second.txt
</code></pre>
<p>Then after editing <code>first.txt</code> I move to <code>second.txt</code> using <code>gt</code>. I press the keys <code>gg</code> and <code>G</code> again. This... | [
{
"answer_id": 1899,
"author": "derobert",
"author_id": 31,
"author_profile": "https://vi.stackexchange.com/users/31",
"pm_score": 3,
"selected": false,
"text": "<p>The SEGV signal, also known as a segfault, is almost always due to a bug in the program you're running—in this case, vim. (... | 2015/02/18 | [
"https://vi.stackexchange.com/questions/1889",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/534/"
] | I get this problem when I start Vim with `-p` option. Suppose, I started out with
```
vim -p first.txt second.txt
```
Then after editing `first.txt` I move to `second.txt` using `gt`. I press the keys `gg` and `G` again. This produces the error
```
Vim: Caught deadly signal SEGV
```
From this point, Vim doesn't ... | The SEGV signal, also known as a segfault, is almost always due to a bug in the program you're running—in this case, vim. (Other causes are things like defective hardware, or once in a blue moon, kernel bugs).
So, really, you need to report a bug. [`:help bug-reports`](http://vimhelp.appspot.com/intro.txt.html#bug-rep... |
1,905 | <p>I am using Vim to program in Java 8, and am having a problem with syntax highlighting.</p>
<p>A new feature in Java 8 is lambda support, which resulted in the creation of the arrow operator: <code>-></code>. Vim does not recognize this as a valid operator in a *.java file. As such, it highlights this operator i... | [
{
"answer_id": 1906,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 6,
"selected": true,
"text": "<h3>2016 update</h3>\n\n<p>The Vim syntax file <a href=\"https://github.com/vim/vim/commit/f3c2afb77f8b1f2591337fcaa90ba... | 2015/02/18 | [
"https://vi.stackexchange.com/questions/1905",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/239/"
] | I am using Vim to program in Java 8, and am having a problem with syntax highlighting.
A new feature in Java 8 is lambda support, which resulted in the creation of the arrow operator: `->`. Vim does not recognize this as a valid operator in a \*.java file. As such, it highlights this operator in bright red to draw att... | ### 2016 update
The Vim syntax file [was updated for this in v7.4.649](https://github.com/vim/vim/commit/f3c2afb77f8b1f2591337fcaa90ba0fb45365cbc#diff-eda7359419b4ac52df5a77541cf1e82f) (March 2015); so if you have this patch you don't need to do this.
The easiest way to fix this is probably by downloading the [newer ... |
1,922 | <p>How does one get vim to replace a character within the visual selection <strong>only</strong> and not elsewhere on the line? Example:</p>
<ul>
<li>Line: <code>int arr[] = { 00 01 02 03 04 05 05 /* ... lots more like this*/};</code> </li>
<li>Visual Selection: <code>{ 00 01 02 03 04 05 05 /*... lots more like this*/... | [
{
"answer_id": 1926,
"author": "VenkatH",
"author_id": 587,
"author_profile": "https://vi.stackexchange.com/users/587",
"pm_score": 7,
"selected": true,
"text": "<pre><code>:'<,'>s/\\%V\\ /\\,0x/g\n</code></pre>\n\n<p><code>%V</code> matches inside the visual area. See <a href=\"ht... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1922",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/224/"
] | How does one get vim to replace a character within the visual selection **only** and not elsewhere on the line? Example:
* Line: `int arr[] = { 00 01 02 03 04 05 05 /* ... lots more like this*/};`
* Visual Selection: `{ 00 01 02 03 04 05 05 /*... lots more like this*/}`
* Command: `:'<,'>s/\ /\,0x/g`
* Expected: `int ... | ```
:'<,'>s/\%V\ /\,0x/g
```
`%V` matches inside the visual area. See [`:help %V`](http://vimhelp.appspot.com/pattern.txt.html#%2F%5C%25V). |
1,923 | <p>I <em>knew</em> this site would teach me more about my beloved <code>vim</code> :-) In posting a question/answer on <a href="https://vi.stackexchange.com/questions/1915/how-do-i-delete-a-large-block-of-text-without-counting-the-lines">how to delete large blocks without having to count lines</a>, one of the answers t... | [
{
"answer_id": 1925,
"author": "200_success",
"author_id": 24,
"author_profile": "https://vi.stackexchange.com/users/24",
"pm_score": 5,
"selected": true,
"text": "<p>Don't do that. A numbering system that goes from -1 to +1 without a zero in between is just asking for trouble.</p>\n\n<... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1923",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I *knew* this site would teach me more about my beloved `vim` :-) In posting a question/answer on [how to delete large blocks without having to count lines](https://vi.stackexchange.com/questions/1915/how-do-i-delete-a-large-block-of-text-without-counting-the-lines), one of the answers taught me something I didn't know... | Don't do that. A numbering system that goes from -1 to +1 without a zero in between is just asking for trouble.
As an alternative habit, I suggest `d``2``j` — "delete this line and the next two lines". That works both ways: `d``2``k` deletes upward.
A long-winded ex command version of that would be `:+2d`. |
1,937 | <p>I'd like to have my editors give me as much screen real estate as possible since it increases my ability to see most of the code at once.</p>
<p>The problem is that <code>gvim</code> seems to give me either an 80x25 window or remember the last non-maximised size, depending on how I invoke it.</p>
<p>So, how can I ... | [
{
"answer_id": 1938,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "<p>You can put this line:</p>\n\n<pre><code>autocmd GUIEnter * simalt ~x\n</code></pre>\n\n<p>at the end of your <code>gvimrc<... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1937",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I'd like to have my editors give me as much screen real estate as possible since it increases my ability to see most of the code at once.
The problem is that `gvim` seems to give me either an 80x25 window or remember the last non-maximised size, depending on how I invoke it.
So, how can I force it to be as large as p... | You can put this line:
```
autocmd GUIEnter * simalt ~x
```
at the end of your `gvimrc` file.
This method uses the `autocmd` feature to weave its magic. The command `autocmd GUIEnter *` specifies a command to run after successfully starting the GUI for a file pattern of `*` (any file).
The command it will execute,... |