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
6,318
<p>I've the following format of the file:</p> <pre><code>&lt;common&gt; fitnes=0 genetic=1 method=0 &lt;/common&gt; &lt;inputs&gt; foo=bar bar=foo &lt;/inputs&gt; &lt;limits&gt; balance=200.00 &lt;/limits&gt; </code></pre> <p>and I would like to delete everything what is between <code>&lt;inputs&gt;</code> and <code>...
[ { "answer_id": 6322, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 3, "selected": false, "text": "<p>This seems to work, at least on a Unix system:</p>\n\n<pre><code>:/&lt;inputs&gt;/+1,/&lt;\\/inputs&gt;/-1!cat foo.txt\...
2016/02/01
[ "https://vi.stackexchange.com/questions/6318", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/467/" ]
I've the following format of the file: ``` <common> fitnes=0 genetic=1 method=0 </common> <inputs> foo=bar bar=foo </inputs> <limits> balance=200.00 </limits> ``` and I would like to delete everything what is between `<inputs>` and `</inputs>` (excluding pattern it-self) and replace it with the content from another ...
A substitution can be used to replace a pattern with the result of an expression like this: ``` :keeppatterns %s;<inputs>\zs\_.\{-}\ze</inputs>;\=insert(readfile('test.txt'), '') ``` See `:help sub-replace-expression` Note that `keeppatterns` prevents the `substitute` command from adding anything to the search hist...
6,331
<p>Hi I want to search text inside gvim with the following criteria <code>a&amp;b&amp;(c|d)</code>. I know for <code>a&amp;b</code> it is <code>/.*a\&amp;.*b</code> and for <code>c|d</code> it is <code>/c\|d</code> but combining these two doesnt work. what can be the exact command ?</p> <p>edit: I tried <code>.*a\&am...
[ { "answer_id": 6335, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 4, "selected": true, "text": "<p>From <code>:help \\&amp;</code>:</p>\n\n<pre><code>2. A branch is one or more concats, separated by \"\\&amp;\". It match...
2016/02/02
[ "https://vi.stackexchange.com/questions/6331", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6247/" ]
Hi I want to search text inside gvim with the following criteria `a&b&(c|d)`. I know for `a&b` it is `/.*a\&.*b` and for `c|d` it is `/c\|d` but combining these two doesnt work. what can be the exact command ? edit: I tried `.*a\&.*b\&.*(c\|d)`, but it is taking it as `.*a\&.*b\&.*(c` ORed with `d)` , inc brackets. ...
From `:help \&`: ``` 2. A branch is one or more concats, separated by "\&". It matches the last concat, but only if all the preceding concats also match at the same position. Examples: "foobeep\&..." matches "foo" in "foobeep". ".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob" ``` ...
6,340
<p>I'm trying to change between the active buffer and the alternate buffer with the command <kbd>Ctrl</kbd> + <kbd>^</kbd> as this <a href="http://vimcasts.org/episodes/working-with-buffers/" rel="nofollow noreferrer">video</a> explains. However, nothing happens. I'm using a Spanish keyboard and to press the <kbd>^</kb...
[ { "answer_id": 6342, "author": "djjcast", "author_id": 6206, "author_profile": "https://vi.stackexchange.com/users/6206", "pm_score": 5, "selected": true, "text": "<p><code>CTRL-6</code> can be used to edit the alternate file - tested on OS X by changing the input source from U.S. to Spa...
2016/02/02
[ "https://vi.stackexchange.com/questions/6340", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5081/" ]
I'm trying to change between the active buffer and the alternate buffer with the command `Ctrl` + `^` as this [video](http://vimcasts.org/episodes/working-with-buffers/) explains. However, nothing happens. I'm using a Spanish keyboard and to press the `^` accent, I have to hit `Shift` therefore I have to type `Ctrl` + ...
`CTRL-6` can be used to edit the alternate file - tested on OS X by changing the input source from U.S. to Spanish ISO. If you find yourself wanting to edit the alternate file often, you could consider mapping backspace to edit the alternate file like this: ``` " 'edit alternate file' convenience mapping nnoremap <BS...
6,341
<p>You can reflow a paragraph with <code>gqip</code> (or <code>gqap</code>).</p> <p>Is the fastest way to sort a paragraph <code>vip:sort&lt;cr&gt;</code>? Or is there some shorter keystroke for sorting?</p>
[ { "answer_id": 6343, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>You can create a simple normal mode mapping:</p>\n\n<pre><code>nnoremap &lt;key&gt; :'{,'}sort&lt;CR&gt;\n\nusage from norma...
2016/02/02
[ "https://vi.stackexchange.com/questions/6341", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5574/" ]
You can reflow a paragraph with `gqip` (or `gqap`). Is the fastest way to sort a paragraph `vip:sort<cr>`? Or is there some shorter keystroke for sorting?
You could define a "sort lines" operator like this: ``` function! s:SortLinesOpFunc(...) '[,']sort endfunction nnoremap <silent> \s :<C-u>set operatorfunc=<SID>SortLinesOpFunc<CR>g@ ``` `\sip` will sort the paragraph under the cursor and, in general, `\s{motion}` will sort the lines moved over by `{motion}`, in...
6,358
<p>I use Vim for writing C++, and I have quite a few <code>#include&lt;&gt;</code> statements, comments, etc. that I must include in each new file I create. I've added </p> <pre><code>autocmd BufNewFile *.cpp r C:\(full file path of skeleton text file) </code></pre> <p>to my vimrc, because I heard this creates a bu...
[ { "answer_id": 6360, "author": "electriccello", "author_id": 6280, "author_profile": "https://vi.stackexchange.com/users/6280", "pm_score": 3, "selected": false, "text": "<p>Skeleton text from an existing file can be added to a new file by inserting the line </p>\n\n<pre><code>autocmd Bu...
2016/02/04
[ "https://vi.stackexchange.com/questions/6358", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6280/" ]
I use Vim for writing C++, and I have quite a few `#include<>` statements, comments, etc. that I must include in each new file I create. I've added ``` autocmd BufNewFile *.cpp r C:\(full file path of skeleton text file) ``` to my vimrc, because I heard this creates a buffer with the text I need in it. How do I go...
Skeleton text from an existing file can be added to a new file by inserting the line ``` autocmd BufNewFile *.cpp r C:\(full file path of skeleton text file) ``` into the vimrc. The `BufNewFile` event does not work if the new file is created in two steps using `:enew` then `:sav filename`. Instead, creating a new f...
6,364
<p>Using UltiSnips, I'd like to add a set of snippets just for one file or for a set of files in the same directory, maybe using a <code>:vim</code> modeline. </p> <p>I tried to put </p> <pre><code> let g:UltiSnipsSnippetDirectories=["UltiSnips", "."] </code></pre> <p>in my <code>.vimrc</code> and then adding a <cod...
[ { "answer_id": 6365, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>If your template expander plugin doesn't support snippets local to the current buffer, i.e. if <code>b:UltiSnipsSnipp...
2016/02/04
[ "https://vi.stackexchange.com/questions/6364", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/854/" ]
Using UltiSnips, I'd like to add a set of snippets just for one file or for a set of files in the same directory, maybe using a `:vim` modeline. I tried to put ``` let g:UltiSnipsSnippetDirectories=["UltiSnips", "."] ``` in my `.vimrc` and then adding a `all.snippets` file in the same directory of the file (by t...
If your template expander plugin doesn't support snippets local to the current buffer, i.e. if `b:UltiSnipsSnippetDirectories` is not understood in your case, you can * ask the maintainers to use this variable if defined, or the global one otherwise -- this is the best course of action * or you can use another snippet...
6,366
<p>Rather than choosing one character to be displayed as the EOL character, I'd like one to display for both CR and LF separately and regardless of if the file is unix or dos. Is this possible?</p>
[ { "answer_id": 9539, "author": "Ptolemarch", "author_id": 527, "author_profile": "https://vi.stackexchange.com/users/527", "pm_score": 3, "selected": true, "text": "<p>With some caveats, you can do this using Vim's binary mode. It seems you might want to use the command</p>\n\n<pre><code...
2016/02/04
[ "https://vi.stackexchange.com/questions/6366", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4833/" ]
Rather than choosing one character to be displayed as the EOL character, I'd like one to display for both CR and LF separately and regardless of if the file is unix or dos. Is this possible?
With some caveats, you can do this using Vim's binary mode. It seems you might want to use the command ``` vim -b +'set list' somefile ``` Alternatively, you can put the following in your `.vimrc`: ``` :set binary :set list ``` The important thing is that binary mode must get set *before* the file in question is ...
6,370
<p>I want to remap <code>&lt;C-i&gt;*character*</code> to <code>i*character*&lt;Esc&gt;</code> for easy inserting of single characters. This is what I've written:</p> <pre><code>let printable_characters = [ '!', '"', '#', '$', '%', '&amp;', '''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6...
[ { "answer_id": 6371, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 4, "selected": true, "text": "<p>There is a much better way of accomplishing this than brute forcing it. You can use these simple expr mappings inste...
2016/02/04
[ "https://vi.stackexchange.com/questions/6370", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6300/" ]
I want to remap `<C-i>*character*` to `i*character*<Esc>` for easy inserting of single characters. This is what I've written: ``` let printable_characters = [ '!', '"', '#', '$', '%', '&', '''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@',...
There is a much better way of accomplishing this than brute forcing it. You can use these simple expr mappings instead: ``` nnoremap <expr> <c-i> "i" . nr2char(getchar()) . "<Esc>" nnoremap <expr> <c-a> "a" . nr2char(getchar()) . "<Esc>" ``` Here is how they work: * `nnoremap <expr> <c-i>` - Create a mapping for `C...
6,378
<p>Imagine I have the following text:</p> <pre><code>some random stuff * asdf * foo * bar some other random stuff </code></pre> <p>I want to replace the asterisk bullets with numbers, like so:</p> <pre><code>some random stuff 1. asdf 2. foo 3. bar some other random stuff </code></pre> <p>How can this be done in vim...
[ { "answer_id": 6380, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 5, "selected": true, "text": "<p>You could try the following command:</p>\n\n<pre><code>:let c=0 | g/^* /let c+=1 | s//\\=c.'. '\n</code></pre>\n\n<hr>\n\...
2016/02/05
[ "https://vi.stackexchange.com/questions/6378", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6310/" ]
Imagine I have the following text: ``` some random stuff * asdf * foo * bar some other random stuff ``` I want to replace the asterisk bullets with numbers, like so: ``` some random stuff 1. asdf 2. foo 3. bar some other random stuff ``` How can this be done in vim ?
You could try the following command: ``` :let c=0 | g/^* /let c+=1 | s//\=c.'. ' ``` --- First it initializes the variable `c` (`let c=0`), then it executes the global command `g` which looks for the pattern `^*` (a beginning of line, followed by an asterisk and a space). Whenever a line containing this pattern is...
6,391
<p>To work, abbreviations need to be separated by whitespace. E.g., if I have an <code>iab fo FOOBAR</code> then typing <code>whatfo</code> will not trigger the abbreviation. There are some obvious sensible reasons for this.</p> <p>However, I'd like an abbreviation that could be used as a suffix without me having to...
[ { "answer_id": 6392, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 4, "selected": true, "text": "<p>You could write inside your vimrc: <code>iab fo &lt;BS&gt;FOOBAR</code></p>\n\n<p><code>&lt;BS&gt;</code> is the notation...
2016/02/06
[ "https://vi.stackexchange.com/questions/6391", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4913/" ]
To work, abbreviations need to be separated by whitespace. E.g., if I have an `iab fo FOOBAR` then typing `whatfo` will not trigger the abbreviation. There are some obvious sensible reasons for this. However, I'd like an abbreviation that could be used as a suffix without me having to trigger the iab then go back and ...
You could write inside your vimrc: `iab fo <BS>FOOBAR` `<BS>` is the notation to use for the backspace key. For more information about special key names, see: ``` :help key-notation ```
6,414
<p>I have a question regarding a plugin called <a href="https://github.com/Shougo/vimfiler.vim" rel="nofollow">Vimfiler</a>. What I want is to open a .doc/.docx file using MS Word from <strong>Vimfiler</strong>. For this, I added the following</p> <pre><code>call vimfiler#set_execute_file('doc,docx', '/Applications/Mi...
[ { "answer_id": 6415, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 2, "selected": false, "text": "<p>I don't have Word or Windows so I tried solving your issue with Libreoffice and <code>.odt</code> files. The following c...
2016/02/09
[ "https://vi.stackexchange.com/questions/6414", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6349/" ]
I have a question regarding a plugin called [Vimfiler](https://github.com/Shougo/vimfiler.vim). What I want is to open a .doc/.docx file using MS Word from **Vimfiler**. For this, I added the following ``` call vimfiler#set_execute_file('doc,docx', '/Applications/Microsoft Word.app') ``` to `.vimrc`. Even if I press...
In your specific case, it is likely OSX already associates `.doc` and `.docx` files with MS Word. So you can use that to your advantage, using `vimfiler_execute_system_associated`, which is mapped to `x`: ``` x <Plug>(vimfiler_execute_system_associated) ``` Just pressing `x` on the filename sho...
6,426
<p>How can I create a recursive macro so that it only runs until the end of the line?</p> <p>Or how to run a recursive macro until the end of the line only?</p>
[ { "answer_id": 6427, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 5, "selected": true, "text": "<p>There is probably a simpler method but maybe you could try the following.</p>\n\n<p>Let's say you will use register <code...
2016/02/10
[ "https://vi.stackexchange.com/questions/6426", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6362/" ]
How can I create a recursive macro so that it only runs until the end of the line? Or how to run a recursive macro until the end of the line only?
There is probably a simpler method but maybe you could try the following. Let's say you will use register `q` to record your recursive macro. At the very beginning of the recording, type: ``` :let a = line('.') ``` Then, at the very end of the recording, instead of hitting `@q` to make the macro recursive, type th...
6,452
<p>I wanted to write this:</p> <pre><code>A = mapping[0] B = mapping[1] C = mapping[2] D = mapping[3] E = mapping[4] F = mapping[5] G = mapping[6] H = mapping[7] I = mapping[8] J = mapping[9] K = mapping[10] L = mapping[11] M = mapping[12] N = mapping[13] O = mapping[14] P = mapping[15] Q = mapping[16] R = mapping[17]...
[ { "answer_id": 6453, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 4, "selected": false, "text": "<p>While it can be done with scripting, if you have a very recent version of Vim (e.g. the one in Arch Linux), you can use...
2016/02/12
[ "https://vi.stackexchange.com/questions/6452", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6402/" ]
I wanted to write this: ``` A = mapping[0] B = mapping[1] C = mapping[2] D = mapping[3] E = mapping[4] F = mapping[5] G = mapping[6] H = mapping[7] I = mapping[8] J = mapping[9] K = mapping[10] L = mapping[11] M = mapping[12] N = mapping[13] O = mapping[14] P = mapping[15] Q = mapping[16] R = mapping[17] S = mapping[1...
While it can be done with scripting, if you have a very recent version of Vim (e.g. the one in Arch Linux), you can use `g Ctrl-a` to increment a visual block. In your case: 1. Write the original line: `A = mapping[0]` `Esc` 2. Yank line and put 25 copies of it below: `yy25p` 3. Visually select the column containing t...
6,459
<p>I found it hard to understand these text object motions:</p> <pre><code> *]]* ]] [count] sections forward or to the next '{' in the first column. When used after an operator, then also stops below a '}' in the first column. |exclusive| Note t...
[ { "answer_id": 6521, "author": "dash-tom-bang", "author_id": 6430, "author_profile": "https://vi.stackexchange.com/users/6430", "pm_score": 2, "selected": false, "text": "<p>These are to move to the top and bottom of functions, where the assumption is that functions' opening and closing ...
2016/02/12
[ "https://vi.stackexchange.com/questions/6459", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6405/" ]
I found it hard to understand these text object motions: ``` *]]* ]] [count] sections forward or to the next '{' in the first column. When used after an operator, then also stops below a '}' in the first column. |exclusive| Note that |exclusive...
It helps to test these out on a file. You can think of these as "forward" and "backward" X "to start" and "to end" Try using the four motions on this block of text: ``` function one {#1 }#2 function two {#3 }#4 function three {#5 }#6 ``` I don't know how to do those often helpful movement gifs, but basically e...
6,463
<p>I have done a bit of research about this but found only very old answers, <a href="http://vim_use.narkive.com/2WmlB8vD/buffer-local-mode">like this one</a>, and all on the negative side. </p> <p>My problem is the following --- suppose you are working on a document/program, say for example a LaTeX file. You have som...
[ { "answer_id": 6467, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 2, "selected": false, "text": "<p>I'm going to be bold and claim that your problem will be solved if you learn to use Vim/vi without using the mouse...
2016/02/13
[ "https://vi.stackexchange.com/questions/6463", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/854/" ]
I have done a bit of research about this but found only very old answers, [like this one](http://vim_use.narkive.com/2WmlB8vD/buffer-local-mode), and all on the negative side. My problem is the following --- suppose you are working on a document/program, say for example a LaTeX file. You have some error and you open ...
In order for Vim to remember if you are in insert mode or not for each window opened, you could add the following autocmds inside your vimrc: ``` augroup RememberMode autocmd! autocmd WinLeave * let w:mode_state = mode() autocmd WinEnter * \ if exists('w:mode_state') && w:mode_state ==# 'i'...
6,485
<p>Referencing Post:</p> <p><a href="https://stackoverflow.com/questions/22206332/vim-ag-search-and-replace-globally-and-within-a-directory">https://stackoverflow.com/questions/22206332/vim-ag-search-and-replace-globally-and-within-a-directory</a></p> <p>Specifically:</p> <pre><code>:Ag foo :Qfdo s/foo/bar/c </code>...
[ { "answer_id": 6487, "author": "user1135541", "author_id": 3050, "author_profile": "https://vi.stackexchange.com/users/3050", "pm_score": 2, "selected": false, "text": "<p>It looks like you have to <code>:AgAdd</code> instead of just <code>Ag</code>, which will add the results to quick l...
2016/02/15
[ "https://vi.stackexchange.com/questions/6485", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3050/" ]
Referencing Post: <https://stackoverflow.com/questions/22206332/vim-ag-search-and-replace-globally-and-within-a-directory> Specifically: ``` :Ag foo :Qfdo s/foo/bar/c ``` I type `Ag miwt-os`, I get this: [![enter image description here](https://i.stack.imgur.com/OATJb.png)](https://i.stack.imgur.com/OATJb.png) W...
You don't need a plugin for using The Silver Searcher — or any other grep alternative — in Vim: ``` set grepprg=ag\ --nogroup\ --nocolor\ --ignore-case\ --column\ --vimgrep set grepformat=%f:%l:%c:%m,%f:%l:%m ``` With those lines in your `vimrc` you can simply do `:grep miwt-os` to populate the quickfix list with ma...
6,490
<p>I normally work with 2 windows, vertically split.</p> <p>The problem I would like to solve, is: <em>easily jumping back and forth from header &lt;-> implementation file</em></p> <p>I'm investigating, without luck, 2 ways to do this:</p> <ol> <li><em>Open alternate file in <strong>current</strong> window</em>: The...
[ { "answer_id": 6491, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>There's three main steps in accomplishing what you're asking:</p>\n\n<ul>\n<li>getting the alternate file's name</li>\n<li...
2016/02/15
[ "https://vi.stackexchange.com/questions/6490", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6427/" ]
I normally work with 2 windows, vertically split. The problem I would like to solve, is: *easily jumping back and forth from header <-> implementation file* I'm investigating, without luck, 2 ways to do this: 1. *Open alternate file in **current** window*: There are many ways to do this, however, I can't find a way ...
There's three main steps in accomplishing what you're asking: * getting the alternate file's name * opening that file in the current window or in another window as desired * restoring cursor position within that file To find the alternate file name you want to break the current file name into the "root" and the "exte...
6,496
<p>I have this in my <code>.vimrc</code></p> <pre><code>let $ROOTPATH=FindRootDirectory() nnoremap &lt;leader&gt;ct :!clear&lt;CR&gt;:!$ROOTPATH/app/Console/cake test %:p&lt;CR&gt; </code></pre> <p>Is there a way I can write this in one line?</p> <p>Using <a href="https://github.com/vim-scripts/vim-rooter" rel="nofo...
[ { "answer_id": 6491, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>There's three main steps in accomplishing what you're asking:</p>\n\n<ul>\n<li>getting the alternate file's name</li>\n<li...
2016/02/16
[ "https://vi.stackexchange.com/questions/6496", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3302/" ]
I have this in my `.vimrc` ``` let $ROOTPATH=FindRootDirectory() nnoremap <leader>ct :!clear<CR>:!$ROOTPATH/app/Console/cake test %:p<CR> ``` Is there a way I can write this in one line? Using [vim-rooter pluguin](https://github.com/vim-scripts/vim-rooter)
There's three main steps in accomplishing what you're asking: * getting the alternate file's name * opening that file in the current window or in another window as desired * restoring cursor position within that file To find the alternate file name you want to break the current file name into the "root" and the "exte...
6,507
<p>Thanks to <a href="https://vi.stackexchange.com/questions/6448/how-do-i-run-cakephps-tests-phpunit-and-output-it-to-quickrun-or-other-window/6450#6450">@muru</a> I was able to run and output the data to QuickRun by the <code>:make</code> command and this setting in my <code>.vimrc</code>:</p> <pre><code>set makeprg...
[ { "answer_id": 6491, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>There's three main steps in accomplishing what you're asking:</p>\n\n<ul>\n<li>getting the alternate file's name</li>\n<li...
2016/02/16
[ "https://vi.stackexchange.com/questions/6507", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3302/" ]
Thanks to [@muru](https://vi.stackexchange.com/questions/6448/how-do-i-run-cakephps-tests-phpunit-and-output-it-to-quickrun-or-other-window/6450#6450) I was able to run and output the data to QuickRun by the `:make` command and this setting in my `.vimrc`: ``` set makeprg=/vagrant/my_project/app/Console/cake\ test\ ap...
There's three main steps in accomplishing what you're asking: * getting the alternate file's name * opening that file in the current window or in another window as desired * restoring cursor position within that file To find the alternate file name you want to break the current file name into the "root" and the "exte...
6,511
<p>There are several times, I need to <code>grep</code> for <code>some_pattern</code> in some <code>XHTML</code> files (many a time, file count in a specified folder goes beyond 10K+).</p> <p>Previously, I have used <a href="http://www.lugaru.com/" rel="noreferrer">Lugaru's Epsilon Programmer's Editor</a> and there wa...
[ { "answer_id": 6519, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 4, "selected": true, "text": "<p>You definitively should try the plugin <a href=\"https://github.com/sk1418/QFGrep\" rel=\"nofollow noreferrer\">QFGrep plu...
2016/02/16
[ "https://vi.stackexchange.com/questions/6511", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5912/" ]
There are several times, I need to `grep` for `some_pattern` in some `XHTML` files (many a time, file count in a specified folder goes beyond 10K+). Previously, I have used [Lugaru's Epsilon Programmer's Editor](http://www.lugaru.com/) and there was `grep` command which invokes the search, and results a list of all ma...
You definitively should try the plugin [QFGrep plugin](https://github.com/sk1418/QFGrep), which was created after the similar question mentioned in the comments: [Is it possible to grep Vimʼs quickfix?](https://stackoverflow.com/questions/15406138/is-it-possible-to-grep-vim%ca%bcs-quickfix). I've been using it for a y...
6,525
<p>I have a number of lines in a file, and I would like to copy each line 11 times (turning each line into 12 lines), and increment the last "1" in each line so that the 12 lines have "1" through "12", where the "1" initially was. There may be other occurrences of "1" in each line, but the "1" I want to increment will ...
[ { "answer_id": 6526, "author": "jjaderberg", "author_id": 1306, "author_profile": "https://vi.stackexchange.com/users/1306", "pm_score": 3, "selected": false, "text": "<p>You could do this by</p>\n\n<ol>\n<li>recording a macro, then</li>\n<li>using the <code>global</code> ex command to e...
2016/02/16
[ "https://vi.stackexchange.com/questions/6525", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6195/" ]
I have a number of lines in a file, and I would like to copy each line 11 times (turning each line into 12 lines), and increment the last "1" in each line so that the 12 lines have "1" through "12", where the "1" initially was. There may be other occurrences of "1" in each line, but the "1" I want to increment will alw...
Here's a substitution that solves the problem: ``` :%s/\(.*\)1\(.*\)/\=join(map(range(1, 12), 'submatch(1) . v:val . submatch(2)'), "\n") ``` The substitution matches each line that contains "1" and captures the text before `{c1}` and after `{c2}` the last "1". For each matched line, the range of numbers from one to...
6,535
<p>Assume the content:</p> <pre><code>foo fnord bar;" &gt;&gt; /tmp/foo/derp gnarf foo fnord bar;" &gt;&gt; /tmp/foo/derp </code></pre> <p>I want to jump to the " and delete to end of line and repeat that over the rest of lines.</p> <p>Yet when I:</p> <pre><code>f"d$ j . </code></pre> <p>it only deletes from my cu...
[ { "answer_id": 6538, "author": "fruglemonkey", "author_id": 4932, "author_profile": "https://vi.stackexchange.com/users/4932", "pm_score": 4, "selected": true, "text": "<p>From the <a href=\"http://vimdoc.sourceforge.net/htmldoc/repeat.html\">repeat documentation</a> :</p>\n\n<pre><code>...
2016/02/17
[ "https://vi.stackexchange.com/questions/6535", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5449/" ]
Assume the content: ``` foo fnord bar;" >> /tmp/foo/derp gnarf foo fnord bar;" >> /tmp/foo/derp ``` I want to jump to the " and delete to end of line and repeat that over the rest of lines. Yet when I: ``` f"d$ j . ``` it only deletes from my current cursor position to the end of file. ``` foo fnord bar; gnarf ...
From the [repeat documentation](http://vimdoc.sourceforge.net/htmldoc/repeat.html) : ``` . Repeat last change, with count replaced with [count]. Also repeat a yank command, when the 'y' flag is included in 'cpoptions'. Does not repeat a command-line command. ``` So, as ...
6,551
<p>In XCode, there is an add-on called vvdocument, which can detect three <code>/</code> hits, and transfer <code>///</code> into:</p> <pre><code>/*! * @author Robbie Yi JIANG, 29-Jan-2016 14:01:45 * * */ </code></pre> <p>How can I do this in Vim.</p>
[ { "answer_id": 6554, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": false, "text": "<p>One way would be to create a file containing this snippet, and read it when you type <code>///</code>.</p>\n\n<p>For example,...
2016/02/18
[ "https://vi.stackexchange.com/questions/6551", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6227/" ]
In XCode, there is an add-on called vvdocument, which can detect three `/` hits, and transfer `///` into: ``` /*! * @author Robbie Yi JIANG, 29-Jan-2016 14:01:45 * * */ ``` How can I do this in Vim.
The method in [my earlier answer](https://vi.stackexchange.com/a/6554/205) doesn't transform well to dynamic content. This is where snippet plugins like UltiSnips and SnipMate come in. I'll provide a demo of [UltiSnips](https://github.com/SirVer/ultisnips) here. Install it using your favourite method from [How do I ins...
6,558
<p>I have Python 2.7.9 installed. And now I get the message that the Gundo plugin requires 2.4. Is there a workaround?</p> <p>Here is my vimrc file:</p> <pre><code>set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize se...
[ { "answer_id": 6559, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 3, "selected": false, "text": "<p>Try the <a href=\"https://github.com/mbbill/undotree/\" rel=\"noreferrer\">undotree plugin</a>:</p>\n\n<blockquote>\n <p...
2016/02/18
[ "https://vi.stackexchange.com/questions/6558", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5346/" ]
I have Python 2.7.9 installed. And now I get the message that the Gundo plugin requires 2.4. Is there a workaround? Here is my vimrc file: ``` set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/...
Try the [undotree plugin](https://github.com/mbbill/undotree/): > > Someone asked me about the difference with Gundo, here is a list of > differences, or advantages. > > > 1. **Pure vimscript implementation and no 3rd-party libraries(like python) is needed**, don't worry about performance, it's not such a big > d...
6,561
<p>I have a CSV that uses ,(comma) as the delimiter. This CSV is nearly 20K lines long and there are 10 instances where a comma was used INSIDE the data. These errant commas are breaking my processor.</p> <p>In VIM, how would you locate ONLY the lines that have more than 1 comma?</p> <p>I can find all commas using </...
[ { "answer_id": 6562, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 4, "selected": true, "text": "<p>I can think of two expressions offhand that may work for you. They both worked on some quick, limited test data I tried. Th...
2016/02/18
[ "https://vi.stackexchange.com/questions/6561", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1417/" ]
I have a CSV that uses ,(comma) as the delimiter. This CSV is nearly 20K lines long and there are 10 instances where a comma was used INSIDE the data. These errant commas are breaking my processor. In VIM, how would you locate ONLY the lines that have more than 1 comma? I can find all commas using ``` :%s/,//gn ``...
I can think of two expressions offhand that may work for you. They both worked on some quick, limited test data I tried. The first expression is ``` \(.\{-},\)\{2,} ``` This translates to "match at least 2 sequences of (as few as possible of anything followed by a comma)." In other words this tries to find matches o...
6,579
<p>I'm trying to search for the string <code>/c</code> in the entire file, and when it's found I'd like to delete everything - including the <code>/c</code> itself - up until the next occurrence of <code>/</code> (but not the <code>/</code> itself). For the purposes I'm using this for, you can assume that:</p> <ol> <l...
[ { "answer_id": 6580, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": true, "text": "<p>I think the following command should do what you need:</p>\n\n<pre><code>:g:/c:s:/c[^/]*/:/:\n</code></pre>\n\n<p>Breaking it ...
2016/02/20
[ "https://vi.stackexchange.com/questions/6579", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6195/" ]
I'm trying to search for the string `/c` in the entire file, and when it's found I'd like to delete everything - including the `/c` itself - up until the next occurrence of `/` (but not the `/` itself). For the purposes I'm using this for, you can assume that: 1. not every line will have a `/c` in it, 2. but when ther...
I think the following command should do what you need: ``` :g:/c:s:/c[^/]*/:/: ``` Breaking it up: * `:g`: for every line that satisfies the condition + that it match `/c` (note, I'm using `:` as the regex delimiter for convenience, or I'd have to escape each `/` that I use) * run `s:/c[^/]*/:/:`, which: + looks ...
6,584
<p>Writing a vim plugin, I can use</p> <pre><code>function! s:InternalMethod() endfunction </code></pre> <p>for <code>InternalMethod</code> to be local to the plugin environment. It will not be directly available to users nor overwrite their methods.</p> <p>How do I perform a similar encapsulation on internal comman...
[ { "answer_id": 6586, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 3, "selected": true, "text": "<p>Vim's help about defining a new command (<code>:com[mand][!] [{attr}...] {cmd} {rep}</code> at <code>:h E174</code>) sta...
2016/02/20
[ "https://vi.stackexchange.com/questions/6584", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2978/" ]
Writing a vim plugin, I can use ``` function! s:InternalMethod() endfunction ``` for `InternalMethod` to be local to the plugin environment. It will not be directly available to users nor overwrite their methods. How do I perform a similar encapsulation on internal commands? ``` command! -nargs=1 InternalCommand <...
Vim's help about defining a new command (`:com[mand][!] [{attr}...] {cmd} {rep}` at `:h E174`) states: > > Define a ***user*** command. The name of the command is > {cmd} and its replacement text is {rep}. The command's > attributes (see below) are {attr}. If the command > already exists, an error is reported, unl...
6,589
<p>Would like to perform a search and replace in a file with 12000 lines. </p> <p>Specifically, if an occurrence of <code>^ SetFontSize 28</code> exists after a <code>^Hide</code> block and before the next <code>^Hide</code> or <code>^Show</code>, change <code>28</code> to <code>18</code>. </p> <p>Here's a snippet...
[ { "answer_id": 7770, "author": "jecxjo", "author_id": 895, "author_profile": "https://vi.stackexchange.com/users/895", "pm_score": 2, "selected": false, "text": "<p>One way to solve this would be to use <code>:global</code> that generates a range output.</p>\n\n<p>Typical use of the <cod...
2016/02/20
[ "https://vi.stackexchange.com/questions/6589", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6520/" ]
Would like to perform a search and replace in a file with 12000 lines. Specifically, if an occurrence of `^ SetFontSize 28` exists after a `^Hide` block and before the next `^Hide` or `^Show`, change `28` to `18`. Here's a snippet from the original file. ``` Hide # Gear - Endgame ItemLevel >= 77 Rarity = ...
It looks like your *nasty* regex was not nasty enough... :-) Search Section -------------- The search would have to be changed to this: ``` ^Hide\(\(\(Show\|Hide\)\@!\_.\)*\)SetFontSize 28 ``` This includes quite a few uncommon things and so many parenthesis... Let's see what we have in there: ### The Caret (`^`)...
6,596
<p>Writing unit tests in RSpec, I frequently change something like this,</p> <pre><code>it 'eats pizza' do pizza = build(:pizza) expect(subject.eats?(pizza)).to be_true end </code></pre> <p>to this,</p> <pre><code>let(:pizza) { build(:pizza) } it 'eats pizza' do expect(subject.eats?(pizza)).to be_true end </c...
[ { "answer_id": 6600, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 3, "selected": true, "text": "<p>To make your first command repeatable with dot, you could try the following code:</p>\n\n<pre><code>function! s:RSpecLet(...
2016/02/21
[ "https://vi.stackexchange.com/questions/6596", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1855/" ]
Writing unit tests in RSpec, I frequently change something like this, ``` it 'eats pizza' do pizza = build(:pizza) expect(subject.eats?(pizza)).to be_true end ``` to this, ``` let(:pizza) { build(:pizza) } it 'eats pizza' do expect(subject.eats?(pizza)).to be_true end ``` I want to automate part of this to...
To make your first command repeatable with dot, you could try the following code: ``` function! s:RSpecLet(bang) if a:bang ==# '!' execute "normal! mzIlet!(:\eea)\ef=r{A }\e`z" call repeat#set("\<Plug>RSpecBangLet") else execute "normal! mzIlet(:\eea)\ef=r{A }\e`z" call repeat#s...
6,598
<p>I have realized that the quickfix window isn't opening automatically when it's supposed to. I have tested this on both Gvim and vim 7.4 on Windows 10 Version 10.0.10586 Build 10586. I have a few plugins installed but I want to know how I might debug this first before I strip my vim configuration down to a minimum ...
[ { "answer_id": 6609, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 3, "selected": true, "text": "<p>In <a href=\"https://github.com/LucHermitte/vim-build-tools-wrapper\" rel=\"nofollow\">BuildToolWrappers</a>, I have e...
2016/02/21
[ "https://vi.stackexchange.com/questions/6598", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2062/" ]
I have realized that the quickfix window isn't opening automatically when it's supposed to. I have tested this on both Gvim and vim 7.4 on Windows 10 Version 10.0.10586 Build 10586. I have a few plugins installed but I want to know how I might debug this first before I strip my vim configuration down to a minimum worki...
In [BuildToolWrappers](https://github.com/LucHermitte/vim-build-tools-wrapper), I have encapsulated `:make` + `:cwindow` behind another `:Make` command. (the command does many more things, but this is the part you are looking for)
6,604
<p>This is a Python 2.7 question. I have a custom python 2.7, that I have compiled and have been using successfully across my system. My custom python has the YAML modules installed as well.</p> <p>The system wide Python 2.7 is in it's usual path on OSX: <code>/System/Library/Frameworks/Python.framework/Versions/2.7/<...
[ { "answer_id": 6756, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 2, "selected": false, "text": "<p>Vim links against Python; it doesn't call an external Python binary.</p>\n\n<p>You can see this with <code>ldd</code...
2016/02/21
[ "https://vi.stackexchange.com/questions/6604", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5328/" ]
This is a Python 2.7 question. I have a custom python 2.7, that I have compiled and have been using successfully across my system. My custom python has the YAML modules installed as well. The system wide Python 2.7 is in it's usual path on OSX: `/System/Library/Frameworks/Python.framework/Versions/2.7/` ``` function!...
Here is the answer to this question, however, first things first: * I do not use macports or brew. * The ideal workflow for me would be to download the source code of any package, module, library or app and compile it myself. For those reasons listed above, `brew` was not an option for me. So here is the solution: `...
6,615
<p>E.g., in this snippet</p> <pre><code> if words[0] == "\"spellgood:" call remove(words, 0) for word in words execute "silent spellgood! " . word endfor endif </code></pre> <p>taken from "<a href="https://vi.stackexchange.com/questions/6479/the-first-and-last-5-lines-of-a-file-use-fo...
[ { "answer_id": 6646, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 4, "selected": true, "text": "<p>As described in <code>:help call</code>, <code>call</code> is for invoking a built-in or user-defined <em>function</em>. It...
2016/02/22
[ "https://vi.stackexchange.com/questions/6615", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5919/" ]
E.g., in this snippet ``` if words[0] == "\"spellgood:" call remove(words, 0) for word in words execute "silent spellgood! " . word endfor endif ``` taken from "[The first and last 5 lines of a file? Use for file specific spell ignore list?](https://vi.stackexchange.com/questions/64...
As described in `:help call`, `call` is for invoking a built-in or user-defined *function*. It's useful to use `call` if you're invoking a function without the intention of capturing the return value, because of how vim's scripting works. That is, if you have a function `foo` that returns an integer, you *must*: ``` c...
6,619
<p>I would like to create a global (configuration) variable that ideally would work as a comma separated list but that we could also append to it. The idea is to have the same behavior as when using <code>+=</code> when setting <code>&amp;runtimepath</code>.</p> <p>So, it would be possible to do something like:</p> <...
[ { "answer_id": 6623, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": true, "text": "<p>You could have your variable be a list and add values with <code>:let g:var += ['item']</code>. However, it won't be p...
2016/02/22
[ "https://vi.stackexchange.com/questions/6619", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/599/" ]
I would like to create a global (configuration) variable that ideally would work as a comma separated list but that we could also append to it. The idea is to have the same behavior as when using `+=` when setting `&runtimepath`. So, it would be possible to do something like: ``` let g:myvar+="newitem" ``` And the ...
You could have your variable be a list and add values with `:let g:var += ['item']`. However, it won't be possible to prevent the same item to be added several times. That's why I've come up with [`lh#list#push_if_new()`](https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/list.vim#L555) ``` function! l...
6,622
<p>In Mac OS, I am trying to write a function that will say the current paragraph without moving the cursor, but something doesn't seem to work. This is what I have so far:</p> <pre><code>function! SayIt() let l:line = line(".") let l:col = col(".") execute "normal V" execute "silent '&lt;,'&gt;w !say...
[ { "answer_id": 6623, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": true, "text": "<p>You could have your variable be a list and add values with <code>:let g:var += ['item']</code>. However, it won't be p...
2016/02/22
[ "https://vi.stackexchange.com/questions/6622", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1095/" ]
In Mac OS, I am trying to write a function that will say the current paragraph without moving the cursor, but something doesn't seem to work. This is what I have so far: ``` function! SayIt() let l:line = line(".") let l:col = col(".") execute "normal V" execute "silent '<,'>w !say" call cursor(l:l...
You could have your variable be a list and add values with `:let g:var += ['item']`. However, it won't be possible to prevent the same item to be added several times. That's why I've come up with [`lh#list#push_if_new()`](https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/list.vim#L555) ``` function! l...
6,633
<p>I'm using airline with its default theme (relying from my theme gruvbox).</p> <p>I use <code>:AirlineTheme base16</code> while I have already opened my vim to change my airline theme to base16.</p> <p>But I want to change the default airline theme permanently, when I set </p> <pre><code>AirlineTheme base16 call A...
[ { "answer_id": 6634, "author": "fruglemonkey", "author_id": 4932, "author_profile": "https://vi.stackexchange.com/users/4932", "pm_score": 5, "selected": true, "text": "<p>Put the following in your .vimrc:</p>\n\n<pre><code>let g:airline_theme='base16'\n</code></pre>\n\n<p>You'll also ne...
2016/02/23
[ "https://vi.stackexchange.com/questions/6633", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6071/" ]
I'm using airline with its default theme (relying from my theme gruvbox). I use `:AirlineTheme base16` while I have already opened my vim to change my airline theme to base16. But I want to change the default airline theme permanently, when I set ``` AirlineTheme base16 call AirlineTheme base16 set AirlineTheme bas...
Put the following in your .vimrc: ``` let g:airline_theme='base16' ``` You'll also need to install the [vim-airline/vim-airline-themes](https://github.com/vim-airline/vim-airline-themes) plugin.
6,651
<p>I have this</p> <pre><code>subject { } it 'delete user' do expect(BlaBla).to eq '' MyModel.my_method end </code></pre> <p>And I want this</p> <pre><code>subject { MyModel.my_method } it 'delete user' do expect(BlaBla).to eq '' end </code></pre> <p><strong>1. First try</strong></p> <p>If I do <code>dd</c...
[ { "answer_id": 6652, "author": "Philipp Moers", "author_id": 6495, "author_profile": "https://vi.stackexchange.com/users/6495", "pm_score": 3, "selected": false, "text": "<p>You can delete the content of a line (without the line break) with <code>^d$</code>. You can delete to any registe...
2016/02/24
[ "https://vi.stackexchange.com/questions/6651", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3357/" ]
I have this ``` subject { } it 'delete user' do expect(BlaBla).to eq '' MyModel.my_method end ``` And I want this ``` subject { MyModel.my_method } it 'delete user' do expect(BlaBla).to eq '' end ``` **1. First try** If I do `dd` and then past it inside my bracket with `i<CTRL>r""` I will get something l...
If your problem is to repeat the operation in an efficient way you could use a macro: First put `{` in your search register with `/{` Then record your macro: `qq^DNp``ddq` * `qq` record the macro in the q register * `ma` put a mark on the line you'll delete * `^` got to the first word of the line (ie. `MyModel`) * `...
6,658
<p>I am trying to use <a href="http://www.vim.org/scripts/script.php?script_id=1397" rel="noreferrer">this plugin</a></p> <p>I have created a copy of <code>xml.vim</code> and named it <code>html.vim</code>.</p> <p>The problem is that the system ftplugin <code>C:\Program Files (x86)\Vim\vim74\ftplugin\html.vim</code> ...
[ { "answer_id": 6659, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 3, "selected": false, "text": "<h1>Overriding a plugin manually</h1>\n\n<p>Unless you intend to change all of the settings set by Vim's existing html ftplugin,...
2016/02/24
[ "https://vi.stackexchange.com/questions/6658", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6559/" ]
I am trying to use [this plugin](http://www.vim.org/scripts/script.php?script_id=1397) I have created a copy of `xml.vim` and named it `html.vim`. The problem is that the system ftplugin `C:\Program Files (x86)\Vim\vim74\ftplugin\html.vim` is loaded before the new one. I have checked this with `:scriptnames`. Once ...
Overriding a plugin manually ============================ Unless you intend to change all of the settings set by Vim's existing html ftplugin, you want your plugin to be loaded before it. The setting of the `b:did_ftplugin` variable will then cause Vim's version to exit immediately. Placing the plugin in your `~/.vim...
6,665
<p>Can I tell vim to assume a filename ends in <code>.tex</code> if no extension is given? e.g. to open bird.tex if I say <code>:e bird</code> (unless there is a file bird with no extension).</p>
[ { "answer_id": 6671, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 1, "selected": false, "text": "<p>Maybe you could try the following custom command <code>:E</code> :</p>\n\n<pre><code>command! -nargs=1 -complete=file E\...
2016/02/24
[ "https://vi.stackexchange.com/questions/6665", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4505/" ]
Can I tell vim to assume a filename ends in `.tex` if no extension is given? e.g. to open bird.tex if I say `:e bird` (unless there is a file bird with no extension).
Adapting tricks I got from two of my previous questions, this should work: ``` function! EditTex(name) if a:name !~ '\.[^/]*$' setlocal bufhidden=wipe exe 'e' fnameescape(a:name).'.tex' set bufhidden< endif endfunction autocmd BufNewFile * nested call EditTex(expand('<afile>')) ``` T...
6,672
<p>I have a large xhtml document that is broken into some 245 long paragraphs, each with a unique id in the form of "ud###"</p> <pre><code>&lt;p class="windowbg" id="ud000"&gt; &lt;!--- lots of content ---&gt; &lt;/p&gt; ... &lt;p class="windowbg" id="ud244"&gt; &lt;!--- and a bit more ---&gt; &lt;/p&gt; </code>...
[ { "answer_id": 6673, "author": "dash-tom-bang", "author_id": 6430, "author_profile": "https://vi.stackexchange.com/users/6430", "pm_score": 2, "selected": false, "text": "<p>It's because Vim is interpreting the numbers as octal. See <code>:h octal</code>. The suggestion there is to use <...
2016/02/25
[ "https://vi.stackexchange.com/questions/6672", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6573/" ]
I have a large xhtml document that is broken into some 245 long paragraphs, each with a unique id in the form of "ud###" ``` <p class="windowbg" id="ud000"> <!--- lots of content ---> </p> ... <p class="windowbg" id="ud244"> <!--- and a bit more ---> </p> ``` Since each 'paragraph' is several times larger than...
Octal numbers! Numbers starting with `0` are taken to be in octal. So, 00108 = 000810, and subtracting one, we get 000710 = 00078. See [`:h octal`](http://vimhelp.appspot.com/eval.txt.html#octal): ``` octal Conversion from a String to a Number is done by converting ...
6,685
<p>I am on a Unixware 7.1 box and can't seem to get VI to backspace properly. The current behavior is when you insert new characters and backspace over them, it will just shift the cursor to the left. However, if I open a fresh file and do not type any new characters, the behavior of backspace is to do nothing at all...
[ { "answer_id": 6686, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": false, "text": "<p>I had to put the following in my <code>.vimrc</code>:</p>\n\n<pre><code>map! &lt;C-h&gt; &lt;BS&gt;\n</code></pre>\n\n...
2016/02/25
[ "https://vi.stackexchange.com/questions/6685", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6587/" ]
I am on a Unixware 7.1 box and can't seem to get VI to backspace properly. The current behavior is when you insert new characters and backspace over them, it will just shift the cursor to the left. However, if I open a fresh file and do not type any new characters, the behavior of backspace is to do nothing at all. The...
I had to put the following in my `.vimrc`: ``` map! <C-h> <BS> ``` Note! Different systems handle backspace differently. To find out what your backspace is getting mapped to, start vi and go into insert mode. Press `Ctrl`+`V` and then `Backspace`. Most likely vim will output something like `^H`. This means that Vi i...
6,691
<p>When searching for a phrase in hard-wrapped text, one wants newlines to be treated as spaces. Can one have that happen? Saying <code>/the\_sphrase\_sI\_sseek</code> is a bit awkward.</p>
[ { "answer_id": 9379, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 2, "selected": false, "text": "<p>You can automatically replace a space with <code>\\_s</code> when searching with:</p>\n\n<pre><code>cnoremap &lt;exp...
2016/02/26
[ "https://vi.stackexchange.com/questions/6691", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4505/" ]
When searching for a phrase in hard-wrapped text, one wants newlines to be treated as spaces. Can one have that happen? Saying `/the\_sphrase\_sI\_sseek` is a bit awkward.
You can automatically replace a space with `\_s` when searching with: ``` cnoremap <expr> <Space> index(['/', '?'], getcmdtype()) > -1 ? '\_s' : ' ' ``` Because `cnoremap` is applied to all the commandline (and not just search), we need an expression mapping to check if we're searching or in another commandline mode...
6,693
<pre><code>This is a sample sentence. This is a second sample sentence. </code></pre> <p>Let's say I select 'is a' of the first sentence. Now I want to change all occurrences of what is selected (including the selection itself) to 'is not a'. How do I do that?</p>
[ { "answer_id": 6694, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>You could execute the following command: <code>:%s/is a/is not a</code>\n:</p>\n\n<ul>\n<li>Select and yank <code>is a</c...
2016/02/26
[ "https://vi.stackexchange.com/questions/6693", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6542/" ]
``` This is a sample sentence. This is a second sample sentence. ``` Let's say I select 'is a' of the first sentence. Now I want to change all occurrences of what is selected (including the selection itself) to 'is not a'. How do I do that?
You could execute the following command: `:%s/is a/is not a` : * Select and yank `is a` with your favorite method (visual selection and `y`, `y``2``w` with cursor on `is`, etc...) * Enter command mode with `:` * Begin to write your replacement command `%s/` * Insert the text to replace with `Ctrl+r` and `"`. (see **No...
6,698
<p>I am frequently editing markdown files, and when dealing with multi-line items in hierarchical lists, it would be great to have a rapid way to indent or un-indent a list item. For example, how can I most easily indent the longest multi-line list item in the following text?</p> <pre><code>- Some list item - Another...
[ { "answer_id": 6700, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 2, "selected": false, "text": "<p>Maybe you could try defining a custom object <code>li</code> for list item. This way you could operate on it with any op...
2016/02/27
[ "https://vi.stackexchange.com/questions/6698", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
I am frequently editing markdown files, and when dealing with multi-line items in hierarchical lists, it would be great to have a rapid way to indent or un-indent a list item. For example, how can I most easily indent the longest multi-line list item in the following text? ``` - Some list item - Another list item that...
Maybe you could try defining a custom object `li` for list item. This way you could operate on it with any operator including `>`. A way to do that is to define a visual mapping with `:xnoremap` which selects your object. Then you would define your list item object with `:onoremap li :normal vli<CR>`. The `:ono...
6,716
<p>I have made a snippet which I want to give different triggers, so instead of say <code>trigger</code> I also want to trigger it with <code>myothertrigger</code>:</p> <pre><code>snippet trigger "just an example" my text ... endsnippet </code></pre> <p>Is there an easy way to do this instead of copying the snippet?...
[ { "answer_id": 6722, "author": "cbaumhardt", "author_id": 3282, "author_profile": "https://vi.stackexchange.com/users/3282", "pm_score": 4, "selected": true, "text": "<p>Currently there is no way to do this in UltiSnips. There is an <a href=\"https://github.com/SirVer/ultisnips/issues/23...
2016/02/28
[ "https://vi.stackexchange.com/questions/6716", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5280/" ]
I have made a snippet which I want to give different triggers, so instead of say `trigger` I also want to trigger it with `myothertrigger`: ``` snippet trigger "just an example" my text ... endsnippet ``` Is there an easy way to do this instead of copying the snippet? **Edit:** To be clear, I am using [**UltiSnips...
Currently there is no way to do this in UltiSnips. There is an [open feature-request on Github](https://github.com/SirVer/ultisnips/issues/235) for it though. Personally, I would like an alias functionality for triggers as indicated [here](https://github.com/SirVer/ultisnips/issues/359) too. Let's hope SirVer (the mai...
6,730
<p>I am using <a href="https://github.com/vim-airline/vim-airline" rel="noreferrer">vim-airline</a> and it's really nice.</p> <p><a href="https://i.stack.imgur.com/jMB0Y.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jMB0Y.png" alt="vim statusbar screenshot"></a></p> <p>However, I get that second status ba...
[ { "answer_id": 6733, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>No, it's impossible to hide the command-line.</p>\n\n<p>-- EDIT --</p>\n\n<p>You can prevent Vim from echoing <code>\"filenam...
2016/03/01
[ "https://vi.stackexchange.com/questions/6730", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5650/" ]
I am using [vim-airline](https://github.com/vim-airline/vim-airline) and it's really nice. [![vim statusbar screenshot](https://i.stack.imgur.com/jMB0Y.png)](https://i.stack.imgur.com/jMB0Y.png) However, I get that second status bar below it which I want to hide. I have tried `set noshowmode` in my `.vimrc`, but tha...
No, it's impossible to hide the command-line. -- EDIT -- You can prevent Vim from echoing `"filename" XXXL, XXXC` when editing a file by prepending `silent` to `e`: ``` :silent e foo ```
6,731
<p>I'm struggling with learning vim regexps (I don't know any other regexp very well either), so the main problem is to define regexp that would match</p> <pre><code>some_function_call(simple_value, keyword=value) </code></pre> <p>keyword in this example.</p> <p>So it should match a word if it's inside parens and ha...
[ { "answer_id": 6732, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 3, "selected": false, "text": "<p>Here is where you can start from:</p>\n\n<pre><code>/([^,]\\+,\\s\\(\\w\\+\\)=.*)\n</code></pre>\n\n<p>Decomposing:</p>\n\...
2016/03/01
[ "https://vi.stackexchange.com/questions/6731", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6634/" ]
I'm struggling with learning vim regexps (I don't know any other regexp very well either), so the main problem is to define regexp that would match ``` some_function_call(simple_value, keyword=value) ``` keyword in this example. So it should match a word if it's inside parens and have equal sign after it. The next...
With these settings: ``` syn region FCall start='[[:alpha:]_]\i*\s*(' end=')' contains=FCall,FCallKeyword syn match FCallKeyword /\i*\ze\s*=[^=]/ contained hi FCallKeyword ctermfg=yellow ``` I get: [![enter image description here](https://i.stack.imgur.com/VPgjF.png)](https://i.stack.imgur.com/VPgjF.png) Here: 1....
6,738
<p>The <a href="http://vimdoc.sourceforge.net/htmldoc/usr_28.html#usr_28.txt">chapter 28 of User Manual</a> says the following about folding: </p> <blockquote> <p>Folding is used to show a range of lines in the buffer as a single line on the screen.</p> </blockquote> <p>And all the examples of folding that I've see...
[ { "answer_id": 6740, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 4, "selected": true, "text": "<p>You can hack around with some custom syntax and the use of the conceal:</p>\n\n<pre><code>syntax region FunctionArguments s...
2016/03/02
[ "https://vi.stackexchange.com/questions/6738", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
The [chapter 28 of User Manual](http://vimdoc.sourceforge.net/htmldoc/usr_28.html#usr_28.txt) says the following about folding: > > Folding is used to show a range of lines in the buffer as a single line on the screen. > > > And all the examples of folding that I've seen converts several lines to only one. **Wh...
You can hack around with some custom syntax and the use of the conceal: ``` syntax region FunctionArguments start=+(+hs=e+1 end=+)+he=e-1 conceal cchar=… set concealleval=1 ``` e.g. ``` function (a, b, c, d, e) function (…) ``` Careful though, with this basic example, all `()` will be concealed, so a little more ...
6,739
<p>I have a bad habit of using the shift key of the same side of the keyboard as the letter when tying uppercase letters. To type a <code>D</code>, for example, I press the left shift with my left pinky and <code>d</code> with my left index finger. It is better to use the right shift in combination with keys on the le...
[ { "answer_id": 6741, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 4, "selected": true, "text": "<p>From the <a href=\"http://vimhelp.appspot.com/vim_faq.txt.html#faq-20.4\">Vim FAQ 20.4. \"I am not able to create a mappin...
2016/03/02
[ "https://vi.stackexchange.com/questions/6739", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3316/" ]
I have a bad habit of using the shift key of the same side of the keyboard as the letter when tying uppercase letters. To type a `D`, for example, I press the left shift with my left pinky and `d` with my left index finger. It is better to use the right shift in combination with keys on the left hand side of the keyboa...
From the [Vim FAQ 20.4. "I am not able to create a mapping for the key. What is wrong?"](http://vimhelp.appspot.com/vim_faq.txt.html#faq-20.4): > > 1) First make sure, the key is passed correctly to Vim. To determine > if this is the case, put Vim in Insert mode and then hit Ctrl-V (or > Ctrl-Q if your Ctrl-V is re...
6,746
<p>Often when coding I have this window layout - which is mapped to the flow of the program I am editing. </p> <p>Tab1</p> <pre><code>+------------+--------------+ | | | | | B | | | | | | | | A +--------------+ | ...
[ { "answer_id": 6747, "author": "the_velour_fog", "author_id": 4603, "author_profile": "https://vi.stackexchange.com/users/4603", "pm_score": 3, "selected": false, "text": "<p>After some research I found a solution.<br>\nIf you are focused on the buffer/window:</p>\n\n<pre><code>:tabe %\n...
2016/03/02
[ "https://vi.stackexchange.com/questions/6746", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
Often when coding I have this window layout - which is mapped to the flow of the program I am editing. Tab1 ``` +------------+--------------+ | | | | | B | | | | | | | | A +--------------+ | | ...
`:tab split` will create a new tab displaying the current buffer, since `:tab` modifies any command that would normally create a split to instead create a tab page. If you want to override `<C-w>T` to do that instead of its default behavior, you can remap it. ``` nnoremap <silent> <C-w>T :tab split<CR> ``` --- You...
6,749
<p>My cursor is in the middle of a paragraph when I decide suddenly I need to copy that paragraph:</p> <p><img src="https://imgur.com/U29vyV7.png" alt="start"></p> <p>So I type <code>vip</code> to select the paragraph visually:</p> <p><img src="https://imgur.com/O3jmXWG.png" alt="selected"></p> <p>Now I hit <code>c...
[ { "answer_id": 6750, "author": "fruglemonkey", "author_id": 4932, "author_profile": "https://vi.stackexchange.com/users/4932", "pm_score": 3, "selected": false, "text": "<p>The <a href=\"https://github.com/svermeulen/vim-easyclip\" rel=\"noreferrer\">vim-easyclip plugin</a> has a setting...
2016/03/03
[ "https://vi.stackexchange.com/questions/6749", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5373/" ]
My cursor is in the middle of a paragraph when I decide suddenly I need to copy that paragraph: ![start](https://imgur.com/U29vyV7.png) So I type `vip` to select the paragraph visually: ![selected](https://imgur.com/O3jmXWG.png) Now I hit `cmd+C` to copy to clipboard (this may vary on your system, but shouldn't be ...
A possible solution is to use jumps: Before yanking or visually selecting you can set a new jump which you'll be able to access after your cursor has moved. To do so use `m````. Then after your cursor has moved because of the yanking use `ctrl``o` to jump back in the jump list. Also you can see the list of the availa...
6,762
<p>I am curious to know how I can find the next instance of a SpellLocal mistake (either by a motion key or via a search command) in vim.</p>
[ { "answer_id": 6763, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 1, "selected": false, "text": "<p>For navigating along the different spell mistakes, you can use the <a href=\"http://vimdoc.sourceforge.net/htmldoc/spell.h...
2016/03/04
[ "https://vi.stackexchange.com/questions/6762", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6673/" ]
I am curious to know how I can find the next instance of a SpellLocal mistake (either by a motion key or via a search command) in vim.
What you can do is modify the `]s` and `[s` motions to skip over `SpellBad` highlighted words. This is actually not very hard. With the [`spellbadword()`](http://vimhelp.appspot.com/eval.txt.html#spellbadword%28%29) function we can get information about the spell status of the current word: Example outputs of `:echo s...
6,768
<p>I often run into a situation where I have a file with a lot of mixed case. For example,</p> <pre><code>CamelCase and camelCase </code></pre> <p>I'm looking for a Vim regular expression replacement to produce,</p> <pre><code>AnotherCase and anotherCase </code></pre> <p>Right now I do this in two steps after visua...
[ { "answer_id": 6769, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<p>I would suggest using <code>:Subvert</code> via Tim Pope's <a href=\"https://github.com/tpope/vim-abolish\">Abolish.v...
2016/03/04
[ "https://vi.stackexchange.com/questions/6768", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6674/" ]
I often run into a situation where I have a file with a lot of mixed case. For example, ``` CamelCase and camelCase ``` I'm looking for a Vim regular expression replacement to produce, ``` AnotherCase and anotherCase ``` Right now I do this in two steps after visually selecting the lines, ``` :s/CamelCase/Anothe...
I would suggest using `:Subvert` via Tim Pope's [Abolish.vim](https://github.com/tpope/vim-abolish) ``` :%S/camelCase/anotherCase/g ``` [Vimcasts](http://vimcasts.org/) episode: [Supercharged substitution with :Subvert](http://vimcasts.org/episodes/supercharged-substitution-with-subvert/)
6,773
<h1>Problem summary</h1> <p>I use <code>vim</code> to edit emails that I send with <code>mutt</code>. I also use <code>format=flowed</code>, which "reflows" text. That is, lines are limited to a fixed number of characters, and a "soft wrap" is applied, as indicated by the presence of a trailing space.</p> <p>In <code...
[ { "answer_id": 6774, "author": "Alok Singh", "author_id": 6682, "author_profile": "https://vi.stackexchange.com/users/6682", "pm_score": 2, "selected": false, "text": "<p><code>setlocal formatoptions=jawtcqln</code> worked for me. I'd put it in <code>~/.vim/ftplugin/mail.vim</code>.</p>\...
2016/03/05
[ "https://vi.stackexchange.com/questions/6773", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1278/" ]
Problem summary =============== I use `vim` to edit emails that I send with `mutt`. I also use `format=flowed`, which "reflows" text. That is, lines are limited to a fixed number of characters, and a "soft wrap" is applied, as indicated by the presence of a trailing space. In `vim`, I have the following set: ``` set...
From [one of my previous answers](https://vi.stackexchange.com/a/6034/205), you can get this to work if: 1. You have `nb:>` in your `comments` setting. 2. And you have `q` in your `formatoptions` setting. So: ``` setlocal comments+=nb:> setlocal fo+=q ``` After doing these, I get the expected wrapping: ``` > Temp...
6,778
<p>I was looking at <a href="https://github.com/tpope/vim-sensible/blob/master/plugin/sensible.vim">Tim Pope's vim-sensible plugin</a> and I noticed this in the README...</p> <blockquote> <p>See the source for the authoritative list of features. (Don't worry, it's mostly <code>:set</code> calls.)</p> </blockquote> ...
[ { "answer_id": 6779, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 3, "selected": false, "text": "<p>There is no difference. If vim sees a <code>:</code> before a command in your vimrc <em>(or any vimscript file)</em...
2016/03/05
[ "https://vi.stackexchange.com/questions/6778", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6689/" ]
I was looking at [Tim Pope's vim-sensible plugin](https://github.com/tpope/vim-sensible/blob/master/plugin/sensible.vim) and I noticed this in the README... > > See the source for the authoritative list of features. (Don't worry, it's mostly `:set` calls.) > > > When I looked at the source, the `:set` calls are l...
A "script" does nothing more than run a sequence of ex commands. An "ex command" is what you type when you use `:` in Vim. For example `:wq`, `:set wrap`, `:e file`, etc. are all ex commands. The `:` is not part of the command; it is merely a keystroke to start the command-line mode; you don't always need to include t...
6,785
<p>My vim was installed on debian8 with the apt-get command.</p> <pre><code>apt-get install vim $ find / -name 'autoload' /usr/share/vim/vim74/autoload $ find / -name '.vim' </code></pre> <p>The above command can find nothing.</p> <pre><code>$ ls /etc/vim vimrc vimrc.tiny </code></pre> <p>Is my vim installed o...
[ { "answer_id": 6787, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>You are not supposed to do anything with the default runtime so where Vim was installed doesn't matter.</p>\n\n<p>Whatever c...
2016/03/06
[ "https://vi.stackexchange.com/questions/6785", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5181/" ]
My vim was installed on debian8 with the apt-get command. ``` apt-get install vim $ find / -name 'autoload' /usr/share/vim/vim74/autoload $ find / -name '.vim' ``` The above command can find nothing. ``` $ ls /etc/vim vimrc vimrc.tiny ``` Is my vim installed on /usr/share/vim properly?
> > Where is my vim installed? > > > If you installed through `apt` the following sequence should get you to the Vim installation. From inside Vim, ``` :echo $VIMRUNTIME /usr/share/vim/vim74 ``` You could look in here and you would discover the Vim files, but if you wanted a more programmatic, portable approac...
6,792
<p>Is there a syntax to cast from one character type for another? For example can you cast from a char to an int?</p> <p>I tried:</p> <pre><code>let my_var = (int)some_char </code></pre> <p>It is not valid code.</p>
[ { "answer_id": 6794, "author": "still_dreaming_1", "author_id": 1410, "author_profile": "https://vi.stackexchange.com/users/1410", "pm_score": 3, "selected": true, "text": "<p>The answer is no. There is no general syntax to cast from one type to another. There are unique ways of converti...
2016/03/06
[ "https://vi.stackexchange.com/questions/6792", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1410/" ]
Is there a syntax to cast from one character type for another? For example can you cast from a char to an int? I tried: ``` let my_var = (int)some_char ``` It is not valid code.
The answer is no. There is no general syntax to cast from one type to another. There are unique ways of converting to different types, but no universal casting syntax.
6,795
<p>I'm trying to make it so I can write a buffer to disk with <strong>one</strong> keystroke.</p> <p><strong>(Side note:</strong> ideally, I'd like this to work in all modes, but for the moment as a start I'm just trying to get it to work in normal mode.<strong>)</strong></p> <p>On the Vim wiki it says...</p> <block...
[ { "answer_id": 7269, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 0, "selected": false, "text": "<p>Change it to <code>&lt;C-S-k&gt;</code>. It works fine for me. You can give some other key also, like <code>&lt;F10&gt...
2016/03/06
[ "https://vi.stackexchange.com/questions/6795", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6689/" ]
I'm trying to make it so I can write a buffer to disk with **one** keystroke. **(Side note:** ideally, I'd like this to work in all modes, but for the moment as a start I'm just trying to get it to work in normal mode.**)** On the Vim wiki it says... > > Vim supports representing control characters using symbolic n...
Your keyboard response can be different than you expect. For e.g. it can provide some special characters of your language. To check out what your system does by pressing any combination: `ctrl+v` in insert mode and then `option+k` or `alt+k` Use the output symbol in your vimrc mapping instead of `<M-k>` WARNING: th...
6,800
<p>I like to define some abbreviations like:</p> <pre><code>cabbr csf cscope find </code></pre> <p>I thought <code>cabbr</code> would just be interpreted in the <code>:</code> command line. However, when I entered the search mode <code>\</code>, I found that <code>\csf</code> would still be expanded to <code>\cscope ...
[ { "answer_id": 6801, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>What you can do is use an expression abbreviation. This will allow you to use any Vim expression on the right-hand si...
2016/03/07
[ "https://vi.stackexchange.com/questions/6800", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4754/" ]
I like to define some abbreviations like: ``` cabbr csf cscope find ``` I thought `cabbr` would just be interpreted in the `:` command line. However, when I entered the search mode `\`, I found that `\csf` would still be expanded to `\cscope find`, which definitely was not what I want. So how to deal with this si...
What you can do is use an expression abbreviation. This will allow you to use any Vim expression on the right-hand side, instead of just a static string. With [`getcmdtype()`](http://vimhelp.appspot.com/eval.txt.html#getcmdtype%28%29) we can check if we're doing a normal Ex command or something else. ``` cabbr <expr> ...
6,803
<p><a href="https://i.stack.imgur.com/7B5M4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7B5M4.png" alt="enter image description here"></a></p> <p>Is there any way to change the syntax highlighting in vimwiki in windows. I could not properly see the line enclosed between [[some word]]. The same w...
[ { "answer_id": 6810, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": false, "text": "<p>I think this is because Windows' cmd.exe has very limited support for colours; you can only use 16, and those 16 are...
2016/03/07
[ "https://vi.stackexchange.com/questions/6803", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6706/" ]
[![enter image description here](https://i.stack.imgur.com/7B5M4.png)](https://i.stack.imgur.com/7B5M4.png) Is there any way to change the syntax highlighting in vimwiki in windows. I could not properly see the line enclosed between [[some word]]. The same works well in Linux.
I think this is because Windows' cmd.exe has very limited support for colours; you can only use 16, and those 16 are different from what Unix terminals use (which mostly support at least 256 colours nowadays). The easiest solution is to just use Gvim. Windows is not designed to be used from the commandline, and doesn'...
6,804
<p>Is there any way to display messages in vim depending on the <code>filetype</code> being edited? It would be good if the messages pop after some specified time interval.</p> <p><strong>Use case</strong></p> <p>We tend to forget style guide while editing files. Auto reminding would be a great feature.</p> <p><stro...
[ { "answer_id": 6810, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": false, "text": "<p>I think this is because Windows' cmd.exe has very limited support for colours; you can only use 16, and those 16 are...
2016/03/07
[ "https://vi.stackexchange.com/questions/6804", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6074/" ]
Is there any way to display messages in vim depending on the `filetype` being edited? It would be good if the messages pop after some specified time interval. **Use case** We tend to forget style guide while editing files. Auto reminding would be a great feature. **Update 1** It seems that auto reminding is not pos...
I think this is because Windows' cmd.exe has very limited support for colours; you can only use 16, and those 16 are different from what Unix terminals use (which mostly support at least 256 colours nowadays). The easiest solution is to just use Gvim. Windows is not designed to be used from the commandline, and doesn'...
6,821
<p>I have mapped <code>[]</code> and <code>{}</code> on my German keyboard with:</p> <pre><code>nmap Ö { nmap Ä } nmap ö [ nmap ä ] </code></pre> <p>but if I try, for example, to delete inside <code>{}</code> with <code>di}</code> it won't delete. It also fails with <code>f</code> and <code>t</code> (for example, <co...
[ { "answer_id": 6810, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": false, "text": "<p>I think this is because Windows' cmd.exe has very limited support for colours; you can only use 16, and those 16 are...
2016/03/09
[ "https://vi.stackexchange.com/questions/6821", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6710/" ]
I have mapped `[]` and `{}` on my German keyboard with: ``` nmap Ö { nmap Ä } nmap ö [ nmap ä ] ``` but if I try, for example, to delete inside `{}` with `di}` it won't delete. It also fails with `f` and `t` (for example, `f}` and `t}`). Can someone tell me if there is an additional map command for such operations?
I think this is because Windows' cmd.exe has very limited support for colours; you can only use 16, and those 16 are different from what Unix terminals use (which mostly support at least 256 colours nowadays). The easiest solution is to just use Gvim. Windows is not designed to be used from the commandline, and doesn'...
6,827
<p>I configured my CursorLine to be lightyellow.</p> <p><a href="https://i.stack.imgur.com/Vfaz5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Vfaz5.png" alt="cursorline screenshot"></a></p> <p>I have a couple of issues here:</p> <ul> <li>First, lightyellow is marked as an error when it is a valid color....
[ { "answer_id": 6828, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<ol>\n<li><p>The default syntax script for vim doesn't have <code>lightyellow</code> listed for <code>vimHiCtermColor</code>. Yo...
2016/03/10
[ "https://vi.stackexchange.com/questions/6827", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6754/" ]
I configured my CursorLine to be lightyellow. [![cursorline screenshot](https://i.stack.imgur.com/Vfaz5.png)](https://i.stack.imgur.com/Vfaz5.png) I have a couple of issues here: * First, lightyellow is marked as an error when it is a valid color. How can I avoid this? * Second, when the cursor line is over an error...
1. The default syntax script for vim doesn't have `lightyellow` listed for `vimHiCtermColor`. You could patch it and submit your change to the vim\_dev mailing list. Or, better, ask them if that is intentional. 2. `Error` as a lower priority than `CursorLine` but you can force it with this simple hack: ``` hi Error c...
6,834
<p>I know that running <code>:map</code> commands without arguments should give me a list of user-defined mappings, but, for example, when I press Ctrl-W Ctrl-I something happens, yet I have no idea what function was just happened as built-in mappings don't appear in the <code>:map</code> commands.</p> <p>How do I fin...
[ { "answer_id": 6886, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": true, "text": "<p>You can't.</p>\n\n<p>Here's the C source code for what <code>&lt;C-w&gt;&lt;C-i&gt;</code> does:</p>\n\n<p><code>norm...
2016/03/10
[ "https://vi.stackexchange.com/questions/6834", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6761/" ]
I know that running `:map` commands without arguments should give me a list of user-defined mappings, but, for example, when I press Ctrl-W Ctrl-I something happens, yet I have no idea what function was just happened as built-in mappings don't appear in the `:map` commands. How do I find out what a key does?
You can't. Here's the C source code for what `<C-w><C-i>` does: `normal.c`: ``` /* * This table contains one entry for every Normal or Visual mode command. * The order doesn't matter, init_normal_cmds() will create a sorted index. * It is faster when all keys from zero to '~' are present. */ static const struct ...
6,844
<p>I am using <a href="https://github.com/equalsraf/neovim-qt" rel="nofollow">neovim-qt</a> but cannot figure out how to set the size of the window. I tried:</p> <pre><code>nvim-qt -h nvim-qt --help nvim-qt --width=80 nvim-qt --geom 80x120 </code></pre> <p>But nothing gave me any indication as to how to do it. The <...
[ { "answer_id": 6920, "author": "Sardathrion - against SE abuse", "author_id": 622, "author_profile": "https://vi.stackexchange.com/users/622", "pm_score": 3, "selected": true, "text": "<p>Oh look, <code>--geometry</code> is a <a href=\"http://doc.qt.io/qt-5/qguiapplication.html\" rel=\"n...
2016/03/11
[ "https://vi.stackexchange.com/questions/6844", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/622/" ]
I am using [neovim-qt](https://github.com/equalsraf/neovim-qt) but cannot figure out how to set the size of the window. I tried: ``` nvim-qt -h nvim-qt --help nvim-qt --width=80 nvim-qt --geom 80x120 ``` But nothing gave me any indication as to how to do it. The [wiki](https://github.com/equalsraf/neovim-qt/wiki) is...
Oh look, `--geometry` is a [QT GUI application's main settings](http://doc.qt.io/qt-5/qguiapplication.html) thus ``` nvim-qt --geometry 500x320 ``` will create a windows just big enough to have 24 lines of 80 characters.
6,858
<p>So I have downloaded <code>proton.vim</code> (a colorscheme) and placed it inside my <code>.vim/colors</code> folder.</p> <p>In .vimrc, right at the bottom I have</p> <pre><code>colorscheme proton </code></pre> <p>but when Vim loads, it is set to the default colorscheme. If I type</p> <pre><code>:colorscheme pro...
[ { "answer_id": 7271, "author": "SibiCoder", "author_id": 7161, "author_profile": "https://vi.stackexchange.com/users/7161", "pm_score": 1, "selected": false, "text": "<p>Check whether the color scheme's name is mentioned properly, for case sensitivity.\nAlso, check whether </p>\n\n<pre><...
2016/03/13
[ "https://vi.stackexchange.com/questions/6858", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6560/" ]
So I have downloaded `proton.vim` (a colorscheme) and placed it inside my `.vim/colors` folder. In .vimrc, right at the bottom I have ``` colorscheme proton ``` but when Vim loads, it is set to the default colorscheme. If I type ``` :colorscheme proton ``` after it has loaded, it works fine though. Anyone know w...
Try this to help troubleshoot the issue: 1. Check the location where you have downloaded the color proton.vim file. On Linux, the system default will be something like `/usr/share/vim/vim74/colors/` On MSWindows, the system default will be something like `C:\Program Files (x86)\Vim\vim74\colors\` You could also try...
6,859
<p>I have a file similar to this:</p> <pre> aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddddd </pre> <p>I woul...
[ { "answer_id": 6861, "author": "Mehdi Nellen", "author_id": 6793, "author_profile": "https://vi.stackexchange.com/users/6793", "pm_score": 4, "selected": true, "text": "<p>I got the macro working:</p>\n\n<pre><code>qqgg5j^V4j$xgg$p9jV4kd\n</code></pre>\n\n<ul>\n<li><code>qq</code> starts...
2016/03/13
[ "https://vi.stackexchange.com/questions/6859", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6793/" ]
I have a file similar to this: ``` aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddddd aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddddd ``` I would like to join th...
I got the macro working: ``` qqgg5j^V4j$xgg$p9jV4kd ``` * `qq` starts a macro called `q` * `gg` sets the startingpoint to the first line of the file * `5j` goes down 5 lines (the start of the block below it) * `^V4j$` goes into column selection mode and selects the first block * `x` cut the content of the selection ...
6,869
<p>I would like to create a dictionary variable for a vimL script. That dictionary will hold information related to a folder structure. However, I have a bit of hard time designing this variable and also I came across some difficulties while handling the information stored in that variable. Below is an example dictiona...
[ { "answer_id": 6861, "author": "Mehdi Nellen", "author_id": 6793, "author_profile": "https://vi.stackexchange.com/users/6793", "pm_score": 4, "selected": true, "text": "<p>I got the macro working:</p>\n\n<pre><code>qqgg5j^V4j$xgg$p9jV4kd\n</code></pre>\n\n<ul>\n<li><code>qq</code> starts...
2016/03/13
[ "https://vi.stackexchange.com/questions/6869", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5328/" ]
I would like to create a dictionary variable for a vimL script. That dictionary will hold information related to a folder structure. However, I have a bit of hard time designing this variable and also I came across some difficulties while handling the information stored in that variable. Below is an example dictionary ...
I got the macro working: ``` qqgg5j^V4j$xgg$p9jV4kd ``` * `qq` starts a macro called `q` * `gg` sets the startingpoint to the first line of the file * `5j` goes down 5 lines (the start of the block below it) * `^V4j$` goes into column selection mode and selects the first block * `x` cut the content of the selection ...
6,887
<p>I found out about printing using the <code>:hardcopy</code> command, and on my Mac it opens up the output in a PDF named "0.pdf", then the next printing from that file opens "1.pdf", etc.</p> <p>I can save these files, of course, but I'm wondering: Where are these files stored on disk? Is there a setting which con...
[ { "answer_id": 6861, "author": "Mehdi Nellen", "author_id": 6793, "author_profile": "https://vi.stackexchange.com/users/6793", "pm_score": 4, "selected": true, "text": "<p>I got the macro working:</p>\n\n<pre><code>qqgg5j^V4j$xgg$p9jV4kd\n</code></pre>\n\n<ul>\n<li><code>qq</code> starts...
2016/03/15
[ "https://vi.stackexchange.com/questions/6887", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
I found out about printing using the `:hardcopy` command, and on my Mac it opens up the output in a PDF named "0.pdf", then the next printing from that file opens "1.pdf", etc. I can save these files, of course, but I'm wondering: Where are these files stored on disk? Is there a setting which controls it somewhere? I...
I got the macro working: ``` qqgg5j^V4j$xgg$p9jV4kd ``` * `qq` starts a macro called `q` * `gg` sets the startingpoint to the first line of the file * `5j` goes down 5 lines (the start of the block below it) * `^V4j$` goes into column selection mode and selects the first block * `x` cut the content of the selection ...
6,900
<p>I have this map in my .vimrc:</p> <pre><code>inoremap &lt;C-space&gt; &lt;C-o&gt;l </code></pre> <p>So that, eg, if I'm in insert mode:</p> <p><a href="https://i.stack.imgur.com/PHt4e.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PHt4e.png" alt="enter image description here"></a></p> <p>I can just ty...
[ { "answer_id": 8838, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>If I understand correctly what you want, you can simply set <code>:set virtualedit=onemore</code> and your mappin...
2016/03/17
[ "https://vi.stackexchange.com/questions/6900", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5373/" ]
I have this map in my .vimrc: ``` inoremap <C-space> <C-o>l ``` So that, eg, if I'm in insert mode: [![enter image description here](https://i.stack.imgur.com/PHt4e.png)](https://i.stack.imgur.com/PHt4e.png) I can just type `<C-space>` to move out of parens: [![enter image description here](https://i.stack.imgur....
Another option is to simply change your mapping to: ``` inoremap <C-space> <C-o><Space> ``` `<Space>` moves forward one character even when at end of line.
6,901
<p>I'm big on <a href="https://unix.stackexchange.com/a/269076/135943">scripted file edits using POSIX <code>ex</code></a> rather than <code>sed -i</code> and co. The big trick of course is how to ensure <code>ex</code> doesn't hang waiting for input if an error is encountered.</p> <p>I just <a href="https://unix.sta...
[ { "answer_id": 8838, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>If I understand correctly what you want, you can simply set <code>:set virtualedit=onemore</code> and your mappin...
2016/03/17
[ "https://vi.stackexchange.com/questions/6901", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
I'm big on [scripted file edits using POSIX `ex`](https://unix.stackexchange.com/a/269076/135943) rather than `sed -i` and co. The big trick of course is how to ensure `ex` doesn't hang waiting for input if an error is encountered. I just [wrote a comment](https://unix.stackexchange.com/questions/25057/how-to-perform-...
Another option is to simply change your mapping to: ``` inoremap <C-space> <C-o><Space> ``` `<Space>` moves forward one character even when at end of line.
6,906
<p>According to the <a href="http://vim.wikia.com/wiki/Syntax_folding_of_Vim_scripts" rel="noreferrer">WIKI</a>, scripts can be folded based on syntax. Does anyone have a solution to fold Python docstrings?</p> <p>Basically, all I need is to fold <code>""" text between triple quotation marks """</code>, like this:</p>...
[ { "answer_id": 6968, "author": "Dan Bradbury", "author_id": 2189, "author_profile": "https://vi.stackexchange.com/users/2189", "pm_score": 3, "selected": true, "text": "<p>There are a few funky factors at play that we should consider when playing with folds (they are complicated and not ...
2016/03/17
[ "https://vi.stackexchange.com/questions/6906", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
According to the [WIKI](http://vim.wikia.com/wiki/Syntax_folding_of_Vim_scripts), scripts can be folded based on syntax. Does anyone have a solution to fold Python docstrings? Basically, all I need is to fold `""" text between triple quotation marks """`, like this: [![enter image description here](https://i.stack.im...
There are a few funky factors at play that we should consider when playing with folds (they are complicated and not easy to understand without digging into the docs..) * setting `foldmethod` to `syntax` was my issue when I was fighting fold but lets take a look at the docs for more info.. > > SYNTAX *fold-syntax* > ...
6,907
<p>First of all I want to say that I know and use <a href="https://github.com/Raimondi/delimitMate" rel="nofollow">delimitmate</a> and <a href="https://github.com/tpope/vim-surround" rel="nofollow">surround-vim</a>.</p> <p>And while they work pretty well, there is room for improvement. I'll explain what I mean.</p> <...
[ { "answer_id": 6909, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p><code>viW(</code> with lh-brackets, or <code>vf(%(</code> if you want something more robust... Something similar is c...
2016/03/17
[ "https://vi.stackexchange.com/questions/6907", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6634/" ]
First of all I want to say that I know and use [delimitmate](https://github.com/Raimondi/delimitMate) and [surround-vim](https://github.com/tpope/vim-surround). And while they work pretty well, there is room for improvement. I'll explain what I mean. Suppose I'm writing the code ``` foo = bar() # some comment ``` ...
You can use surround's `ys` operator with the `iW` motion. Using the `f` surrounding prompts for a function name. ``` ysiWfbaz<cr> ``` For more help see: ``` :h surround-mappings :h iW :h text-objects ```
6,908
<p>I'm writing <a href="https://cucumber.io/docs/reference#scenario-outline" rel="nofollow">cucumber</a> example tables, which are formatted like this:</p> <pre><code>| title | title | | data | data | | data | data | </code></pre> <p>How can I replace one of the data or title cells with a word of differi...
[ { "answer_id": 6912, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 2, "selected": false, "text": "<p>If you were using Vim them you could use some alignment plugin, as mentioned on the question comments. Or you could use <...
2016/03/17
[ "https://vi.stackexchange.com/questions/6908", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1033/" ]
I'm writing [cucumber](https://cucumber.io/docs/reference#scenario-outline) example tables, which are formatted like this: ``` | title | title | | data | data | | data | data | ``` How can I replace one of the data or title cells with a word of differing length without disturbing the layout?
If you were using Vim them you could use some alignment plugin, as mentioned on the question comments. Or you could use [the vimwiki plugin](https://github.com/vimwiki/vimwiki), which provides several helpers to use tables. As you are using VsVim, you could try to isolate the table formatting function in [vimwiki/auto...
6,916
<p>I found that I frequently needed a command in <code>INSERT</code> mode to open a line above the cursor (what <kbd>O</kbd> does in <code>NORMAL</code> mode)</p> <p>I put this in my <code>.vimrc</code></p> <pre><code>inoremap ao &lt;esc&gt;O </code></pre> <p>It works well. I chose the key sequence <code>ao</code> b...
[ { "answer_id": 6917, "author": "saginaw", "author_id": 4939, "author_profile": "https://vi.stackexchange.com/users/4939", "pm_score": 4, "selected": true, "text": "<p><code>:help map-which-keys</code> gives some information on the subject:</p>\n\n<pre><code>If you are going to map someth...
2016/03/18
[ "https://vi.stackexchange.com/questions/6916", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5484/" ]
I found that I frequently needed a command in `INSERT` mode to open a line above the cursor (what `O` does in `NORMAL` mode) I put this in my `.vimrc` ``` inoremap ao <esc>O ``` It works well. I chose the key sequence `ao` because I rarely encounter `a` and `o` together (also I remember it as "**a**bove **o**pen")....
`:help map-which-keys` gives some information on the subject: ``` If you are going to map something, you will need to choose which key(s) to use for the {lhs}. You will have to avoid keys that are used for Vim commands, otherwise you would not be able to use those commands anymore. Here are a few suggestions: - Func...
6,923
<p>I'm trying to save the current relative path of my file and line number into my clipboard. I would like to have <code>application/models/my_model.rb:34</code> </p> <p>But I don't understand how <a href="http://vimdoc.sourceforge.net/htmldoc/eval.html#expand()" rel="nofollow">expand</a> works. </p> <p>They have thi...
[ { "answer_id": 6924, "author": "Mio", "author_id": 3357, "author_profile": "https://vi.stackexchange.com/users/3357", "pm_score": 2, "selected": false, "text": "<p>One way to do it to combine expand :</p>\n\n<pre><code>:echom expand(\"%:h\") . '/' . expand(\"%:t\") . ':' . line(\".\") ...
2016/03/18
[ "https://vi.stackexchange.com/questions/6923", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3357/" ]
I'm trying to save the current relative path of my file and line number into my clipboard. I would like to have `application/models/my_model.rb:34` But I don't understand how [expand](http://vimdoc.sourceforge.net/htmldoc/eval.html#expand()) works. They have this example : ``` Example: :let &tags = exp...
You should just use `expand('%')`. If I do: ``` cd ~/..; vim ~/.vim/vimrc ``` Then, in Vim: ``` :echo join([expand('%'), line(".")], ':') muru/.vim/vimrc:1 ``` Or with `cd ~/Documents; vim ~/.vim/vimrc`: ``` :echo join([expand('%'), line(".")], ':') join([expand('%:h'), expand('%:t')], '/') /home/muru/.vim/vi...
6,938
<p>I see how to copy text in vim using visual mode, arrow keys, <kbd>y</kbd> to yank, and <kbd>p</kbd> to paste. I also see how to find a given starting string using back slash.</p> <p>However, I'd appreciate knowing how to copy all the text from a given start phrase (such as <code>To list all available commands enter...
[ { "answer_id": 6940, "author": "QuantumFool", "author_id": 5923, "author_profile": "https://vi.stackexchange.com/users/5923", "pm_score": 1, "selected": false, "text": "<p>After some googling (mainly thanks to <a href=\"https://vi.stackexchange.com/questions/1915/how-do-i-delete-a-large-...
2016/03/19
[ "https://vi.stackexchange.com/questions/6938", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5923/" ]
I see how to copy text in vim using visual mode, arrow keys, `y` to yank, and `p` to paste. I also see how to find a given starting string using back slash. However, I'd appreciate knowing how to copy all the text from a given start phrase (such as `To list all available commands enter "/?"`) to a given stop phrase (s...
I think the idea of using marks is indeed a good approach. Here is a function to add to your `.vimrc` to ease the process: ``` function! SelectDelimitations(start, end) " Set start mark call search(a:start) normal! ma " Set end mark at the end of the match call search(a:end, "e") normal! mb ...
6,958
<p>I was searching for an answer to this, but haven't found anything yet, so if I missed something obvious, I apologize. I thought it would be a quick google search away, so maybe it's more complicated than I thought.</p> <p>I'd like to be able to conditionally load plugins based on the type of file I'm editing. For e...
[ { "answer_id": 6959, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>You can do this with Vim-Plug. See <a href=\"https://github.com/junegunn/vim-plug#example\" rel=\"noreferrer\">the README<...
2016/03/21
[ "https://vi.stackexchange.com/questions/6958", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6900/" ]
I was searching for an answer to this, but haven't found anything yet, so if I missed something obvious, I apologize. I thought it would be a quick google search away, so maybe it's more complicated than I thought. I'd like to be able to conditionally load plugins based on the type of file I'm editing. For example, wh...
You can do this with Vim-Plug. See [the README](https://github.com/junegunn/vim-plug#example): ``` " On-demand loading Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } Plug 'tpope/vim-fireplace', { 'for': 'clojure' } ``` I think you'll have to use `:set filetype whatever` instead of `set syntax whatever` to e...
6,975
<p>Is there any way to store the number of matches in a variable in a VIMScript function?</p> <p>For instance I'm using:</p> <pre><code>%s/,//gn </code></pre>
[ { "answer_id": 6984, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>I know that @romainl debugged the question as a XY problem in the comments but I guess it still could be useful to some p...
2016/03/22
[ "https://vi.stackexchange.com/questions/6975", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
Is there any way to store the number of matches in a variable in a VIMScript function? For instance I'm using: ``` %s/,//gn ```
There is another way that doesn't move the cursor nor requires `:exe`, but uses other tricks. Here I count by using a function that modifies and returns something (if `+=` was an expression like in C, it would have been simpler) ``` command! -nargs=1 -range Count call s:Count2(<f-args>, <line1>,<line2>) " Not using t...
6,976
<p>How does one move to the next match in Vimscript? The way you would when matching an expression and then hitting <code>n</code>?</p>
[ { "answer_id": 6984, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>I know that @romainl debugged the question as a XY problem in the comments but I guess it still could be useful to some p...
2016/03/22
[ "https://vi.stackexchange.com/questions/6976", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
How does one move to the next match in Vimscript? The way you would when matching an expression and then hitting `n`?
There is another way that doesn't move the cursor nor requires `:exe`, but uses other tricks. Here I count by using a function that modifies and returns something (if `+=` was an expression like in C, it would have been simpler) ``` command! -nargs=1 -range Count call s:Count2(<f-args>, <line1>,<line2>) " Not using t...
6,993
<p>I am considering attaching a macro to the space bar to insert a space.</p> <p>My question is whether this will change its normal mode behavior. For example, if I type <code>23&lt;space&gt;</code> will it execute the macro 23 times or do the normal thing (move forward 23 spaces)?</p> <p>I want to keep the old funct...
[ { "answer_id": 6994, "author": "Dan Bradbury", "author_id": 2189, "author_profile": "https://vi.stackexchange.com/users/2189", "pm_score": 0, "selected": false, "text": "<p>I'm under the impression that a macro on space would become an annoyance very quickly. (assuming a macro is externa...
2016/03/23
[ "https://vi.stackexchange.com/questions/6993", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6952/" ]
I am considering attaching a macro to the space bar to insert a space. My question is whether this will change its normal mode behavior. For example, if I type `23<space>` will it execute the macro 23 times or do the normal thing (move forward 23 spaces)? I want to keep the old functionality for repetitive actions be...
Using a function, you can split the functionality of a key map. In this case, the determining factor is if a count is given to the command or not, which is stored in `v:count`. ``` function! SpaceOrSpace(cnt) if a:cnt > 0 exec "normal " . a:cnt . "l" else normal i ^[ endif endfunction nnoremap <silent> ...
6,995
<p>I'm using vim-plug for managing plugins, primarily for its lazy-loading capabilities. This lets me do:</p> <pre><code>Plug 'Valloric/YouCompleteMe', { 'do': 'python2 ./install.py --clang-completer --gocode-completer --tern-completer', …} </code></pre> <p>I don't have YCM in all systems where I do have my <code>.vi...
[ { "answer_id": 7376, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": true, "text": "<p>As noted in the comments, you can use Vimscript within the vim-plug block, so I ended up checking for particular commands to c...
2016/03/23
[ "https://vi.stackexchange.com/questions/6995", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/205/" ]
I'm using vim-plug for managing plugins, primarily for its lazy-loading capabilities. This lets me do: ``` Plug 'Valloric/YouCompleteMe', { 'do': 'python2 ./install.py --clang-completer --gocode-completer --tern-completer', …} ``` I don't have YCM in all systems where I do have my `.vim` present and updated, and som...
As noted in the comments, you can use Vimscript within the vim-plug block, so I ended up checking for particular commands to control installation of plugins. For example, I rarely have cmake installed, I usually install it for YCM. So a `executable('cmake')` check is good enough for that. Now, my vim-plug block has one...
6,996
<p>I want to work with quickfix without ever having a split window.</p> <p>So I've set:</p> <pre><code>set switchbuf=newtab </code></pre> <p>as mentioned at <a href="https://stackoverflow.com/questions/6852763/vim-quickfix-list-launch-files-in-new-tab">https://stackoverflow.com/questions/6852763/vim-quickfix-list-la...
[ { "answer_id": 6997, "author": "Dan Bradbury", "author_id": 2189, "author_profile": "https://vi.stackexchange.com/users/2189", "pm_score": 3, "selected": false, "text": "<p>The <code>quickfix</code>/<code>location list</code> is an interesting beast. I'd recommend reading into <code>:hel...
2016/03/23
[ "https://vi.stackexchange.com/questions/6996", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2038/" ]
I want to work with quickfix without ever having a split window. So I've set: ``` set switchbuf=newtab ``` as mentioned at <https://stackoverflow.com/questions/6852763/vim-quickfix-list-launch-files-in-new-tab> Now: ``` tab copen ``` opens the quickfix window on a new tab. But if I hit enter on a quickfix item...
This workaround seems to work (mind the capitalized `T` in the end): ``` autocmd FileType qf nnoremap <buffer> <Enter> <C-W><Enter><C-W>T ``` It will create a mapping that is local to the `quickfix` buffer (it also works in `location lists`, since they have the same filetype, i.e. `qf`). This mapping will first open...
7,006
<p>Is there anything like </p> <pre><code>eval("is_recording()") </code></pre> <p>that I can call in my vimscript to find out if I am currently recording a macro? I would have thought this works:</p> <pre><code>eval("mode(1)") </code></pre> <p>but that just returns <code>"n"</code>.</p> <p>Not sure if it matters, ...
[ { "answer_id": 7007, "author": "Dan Bradbury", "author_id": 2189, "author_profile": "https://vi.stackexchange.com/users/2189", "pm_score": 2, "selected": false, "text": "<p>This is a pretty curious request since there is no \"mode\" for recording a macro. After digging through some docs ...
2016/03/23
[ "https://vi.stackexchange.com/questions/7006", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
Is there anything like ``` eval("is_recording()") ``` that I can call in my vimscript to find out if I am currently recording a macro? I would have thought this works: ``` eval("mode(1)") ``` but that just returns `"n"`. Not sure if it matters, but I am using neovim, so if it's exclusive to neovim, that is okay...
Firstly, I think that your problem is mainly a [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). You should give us more information about what you are trying to do in the end and I think we could find another solution. Now here is a workaround, it is probably not ideal and certainly...
7,011
<p>Is it possible to go to a class or function definition by search?</p> <p>E.g. in Sublime it is possible to search the file for class and function names, and the viewport will automatically jump to the current closest match.</p> <p>Right now if I want to find a specific function i use</p> <pre><code>/&lt;function ...
[ { "answer_id": 7012, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>You will have to use a program like ctags to generate a tag file. It is recommended to use <a href=\"http://ctags.sourcef...
2016/03/24
[ "https://vi.stackexchange.com/questions/7011", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6957/" ]
Is it possible to go to a class or function definition by search? E.g. in Sublime it is possible to search the file for class and function names, and the viewport will automatically jump to the current closest match. Right now if I want to find a specific function i use ``` /<function name>/ ``` and press `n` or `...
You don't necessarily have to install a plugin like ctags (although this would be reliable and allow many more great features, because you have semantic knowledge of your code, of course). Vim has a built in function to go to the definition by doing a clever search: With the cursor over a keyword, press `gd` or `gD`....
7,025
<p>If I'm using a range in a regex, how can I replace with the character that was matched? For example, lets say I want to find all occurrences of <code>a</code> or <code>b</code>, and replace them with <code>aa</code> or <code>bb</code>. Can I do this in a single regex? For example, something like this:</p> <pre><cod...
[ { "answer_id": 7026, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": true, "text": "<p>For using the entire matched text, just use <a href=\"http://vimhelp.appspot.com/change.txt.html#s%2F%5C%26\" rel=\"nofollow\"...
2016/03/24
[ "https://vi.stackexchange.com/questions/7025", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
If I'm using a range in a regex, how can I replace with the character that was matched? For example, lets say I want to find all occurrences of `a` or `b`, and replace them with `aa` or `bb`. Can I do this in a single regex? For example, something like this: ``` :%s/[a-b]/\1\1/g ``` Where `\1` means the first matchi...
For using the entire matched text, just use [`&`](http://vimhelp.appspot.com/change.txt.html#s%2F%5C%26): ``` magic nomagic action & \& replaced with the whole matched pattern s/\& \& & replaced with & ``` So: ``` %s/[a-b]/&&/g ``` For using the matched text in parts, ...
7,033
<p>I'm using Vim 7.4.</p> <p>I have a buffer open and I type <code>:vsplit</code>. Vim splits the screen and I see my buffer in both windows. That's great. Just what I want.</p> <p>And at this point <kbd>ctrl</kbd>+<kbd>W</kbd> <kbd>W</kbd> switches the focus from one window to the other, as documented.</p> <p><stro...
[ { "answer_id": 9284, "author": "serup", "author_id": 8869, "author_profile": "https://vi.stackexchange.com/users/8869", "pm_score": 0, "selected": false, "text": "<p>I could not reproduce this - the focus worked fine for me - only difference I see is that I have enabled mouse focus, perh...
2016/03/24
[ "https://vi.stackexchange.com/questions/7033", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6689/" ]
I'm using Vim 7.4. I have a buffer open and I type `:vsplit`. Vim splits the screen and I see my buffer in both windows. That's great. Just what I want. And at this point `ctrl`+`W` `W` switches the focus from one window to the other, as documented. **However,** if I open a Netrw browser in one of the windows like t...
Starting vim using ``` vim -u NONE ``` won't work because you need a vimrc file with ``` set nocp filetype plugin on ``` The two settings are needed because "netrw" is actually a plugin distributed with vim by default, but still a plugin. I would reccomend you to create an alternative vimrc to confirm that the i...
7,038
<p>If I use the color logging for maven, the file path is corrupted by the coloring syntax:</p> <pre><code>^[[1;31m[ERROR]^[[m /home/foo/bar/src/main/java/com/domain/bar/App.java </code></pre> <p>instead of</p> <pre><code>[ERROR] /home/foo/bar/src/main/java/com/domain/bar/App.java:[48,50] cannot find symbol </code><...
[ { "answer_id": 7045, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 2, "selected": false, "text": "<p>Vim does not support Ansi escape color codes. The <a href=\"http://www.vim.org/scripts/script.php?script_id=302\" re...
2016/03/25
[ "https://vi.stackexchange.com/questions/7038", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2510/" ]
If I use the color logging for maven, the file path is corrupted by the coloring syntax: ``` ^[[1;31m[ERROR]^[[m /home/foo/bar/src/main/java/com/domain/bar/App.java ``` instead of ``` [ERROR] /home/foo/bar/src/main/java/com/domain/bar/App.java:[48,50] cannot find symbol ``` How can I have a colored output and cor...
My solution to have color working into vim and console is to use <https://github.com/jcgay/maven-color> Then set the colored log pattern into `/opt/apache-maven-3.3.9/conf/logging/log4j2.xml` ``` <Console name="maven-color-true" target="SYSTEM_OUT"> <PatternLayout pattern="%highlight{[%p] %mavenMsg%n%rEx}{FATAL=red...
7,052
<p>Every time I need to create a list of strings in python or another language with similar list syntax (and they more or less the same everywhere) I have to do the following.</p> <pre><code># resulting expression a = ('word1', 'word2', 'word3') #cursor is between the parenthesis a = (|) </code></pre> <p>type <code>...
[ { "answer_id": 7053, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": true, "text": "<pre><code>a = ('word1', 'word2', 'word3')\n</code></pre>\n\n<p>Technically, that's a tuple. :)</p>\n\n<p>Now, for the <code>subs...
2016/03/26
[ "https://vi.stackexchange.com/questions/7052", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6634/" ]
Every time I need to create a list of strings in python or another language with similar list syntax (and they more or less the same everywhere) I have to do the following. ``` # resulting expression a = ('word1', 'word2', 'word3') #cursor is between the parenthesis a = (|) ``` type `'word1<ESC>a,` etc for each wor...
``` a = ('word1', 'word2', 'word3') ``` Technically, that's a tuple. :) Now, for the `substitute()` command, it depends on what the strings can contain. If they don't contain any whitespace, you can match non-whitespace characters with `\S`: ``` :s/(\zs.*\ze)/\=substitute(submatch(0), '\S\+', "'&',", 'g')/ ``` Th...
7,058
<p>I've just added this line to my <code>.vimrc</code> to be able to open chrome without leaving vim.</p> <pre><code>command GoogleChromeA execute "!google-chrome &gt; /dev/null 2&gt;&amp;1 &amp;" </code></pre> <p>It works fine however, when I use the command <code>source $MYVIMRC</code>, I get this error: </p> <pre...
[ { "answer_id": 7063, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p><code>command</code> will give an error if a command with that name already exists. Vim has no way of knowing that th...
2016/03/27
[ "https://vi.stackexchange.com/questions/7058", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5081/" ]
I've just added this line to my `.vimrc` to be able to open chrome without leaving vim. ``` command GoogleChromeA execute "!google-chrome > /dev/null 2>&1 &" ``` It works fine however, when I use the command `source $MYVIMRC`, I get this error: ``` E174: command already exists: add ! to replace it ``` How can I ...
`command` will give an error if a command with that name already exists. Vim has no way of knowing that the command in your vimrc is actually the same command; from Vim's viewpoint it's a "new" command. You have to use `command!` to override any existing commands. The same applies to functions; use `function!` to over...
7,074
<p>I used many macros assigned to registers, for instance I have this line in my <code>.vimrc</code>:</p> <pre><code>let @p='^[O&lt;/p&gt;^[0jj' </code></pre> <p>I just type <code>@p</code> and it closes the tag, very convenient.</p> <p><strong>PROBLEM</strong>: On my new keyboard <code>@</code> (at-mark) is too far...
[ { "answer_id": 7075, "author": "Nicolas Raoul", "author_id": 1083, "author_profile": "https://vi.stackexchange.com/users/1083", "pm_score": 2, "selected": false, "text": "<p>Add this to your <code>.vimrc</code>:</p>\n\n<pre><code>:noremap ; @\n:noremap @ ;\n</code></pre>\n\n<p>The first ...
2016/03/29
[ "https://vi.stackexchange.com/questions/7074", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1083/" ]
I used many macros assigned to registers, for instance I have this line in my `.vimrc`: ``` let @p='^[O</p>^[0jj' ``` I just type `@p` and it closes the tag, very convenient. **PROBLEM**: On my new keyboard `@` (at-mark) is too far away. **QUESTION**: Can I change it to another key? `;` would be convenient.
Add this to your `.vimrc`: ``` :noremap ; @ :noremap @ ; ``` The first line maps the `;` key to the register feature. The second line maps the `@` key to whatever feature was assigned to the `;` key, just in case you need it. It is optional. `noremap` creates a **no**n-**re**cursive **map**ping. *Thanks to Carpet...
7,083
<p><em>I would like to:</em></p> <ol> <li><p>First, save the current highlight state (nohlsearch? or hlsearch?).</p></li> <li><p>...the current cursor position and the current search pattern.</p></li> <li><p>Then search for the trailing spaces, highlighting those and also be able to move around them.</p></li> <li><p>O...
[ { "answer_id": 7075, "author": "Nicolas Raoul", "author_id": 1083, "author_profile": "https://vi.stackexchange.com/users/1083", "pm_score": 2, "selected": false, "text": "<p>Add this to your <code>.vimrc</code>:</p>\n\n<pre><code>:noremap ; @\n:noremap @ ;\n</code></pre>\n\n<p>The first ...
2016/03/29
[ "https://vi.stackexchange.com/questions/7083", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5328/" ]
*I would like to:* 1. First, save the current highlight state (nohlsearch? or hlsearch?). 2. ...the current cursor position and the current search pattern. 3. Then search for the trailing spaces, highlighting those and also be able to move around them. 4. Once done, turn OFF the trailing space highlighting and revert ...
Add this to your `.vimrc`: ``` :noremap ; @ :noremap @ ; ``` The first line maps the `;` key to the register feature. The second line maps the `@` key to whatever feature was assigned to the `;` key, just in case you need it. It is optional. `noremap` creates a **no**n-**re**cursive **map**ping. *Thanks to Carpet...
7,085
<p>Would you provide a key mapping for insert mode which could make letters between start of current word to current cursor uppercase?</p> <p>Example:<br></p> <ol> <li>For string <code>abcd efgh</code>, and now cursor is flickering at the end following <code>h</code>, then I could get <code>abcd EFGH</code>.<br></li>...
[ { "answer_id": 7086, "author": "Qiu Yangfan", "author_id": 6267, "author_profile": "https://vi.stackexchange.com/users/6267", "pm_score": 3, "selected": false, "text": "<p>Thanks to the hint of <code>gUb</code> from Carpetsmoker, I think out one solution as following:</p>\n\n<pre><code>i...
2016/03/30
[ "https://vi.stackexchange.com/questions/7085", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6267/" ]
Would you provide a key mapping for insert mode which could make letters between start of current word to current cursor uppercase? Example: 1. For string `abcd efgh`, and now cursor is flickering at the end following `h`, then I could get `abcd EFGH`. 2. For string `abcd efgh`, and now cursor is flickering on `g`,...
If you use `<Esc>…a`, the cursor will move to the character before the cursor after `<Esc>`. Use [`<c-\><c-o>`](http://vimhelp.appspot.com/insert.txt.html#i_CTRL-O): ``` CTRL-O execute one command, return to Insert mode i_CTRL-O CTRL-\ CTRL-O like CTRL-O but don't move the cursor i_CTRL-\_CTRL-O `...
7,094
<p>I have an ugly orange triangle appearing in the airline bar in my nvim regardless of the theme I use. Take a look at that : </p> <p><a href="https://i.stack.imgur.com/a655o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a655o.png" alt="Look at the right side on the airline bar"></a></p> <p>Shoc...
[ { "answer_id": 7086, "author": "Qiu Yangfan", "author_id": 6267, "author_profile": "https://vi.stackexchange.com/users/6267", "pm_score": 3, "selected": false, "text": "<p>Thanks to the hint of <code>gUb</code> from Carpetsmoker, I think out one solution as following:</p>\n\n<pre><code>i...
2016/03/30
[ "https://vi.stackexchange.com/questions/7094", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7005/" ]
I have an ugly orange triangle appearing in the airline bar in my nvim regardless of the theme I use. Take a look at that : [![Look at the right side on the airline bar](https://i.stack.imgur.com/a655o.png)](https://i.stack.imgur.com/a655o.png) Shocking, isn't it ? Now do you have an idea on how to correct this ?
If you use `<Esc>…a`, the cursor will move to the character before the cursor after `<Esc>`. Use [`<c-\><c-o>`](http://vimhelp.appspot.com/insert.txt.html#i_CTRL-O): ``` CTRL-O execute one command, return to Insert mode i_CTRL-O CTRL-\ CTRL-O like CTRL-O but don't move the cursor i_CTRL-\_CTRL-O `...
7,113
<p>Is there anyway I could make sure a file is locked so that I cant make any changes to it. Is there a command for locking / unlocking a file in vim. Some times i would like a file to be in readonly mode.</p>
[ { "answer_id": 7115, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 5, "selected": true, "text": "<p>You can set the file to read only and not modifiable</p>\n\n<pre><code>:set readonly\n:set nomodifiable\n</code></pre...
2016/03/31
[ "https://vi.stackexchange.com/questions/7113", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7053/" ]
Is there anyway I could make sure a file is locked so that I cant make any changes to it. Is there a command for locking / unlocking a file in vim. Some times i would like a file to be in readonly mode.
You can set the file to read only and not modifiable ``` :set readonly :set nomodifiable ``` For more help see: ``` :h 'readonly' :h 'modifiable' ```
7,116
<p>Since importing a package and <em>not</em> using it in Go is a compilation error, fixing the <code>import</code> manually can be a bit of a pain while debugging, so I'm currently using this to fix it up automatically before saving:</p> <pre><code>" Filter all lines through cmd, and silently undo it if there's an er...
[ { "answer_id": 7118, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 2, "selected": false, "text": "<p>For removing <code>:!goimports</code> from the history, use <code>systemlist</code>:</p>\n\n<pre><code>call setline(1, system...
2016/04/01
[ "https://vi.stackexchange.com/questions/7116", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/51/" ]
Since importing a package and *not* using it in Go is a compilation error, fixing the `import` manually can be a bit of a pain while debugging, so I'm currently using this to fix it up automatically before saving: ``` " Filter all lines through cmd, and silently undo it if there's an error fun! s:write_cmd(cmd) le...
For removing `:!goimports` from the history, use `systemlist`: ``` call setline(1, systemlist('goimports', getline(0, line('$')))) ``` The problem here is that if there are fewer lines after `goimports`, some garbage will remain at the end. For the undo problem, use [`undojoin`](http://vimhelp.appspot.com/undo.txt....
7,136
<p>When I use <code>:set iskeyword?</code> to view keyword characters, result for shell scripts is:</p> <pre><code>iskeyword=@,48-57,_,192-255,- </code></pre> <p>:h iskeyword says @ expands to any alpha character that the isalpha() functions returns true on, but what about <code>48-57</code> and <code>192-255</code> ...
[ { "answer_id": 7137, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>You can use:</p>\n\n<pre><code>:echo map(range(48, 57), 'nr2char(v:val)')\n:echo map(range(192, 255), 'nr2char(v:val)...
2016/04/01
[ "https://vi.stackexchange.com/questions/7136", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
When I use `:set iskeyword?` to view keyword characters, result for shell scripts is: ``` iskeyword=@,48-57,_,192-255,- ``` :h iskeyword says @ expands to any alpha character that the isalpha() functions returns true on, but what about `48-57` and `192-255` how can I view these characters?
You can use: ``` :echo map(range(48, 57), 'nr2char(v:val)') :echo map(range(192, 255), 'nr2char(v:val)') ``` Which should output: > > ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] > > > ['À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', > 'Ó', 'Ô', 'Õ', 'Ö', '×'...
7,138
<p>Is there any way I can use Vim with or Neovim to edit my project, and still be able to build it using Visual Studio?</p> <p>Note I am not talking about limited Vim emulators for Visual Studio but proper integration, with Vim at the front-end as the main tool and build tools at the back-end of the pipeline.</p>
[ { "answer_id": 7163, "author": "fuzzybear3965", "author_id": 2062, "author_profile": "https://vi.stackexchange.com/users/2062", "pm_score": 2, "selected": false, "text": "<p>So, what you're asking about is totally possible. Your code is, ultimately, going to consist of a bunch of plain t...
2016/04/01
[ "https://vi.stackexchange.com/questions/7138", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5328/" ]
Is there any way I can use Vim with or Neovim to edit my project, and still be able to build it using Visual Studio? Note I am not talking about limited Vim emulators for Visual Studio but proper integration, with Vim at the front-end as the main tool and build tools at the back-end of the pipeline.
**External Editing** If you have Visual Studio up and running while you edit the project files in a separate window under Vim, every time you switch back to Visual Studio, it looks at the on-disk timestamps for every file you have open in Visual Studio, including the project file. For each file that changed since you ...
7,140
<p>If I have a shell script with code like</p> <pre><code>... chars+=('5') chars+=('6') ... chars+=('%') chars+=('&amp;') ... </code></pre> <p>and <code>iskeyword</code> is defined as </p> <pre><code>iskeyword=@,48-57,_,192-255,- </code></pre> <p>This definition indicates to me Vim will consider a continuous sequen...
[ { "answer_id": 7143, "author": "John O'M.", "author_id": 227, "author_profile": "https://vi.stackexchange.com/users/227", "pm_score": 4, "selected": true, "text": "<p>I think the misunderstanding is that iskeyword doesn't define what a word is; rather, it adjusts where a boundary may hap...
2016/04/02
[ "https://vi.stackexchange.com/questions/7140", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4603/" ]
If I have a shell script with code like ``` ... chars+=('5') chars+=('6') ... chars+=('%') chars+=('&') ... ``` and `iskeyword` is defined as ``` iskeyword=@,48-57,_,192-255,- ``` This definition indicates to me Vim will consider a continuous sequence of characters from these `iskeywords` characters to be a word...
I think the misunderstanding is that iskeyword doesn't define what a word is; rather, it adjusts where a boundary may happen by adjusting what a keyword is. Both keywords and non-keywords are still "words". According to `:help word`: > > A word consists of a sequence of letters, digits and underscores, or a > seque...
7,145
<p>Suppose I have the following text, how can I delete single quotation marks and comma in each line end? I know I can use <code>x</code> command and delete <code>'</code> and <code>,</code> line by line. But are there any more clever way to do this? <kbd>CTRL</kbd>+<kbd>V</kbd> doesn't work here.</p> <pre><code>inde...
[ { "answer_id": 7146, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>With <code>:help :s</code>…</p>\n\n<pre><code>:%s/',\n</code></pre>\n\n<p>With <code>:help :normal</code>…</p>\n\n<pre><code>...
2016/04/02
[ "https://vi.stackexchange.com/questions/7145", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4582/" ]
Suppose I have the following text, how can I delete single quotation marks and comma in each line end? I know I can use `x` command and delete `'` and `,` line by line. But are there any more clever way to do this? `CTRL`+`V` doesn't work here. ``` index', wind_code', date', acct_rcv', acct_payable', adminexpensetogr'...
With `:help :s`… ``` :%s/', ``` With `:help :normal`… ``` :%norm $xx ``` With `:help recording`… ``` qq $xxj q :,$norm @q ``` or… ``` qq $xxj q @q@@@@@@@@@@ (as many times as needed) ``` With `:h .`… ``` /',<CR> 2x n.n.n.n. (as many times as needed) ```
7,160
<p>How do I turn vi colors off? I was using vim-tiny on on Ubuntu 14.04. Installed vim-nox. Version is version 7.4.52. Once I installed that, I got all these syntax colors by default. I have my Terminal set to a black background with bright green text. Now when I use vi with the colors, some of the text is unreadable a...
[ { "answer_id": 7161, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 2, "selected": false, "text": "<p>You can disable syntax highlighting by doing:</p>\n\n<pre><code>:syntax off\n</code></pre>\n\n<p>To turn it back on:</p>\n\n<...
2016/04/03
[ "https://vi.stackexchange.com/questions/7160", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1705/" ]
How do I turn vi colors off? I was using vim-tiny on on Ubuntu 14.04. Installed vim-nox. Version is version 7.4.52. Once I installed that, I got all these syntax colors by default. I have my Terminal set to a black background with bright green text. Now when I use vi with the colors, some of the text is unreadable agai...
You can use: ``` :set t_Co=0 ``` This will tell Vim that you're not using a colour terminal. The difference with using `:syntax off` is that this will still enable *some* syntax highlighting features with bold, underlined, and "reverse video".