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
3,300
<p>I have just reinstalled gvim 7.4 on my 64 bit Windows 7 system. <code>gvim.exe</code> now does not start, (or appears not to start - it may be exiting immediately)</p> <p>If I start <code>vim.exe</code> then it works fine. This is about the GUI version not starting. </p> <p>What might be the problem, and what stra...
[ { "answer_id": 3303, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 4, "selected": true, "text": "<p>You can capture a full log of a Vim session with <code>gvim -V20vimlog</code>. After quitting Vim, examine the <code>vi...
2015/05/16
[ "https://vi.stackexchange.com/questions/3300", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/460/" ]
I have just reinstalled gvim 7.4 on my 64 bit Windows 7 system. `gvim.exe` now does not start, (or appears not to start - it may be exiting immediately) If I start `vim.exe` then it works fine. This is about the GUI version not starting. What might be the problem, and what strategies might I adopt to get further ins...
You can capture a full log of a Vim session with `gvim -V20vimlog`. After quitting Vim, examine the `vimlog` log file for suspect commands. Also, it may be something in your configuration, so try launching with `gvim -N -u NONE` (which ignores plugins and your `.vimrc`).
3,307
<p>Is there a way to get vim's <code>gf</code> command (or something similar) to recognize a <code>+{cmd}</code> argument for file-paths?</p> <p>One can start vim and go directly to a search term by doing:</p> <pre><code>$ vim +/coding_effort ~/project/file </code></pre> <p>Similarly, in command mode you can do:</p>...
[ { "answer_id": 3312, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 4, "selected": true, "text": "<p>No, the first problem is that the necessary space between command and filename is not part of the '<code>isfname'</code...
2015/05/16
[ "https://vi.stackexchange.com/questions/3307", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1039/" ]
Is there a way to get vim's `gf` command (or something similar) to recognize a `+{cmd}` argument for file-paths? One can start vim and go directly to a search term by doing: ``` $ vim +/coding_effort ~/project/file ``` Similarly, in command mode you can do: ``` :e +/coding_effort ~/project/file ``` I often take ...
No, the first problem is that the necessary space between command and filename is not part of the '`isfname'` option, and adding it would mean file borders couldn't be recognized at all. You'd either have to always use a visual selection (of both command and filename), or implement custom parsing in a `gf` command over...
3,308
<p>I like the <code>-</code> and <code>&lt;C-M&gt;</code> normal-mode keys for going to the first non-whitespace character of the previous/next line.</p> <p>Are there coresponding keys for going to the <em>last</em> non-whitespace character on the previous/next line?</p>
[ { "answer_id": 3309, "author": "akshay", "author_id": 246, "author_profile": "https://vi.stackexchange.com/users/246", "pm_score": 5, "selected": true, "text": "<p><code>g_</code> moves the cursor to the last non-blank character of the <em>current</em> line. From Vim's <a href=\"http://v...
2015/05/17
[ "https://vi.stackexchange.com/questions/3308", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1855/" ]
I like the `-` and `<C-M>` normal-mode keys for going to the first non-whitespace character of the previous/next line. Are there coresponding keys for going to the *last* non-whitespace character on the previous/next line?
`g_` moves the cursor to the last non-blank character of the *current* line. From Vim's [`:help g_`](http://vimhelp.appspot.com/motion.txt.html#g_): ``` g_ To the last non-blank character of the line and [count - 1] lines downward |inclusive|. {not in Vi} ``` Unfortunately, I think the only opti...
3,314
<p>Is there a way to shorten the displayed name of the buffer, for example, on the image, path(...)/application_controller.rb to simply "application_controller.rb"? If I have many buffers with such long names, things get messy.</p> <p>My buffer menu :</p> <pre><code>set wildmenu set wildmode=longest:full,full s...
[ { "answer_id": 3315, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 2, "selected": false, "text": "<p>If all you want to do is shorten the filename shown on the status line, search <code>statusline</code> or <code>stl</code...
2015/05/17
[ "https://vi.stackexchange.com/questions/3314", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2131/" ]
Is there a way to shorten the displayed name of the buffer, for example, on the image, path(...)/application\_controller.rb to simply "application\_controller.rb"? If I have many buffers with such long names, things get messy. My buffer menu : ``` set wildmenu set wildmode=longest:full,full set wildcharm='<'C-Y...
If all you want to do is shorten the filename shown on the status line, search `statusline` or `stl` in your `vimrc`, and replace `%f` with `%t`. See `:help statusline` for details.
3,320
<p>I'm facing a behavior that I find unatural when trying to paste a block of text selected with visual block mode (<code>&lt;C-v&gt;</code>): I can't insert it between two lines without messing with the already existing line.</p> <p>Here's an example:</p> <p>If I have this file</p> <pre><code>abc def hij klm This ...
[ { "answer_id": 3315, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 2, "selected": false, "text": "<p>If all you want to do is shorten the filename shown on the status line, search <code>statusline</code> or <code>stl</code...
2015/05/18
[ "https://vi.stackexchange.com/questions/3320", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
I'm facing a behavior that I find unatural when trying to paste a block of text selected with visual block mode (`<C-v>`): I can't insert it between two lines without messing with the already existing line. Here's an example: If I have this file ``` abc def hij klm This is a text on several lines and this is anothe...
If all you want to do is shorten the filename shown on the status line, search `statusline` or `stl` in your `vimrc`, and replace `%f` with `%t`. See `:help statusline` for details.
3,327
<p>I have some C++ sources files which are in a few mega-bytes (a few tens thousands lines) to view and edit. The performance looks really bad in Vim. Refersh (<code>&lt;C-l&gt;</code>) or input single char in insert mode take several seconds to complete. I tried <code>:syn off</code> then all previous operations respo...
[ { "answer_id": 17372, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>Actually, while this isn't a solution to your <em>specific</em> problem (improving syntax highlighting for massive files)...
2015/05/19
[ "https://vi.stackexchange.com/questions/3327", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/477/" ]
I have some C++ sources files which are in a few mega-bytes (a few tens thousands lines) to view and edit. The performance looks really bad in Vim. Refersh (`<C-l>`) or input single char in insert mode take several seconds to complete. I tried `:syn off` then all previous operations responded immediately. I also tried ...
Actually, while this isn't a solution to your *specific* problem (improving syntax highlighting for massive files), you may want to actually think about refactoring your source code so that you *don't* have tens of thousands of line in a single file. This scenario generally has impacts *beyond* your editor, things lik...
3,328
<p>When I have to replace a word with another word I yank before, I usually use a workflow which seems unnatural to me:</p> <p>Let's say I have this text:</p> <pre><code>foo bar buzz </code></pre> <p>And I want to yank <code>foo</code> and replace <code>bar</code> with what I yanked before.</p> <p>After yanking <co...
[ { "answer_id": 3329, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": false, "text": "<p>Assuming you've already yanked <code>foo</code> with <code>ye</code> or something similar, and that the cursor is so...
2015/05/19
[ "https://vi.stackexchange.com/questions/3328", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
When I have to replace a word with another word I yank before, I usually use a workflow which seems unnatural to me: Let's say I have this text: ``` foo bar buzz ``` And I want to yank `foo` and replace `bar` with what I yanked before. After yanking `foo`, I see the following options: **Option 1** 1. Place the c...
**EDIT 5 years later** I had forgotten about this question but it turns out that the perfect solution for me is [vim-subversive](https://github.com/svermeulen/vim-subversive) which provides two new operator motions to make it easy to perform quick substitutions. I installed the plugin and added this to my config: ```...
3,333
<p>I love vim, i use it all the time for write codes, but now I want to write some personal notes.</p> <p>I'm trying <a href="https://github.com/vim-pandoc/vim-pandoc" rel="noreferrer">vim-pandoc</a> (with vim-pandoc-syntax) and it's nice to have 'rich text' features like titles, items, bold, italic fonts and even tab...
[ { "answer_id": 3336, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 1, "selected": false, "text": "<p>It really depends on where you want to read those documents. Inside Vim, you can define your own <em>syntax highlighti...
2015/05/19
[ "https://vi.stackexchange.com/questions/3333", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2145/" ]
I love vim, i use it all the time for write codes, but now I want to write some personal notes. I'm trying [vim-pandoc](https://github.com/vim-pandoc/vim-pandoc) (with vim-pandoc-syntax) and it's nice to have 'rich text' features like titles, items, bold, italic fonts and even tables, but doen't have 'arbitrary colore...
@Ingo Karkat Your Txtfmt files should look the same on different computers. If they don't, it could be that Vim is using a different encoding on the different computers (e.g., utf-8 vs latin-1), and you haven't set Txtfmt's 'tokrange' option explicitly. Recommended approach is to set 'tokrange' to a value that will wo...
3,342
<h2>Background</h2> <p>I work at a research laboratory and use three different OS's daily. On the Windows and Mac machines I make use of <a href="http://www.zhornsoftware.co.uk/caffeine/" rel="noreferrer">Caffeine</a> to keep those machines from enabling the screensaver while I work on a different machine (Linux doesn...
[ { "answer_id": 3343, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": true, "text": "<p>You can map a key to <code>&lt;nop&gt;</code> (short for \"no operation\") to make it \"do nothing\".</p>\n\n<p>This ...
2015/05/20
[ "https://vi.stackexchange.com/questions/3342", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1862/" ]
Background ---------- I work at a research laboratory and use three different OS's daily. On the Windows and Mac machines I make use of [Caffeine](http://www.zhornsoftware.co.uk/caffeine/) to keep those machines from enabling the screensaver while I work on a different machine (Linux doesn't have this problem). It's v...
You can map a key to `<nop>` (short for "no operation") to make it "do nothing". This should make Vim ignore the `<F15>` key in all modes: ``` :noremap <F15> <nop> :noremap! <F15> <nop> ``` This will *probably* fix your problem, but I haven't tested it in your specific situation, as I don't have various Windows/OS...
3,352
<p>If editing a buffer in the right side window when using two vertical split windows in a big display screen, we have to move our eyes all across the screen to the bottom left corner to see any messages Vim is displaying.</p> <p>This is specially important because many times I need to re-indent the code I've just pas...
[ { "answer_id": 3353, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 2, "selected": false, "text": "<p>The <em>command-line</em> will always span the entire width of Vim's application window; it cannot be moved or restric...
2015/05/21
[ "https://vi.stackexchange.com/questions/3352", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/599/" ]
If editing a buffer in the right side window when using two vertical split windows in a big display screen, we have to move our eyes all across the screen to the bottom left corner to see any messages Vim is displaying. This is specially important because many times I need to re-indent the code I've just pasted, so I ...
Messages are displayed in the commandline, and there is no way to change the position of the commandline, except for changing the height. The only workaround I can think of is using the message history (`:messages`), and putting that in the statusline. Note that `:echo` will *not* put the message in the message histo...
3,359
<p>I installed the <a href="https://github.com/bling/vim-airline" rel="noreferrer"><strong>Airline</strong></a> plugin in order to have a custom status bar, as seen in the figure below:</p> <p><img src="https://i.stack.imgur.com/ehqwL.gif" alt="Enter image description here"></p> <p>However, my status bar is presentin...
[ { "answer_id": 3360, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 4, "selected": false, "text": "<p>From the <a href=\"https://github.com/bling/vim-airline#user-content-integrating-with-powerline-fonts\">README</a>:</p>\n...
2015/05/22
[ "https://vi.stackexchange.com/questions/3359", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2179/" ]
I installed the [**Airline**](https://github.com/bling/vim-airline) plugin in order to have a custom status bar, as seen in the figure below: ![Enter image description here](https://i.stack.imgur.com/ehqwL.gif) However, my status bar is presenting the symbols `<`, `>>` and `<`. How do I fix this problem? ![Enter ima...
At first I too didn't understand what needs to be done to get this nice looking toolbar. Yes I know about the README and other stuff, but I think there should be a `getting started` or `minimum settings` section in the help file. Anyway here are the settings. ### Installing the appropriate fonts You need to install ...
3,362
<p>I'm using a script to load files in vim remotely into one gvim instance per desktop viewport. It works fine, except that it causes an empty additional window, that will remain after closing all others, and needs extra keystrokes to quit.</p> <p>Are there simple means of quitting in that situation, without messing u...
[ { "answer_id": 3472, "author": "Cometsong", "author_id": 2303, "author_profile": "https://vi.stackexchange.com/users/2303", "pm_score": 0, "selected": false, "text": "<p>I found possible solution in this answer at SuperUser <a href=\"https://superuser.com/a/668612\">\"Vim: quit if buffer...
2015/05/22
[ "https://vi.stackexchange.com/questions/3362", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/925/" ]
I'm using a script to load files in vim remotely into one gvim instance per desktop viewport. It works fine, except that it causes an empty additional window, that will remain after closing all others, and needs extra keystrokes to quit. Are there simple means of quitting in that situation, without messing up others ...
The way I understood your question, you have a script which opens several tabs in a vim instance, you do stuff and end with 2 tabs opened in vim, and one of these tabs is empty. When you close the non empty tab, vim should close too since the remaining tab is useless. In this case you could use the following function ...
3,364
<p>The normal mode command <code>gf</code> go to a file with the path the cursor currently is at.</p> <p>But it does so in the current window, replacing the current text. That means you need to navigate back explicitly to go to the back later, and that you need to write changes in the current buffer potentially.</p>...
[ { "answer_id": 3365, "author": "Alexander Myshov", "author_id": 500, "author_profile": "https://vi.stackexchange.com/users/500", "pm_score": 4, "selected": false, "text": "<p>You can use bindings for this:</p>\n<p>opening in a new window (split):</p>\n<pre><code>nnoremap gf &lt;C-W&gt;f\...
2015/05/22
[ "https://vi.stackexchange.com/questions/3364", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/925/" ]
The normal mode command `gf` go to a file with the path the cursor currently is at. But it does so in the current window, replacing the current text. That means you need to navigate back explicitly to go to the back later, and that you need to write changes in the current buffer potentially. I'm sure it's possible ...
*EDIT: Suggest nicely symmetric mappings for the vertical split case, since Vim by default has two mappings for the horizontal split case.* There are several ways to edit the "file under cursor", and while you certainly can remap `gf` to edit in a new tabpage as @alexander-myshov mentions, that means you have two ways...
3,378
<p>How do I refresh file tree in NERDTree ?</p> <p>If I use: </p> <pre><code>:!touch SomeNewFile </code></pre> <p>It is not rendered in the tree.</p>
[ { "answer_id": 3380, "author": "jjaderberg", "author_id": 1306, "author_profile": "https://vi.stackexchange.com/users/1306", "pm_score": 5, "selected": true, "text": "<p>The NERD tree quick help is accessible from the NERD tree window by typing <kbd>?</kbd> There I read:</p>\n\n<blockquo...
2015/05/23
[ "https://vi.stackexchange.com/questions/3378", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1262/" ]
How do I refresh file tree in NERDTree ? If I use: ``` :!touch SomeNewFile ``` It is not rendered in the tree.
The NERD tree quick help is accessible from the NERD tree window by typing `?` There I read: > > " Filesystem mappings~ > > ... > > " r: refresh cursor dir > > " R: refresh current root > > > These should do what you ask.
3,379
<p>How can I have different cursor shapes when running vim inside tmux under cygwin?</p> <p>WITHOUT tmux these lines would be enough to achieve what I want:</p> <pre><code>let &amp;t_SI = "\e[5 q" let &amp;t_EI = "\e[2 q" </code></pre> <p>But somehow my tmux breaks it - cursor has block shape no matter what vim mode...
[ { "answer_id": 3421, "author": "Alex Kroll", "author_id": 1145, "author_profile": "https://vi.stackexchange.com/users/1145", "pm_score": 2, "selected": false, "text": "<p>The correct value of <code>$TERM</code> environments variable is very important. Make sure that it is different from ...
2015/05/23
[ "https://vi.stackexchange.com/questions/3379", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1067/" ]
How can I have different cursor shapes when running vim inside tmux under cygwin? WITHOUT tmux these lines would be enough to achieve what I want: ``` let &t_SI = "\e[5 q" let &t_EI = "\e[2 q" ``` But somehow my tmux breaks it - cursor has block shape no matter what vim mode I'm in. **My specs:** * Windows 7 x64 ...
It seems the problem is that tmux doesn't send your cursor-changing escape codes to the terminal emulator. You need to wrap your desired escape codes in a special sequence that tells tmux that it should pass it on to the outer terminal. The sequence you need to wrap your escape sequence in is `\<Esc>Ptmux;\<Esc> ... \...
3,397
<p>My <code>.vimrc</code> chooses my preferred color scheme (solarized) which is installed via plugin management system. Yet on some systems which don't have that plugin the <code>:colorscheme solarized</code> command runs but the result is whacky.</p> <p>how do I conditionally test if solarized is indeed installed a...
[ { "answer_id": 3398, "author": "Dan Bradbury", "author_id": 2189, "author_profile": "https://vi.stackexchange.com/users/2189", "pm_score": 2, "selected": false, "text": "<p>If you want to accomplish this programmatically you will need to check the list of available colorschemes.</p>\n\n<...
2015/05/26
[ "https://vi.stackexchange.com/questions/3397", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/544/" ]
My `.vimrc` chooses my preferred color scheme (solarized) which is installed via plugin management system. Yet on some systems which don't have that plugin the `:colorscheme solarized` command runs but the result is whacky. how do I conditionally test if solarized is indeed installed and use it if it is but use a diff...
### Lets fail with Style! ``` silent! colorscheme evening silent! colorscheme solarized ``` The `:silent!` will ignore the errors at start up. Just put color schemes in reverse order of what you really want. For more help see: ``` :h :silent ```
3,405
<p>I'm planning to implement some utility mappings for my <a href="https://github.com/lervag/vimtex">LaTeX plugin</a> to simplify typing of mathematics. For instance, I want to create abbreviations similar to</p> <pre><code>`a : \alpha `b : \beta -&gt; : \to =&gt; : \Rightarrow </code></pre> <p>And similar. I want (s...
[ { "answer_id": 3406, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 4, "selected": true, "text": "<p>Perhaps like this:</p>\n\n\n\n<pre><code>let s:TeXmaps = {\n \\ '`a': '\\alpha',\n \\ '`b': '\\beta',\n \\ '-&gt;...
2015/05/27
[ "https://vi.stackexchange.com/questions/3405", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/21/" ]
I'm planning to implement some utility mappings for my [LaTeX plugin](https://github.com/lervag/vimtex) to simplify typing of mathematics. For instance, I want to create abbreviations similar to ``` `a : \alpha `b : \beta -> : \to => : \Rightarrow ``` And similar. I want (some of) the mappings only to be available i...
Perhaps like this: ``` let s:TeXmaps = { \ '`a': '\alpha', \ '`b': '\beta', \ '->': '\to', \ '=>': '\Rightarrow' } function! <SID>IsTeXMath() return &ft ==# 'tex' && match(map( synstack(line('.'), col('.')), 'synIDattr(v:val, "name")' ), '\m^texMathZone[EX]$') >= 0 endfunction for s:k in keys(s:T...
3,455
<p>When using Vim to edit a read only file it will just provide a warning the first time it is edited but allow any changes to take place. I can understand this behaviour could be useful for someone intending on saving the file under another name; but I sometimes open files that I don't have write access to, then forge...
[ { "answer_id": 3457, "author": "ZeroKelvinKeyboard", "author_id": 2283, "author_profile": "https://vi.stackexchange.com/users/2283", "pm_score": 5, "selected": true, "text": "<p>I found a solution. Setting <code>nomodifiable</code> prevents the file being edited (as used in help windows)...
2015/05/29
[ "https://vi.stackexchange.com/questions/3455", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2283/" ]
When using Vim to edit a read only file it will just provide a warning the first time it is edited but allow any changes to take place. I can understand this behaviour could be useful for someone intending on saving the file under another name; but I sometimes open files that I don't have write access to, then forget a...
I found a solution. Setting `nomodifiable` prevents the file being edited (as used in help windows). I created a simple function to set or unset `modifiable` depending on if `readonly` is set and attached it to an autocmd. ``` " Don't allow editing of read only files autocmd BufRead * call RONoEdit() function! RONoE...
3,468
<p>Suppose I am editing a file.tex. How would I open file.pdf in zathura (or any pdf viewer) from vim?</p> <p>I understand how to reference file.tex using '%' but I'm not sure how to reference file.pdf.</p>
[ { "answer_id": 3469, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 2, "selected": false, "text": "<p>You can do something like this</p>\n\n<pre><code>let main = expand('%')\nlet pdf = fnamemod(main, ':r') . '.pdf'\n...
2015/05/30
[ "https://vi.stackexchange.com/questions/3468", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2296/" ]
Suppose I am editing a file.tex. How would I open file.pdf in zathura (or any pdf viewer) from vim? I understand how to reference file.tex using '%' but I'm not sure how to reference file.pdf.
`%` indeed stands for the current file. `%:r` (see `:help filename-modifiers`) strips off the file extension. You can then use `:!` to launch an external command, e.g. the PDF viewer: ``` :! zathura %:r.pdf ```
3,478
<p>I'm trying to write a simple mapping that will pre-populate the vim ex command line but leave the user there to execute the command on their own.</p> <p>The use-case is for the user to type <code>&lt;leader&gt;/foo</code> which would then open the command line with <code>:e **/foo</code> and the user could either f...
[ { "answer_id": 3479, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>That kind of mapping is very, very common:</p>\n\n<pre><code>nnoremap &lt;leader&gt;/ :edit **/*\n</code></pre>\n\n<p><img sr...
2015/05/31
[ "https://vi.stackexchange.com/questions/3478", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2312/" ]
I'm trying to write a simple mapping that will pre-populate the vim ex command line but leave the user there to execute the command on their own. The use-case is for the user to type `<leader>/foo` which would then open the command line with `:e **/foo` and the user could either further refine, press ctrl-d to see pos...
That kind of mapping is very, very common: ``` nnoremap <leader>/ :edit **/* ``` ![:edit](https://i.stack.imgur.com/jHCAW.gif) Might I suggest the following slightly smarter alternative? ``` set path=.,** nnoremap <leader>/ :find * ``` The `'path'` option tells Vim to look for files matching the argument given t...
3,491
<p>Something that helps in text editing and proofreading is that for Insert mode, I have set an IMAP:</p> <pre><code>:imap zz ^[:w^M </code></pre> <p>and when I type <code>zz</code> I return to command mode and also write the current buffer. This makes <code>latexmk</code> reprocess my <code>.tex</code>.</p> <p>Howe...
[ { "answer_id": 3492, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 3, "selected": false, "text": "<p>Use event-based autocommands: I suggest <code>TextChanged</code> for normal mode, and <code>InsertLeave</code> for inse...
2015/06/01
[ "https://vi.stackexchange.com/questions/3491", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2017/" ]
Something that helps in text editing and proofreading is that for Insert mode, I have set an IMAP: ``` :imap zz ^[:w^M ``` and when I type `zz` I return to command mode and also write the current buffer. This makes `latexmk` reprocess my `.tex`. However, I also make smaller changes like replacing single characters ...
Use event-based autocommands: I suggest `TextChanged` for normal mode, and `InsertLeave` for insert mode - which can also replace your `zz` mapping.
3,498
<p>How can I bring up the path to the current file in the command line, so as to type a similar file name? I don't want an abbreviation that would be replaced by the current file name, I want to edit the file name, complete with its directory path. For example, I want to <code>:edit</code> a file with a similar name, o...
[ { "answer_id": 3499, "author": "Gilles 'SO- stop being evil'", "author_id": 8, "author_profile": "https://vi.stackexchange.com/users/8", "pm_score": 3, "selected": false, "text": "<p>Oh. Search for “file name” in <code>:help :</code>! It's simple: <code><a href=\"http://vimdoc.sourceforg...
2015/06/02
[ "https://vi.stackexchange.com/questions/3498", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8/" ]
How can I bring up the path to the current file in the command line, so as to type a similar file name? I don't want an abbreviation that would be replaced by the current file name, I want to edit the file name, complete with its directory path. For example, I want to `:edit` a file with a similar name, or in a similar...
In addition to inserting the `%` register as you've discovered yourself, you can also use `:edit %<Tab>`. From [`:help cmdline-special`](http://vimhelp.appspot.com/cmdline.txt.html#cmdline-special): ``` In Ex commands, at places where a file name can be used, the following characters have a special meaning. These ca...
3,503
<p>I have some autocmd triggering on <code>TextChanged</code>, that I want to have persisted between Vim restarts.</p> <p>I could make a big if-elseif construct in the vimrc, sure, but I prefer saving the autocmd only for the specific file, as the autocmd cmd changes with each file.</p> <p>Can this be done using view...
[ { "answer_id": 3504, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 2, "selected": false, "text": "<p>In your <code>~/.vimrc</code>, you can define an <code>:autocmd</code> that targets the opening of the particular file...
2015/06/03
[ "https://vi.stackexchange.com/questions/3503", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2349/" ]
I have some autocmd triggering on `TextChanged`, that I want to have persisted between Vim restarts. I could make a big if-elseif construct in the vimrc, sure, but I prefer saving the autocmd only for the specific file, as the autocmd cmd changes with each file. Can this be done using view sessions? Do you have bette...
In your `~/.vimrc`, you can define an `:autocmd` that targets the opening of the particular file, and then define the `TextChanged` autocmd for the particular buffer in there: ``` autocmd BufRead /path/to/the/special/file autocmd TextChanged <buffer> ... ```
3,512
<p>The syntax <code>foldmethod</code> is great, but sometimes I just want to fold the comments in a source file.</p> <p>Also syntax folding of comments only works for C-Style comments like:</p> <pre><code>/* ... */ </code></pre> <p>But not for comment boilerplate like:</p> <pre><code>// // // ... // </code></pre>...
[ { "answer_id": 3513, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": true, "text": "<p>Folding only the comments is fairly easy by using <code>foldmethod=expr</code>:</p>\n\n<pre><code>set foldmethod=expr...
2015/06/04
[ "https://vi.stackexchange.com/questions/3512", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2357/" ]
The syntax `foldmethod` is great, but sometimes I just want to fold the comments in a source file. Also syntax folding of comments only works for C-Style comments like: ``` /* ... */ ``` But not for comment boilerplate like: ``` // // // ... // ``` Or even for comment blocks in non-C-like languages like: ``` ...
Folding only the comments is fairly easy by using `foldmethod=expr`: ``` set foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*'.&commentstring[0] ``` This will simply check if the line starts with any amount of whitespace followed by a comment character. Note that this is fairly naïve and may not work for all languag...
3,514
<p>I'm using a <a href="http://myusuf3.github.io/numbers.vim/" rel="noreferrer">really clever plugin</a> that changes the line number style (relative/normal) contextually. Basically when you enter insert mode you have normal line numbers and when you leave insert mode it switches to relative numbers. A missing feature ...
[ { "answer_id": 3515, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>You can use mappings to override <code>:</code>, <code>/</code>, and <code>?</code> to do some action first:</p>\n\n<...
2015/06/04
[ "https://vi.stackexchange.com/questions/3514", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/544/" ]
I'm using a [really clever plugin](http://myusuf3.github.io/numbers.vim/) that changes the line number style (relative/normal) contextually. Basically when you enter insert mode you have normal line numbers and when you leave insert mode it switches to relative numbers. A missing feature is to have normal line numbers ...
You can use mappings to override `:`, `/`, and `?` to do some action first: ``` nnoremap : :set number<CR>: nnoremap / :set number<CR>/ nnoremap ? :set number<CR>? ``` Because we use *non-recursive* mappings, the `:` at the end will call the original built-in `:`. To hide the numbers again, you can use command-line...
3,518
<p>I wanted to know if there is some way of fetching a random "article" (maybe article is not the proper term here) from the vim documentation.</p> <p>I found nearly nothing on the subject on vim documentation and on internet.</p> <p>One of my ideas was to list every file of documentation and then pick one randomly. ...
[ { "answer_id": 3519, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 2, "selected": false, "text": "<p>The documentation files are stored are text files in <code>$VIMRUNTIME/doc</code>. You can start the documentation b...
2015/06/04
[ "https://vi.stackexchange.com/questions/3518", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
I wanted to know if there is some way of fetching a random "article" (maybe article is not the proper term here) from the vim documentation. I found nearly nothing on the subject on vim documentation and on internet. One of my ideas was to list every file of documentation and then pick one randomly. But even "list ev...
I think the 'article' you're looking for is 'help tag' - if so, look no further than: <https://github.com/mhinz/vim-randomtag>
3,530
<p>I want to write a function which takes two strings <strong>this</strong> and <strong>that</strong> as its arguments and replaces all instances of <strong>this</strong> with <strong>that</strong>.</p> <p>So the function should look like:</p> <pre><code>function! ReplaceThisWithThat(this, that) "Main Stuff . ...
[ { "answer_id": 3531, "author": "Alex Kroll", "author_id": 1145, "author_profile": "https://vi.stackexchange.com/users/1145", "pm_score": 1, "selected": false, "text": "<p>Function arguments have <code>a:</code> prefix.</p>\n\n<pre><code>function! ReplaceThisWithThat(this, that)\n \...
2015/06/06
[ "https://vi.stackexchange.com/questions/3530", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2369/" ]
I want to write a function which takes two strings **this** and **that** as its arguments and replaces all instances of **this** with **that**. So the function should look like: ``` function! ReplaceThisWithThat(this, that) "Main Stuff . . . endfunction ``` Can somebody please help?
You can do it very simply with: ``` function! ReplaceThisWithThat(this, that) execute "%s/" . a:this . "/" . a:that . "/g" endfunction ``` Which will substitute every occurrence of `a:this` with `a:that` in the whole buffer. If you want to perform that substitution on the content of some variable or register, y...
3,534
<p>I'm working on large files for wikisource, along with another guy. I generate a big text file (a few Mb) witch I format a bit using scripts, then I upload the text to a temporary page, where the other guy does some more formatting.</p> <p>My friends computer and internet connection are not the best in the market, a...
[ { "answer_id": 3535, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 2, "selected": false, "text": "<p>You can try something like this: place you cursor on the next line after a header, and hit: </p>\n\n<p><code>y/\\_.\\{0...
2015/06/06
[ "https://vi.stackexchange.com/questions/3534", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/342/" ]
I'm working on large files for wikisource, along with another guy. I generate a big text file (a few Mb) witch I format a bit using scripts, then I upload the text to a temporary page, where the other guy does some more formatting. My friends computer and internet connection are not the best in the market, and he aske...
Ok, this is somewhat of a quick hack, let's hope it works: ``` function! <SID>Chunk() " find first header let l_start = search('\m^==[^=]\+==$', 'cW') if !l_start " beep execute "normal \<Esc>" return endif " translate to byte position let b_start = line2byte(l_start) ...
3,559
<p>I added the following key mappings:</p> <pre><code>inoremap &lt;silent&gt; &lt;Up&gt; &lt;C-o&gt;gk inoremap &lt;silent&gt; &lt;Down&gt; &lt;C-o&gt;gj </code></pre> <p>The goal was that <code>j</code>/<code>k</code> would still work the way that I was used to, but that I could use the arrow keys as an alternativ...
[ { "answer_id": 3560, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>You can use the more powerful \"expression mappings\":</p>\n\n<pre><code>:inoremap &lt;expr&gt; &lt;silent&gt; &lt;Up...
2015/06/10
[ "https://vi.stackexchange.com/questions/3559", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1688/" ]
I added the following key mappings: ``` inoremap <silent> <Up> <C-o>gk inoremap <silent> <Down> <C-o>gj ``` The goal was that `j`/`k` would still work the way that I was used to, but that I could use the arrow keys as an alternative to more easily navigate wrapped lines. Now I've discovered that these mappings int...
You can use the more powerful "expression mappings": ``` :inoremap <expr> <silent> <Up> pumvisible() ? "\<Up>" : "\<C-o>gk" :inoremap <expr> <silent> <Down> pumvisible() ? "\<Down>" : "\<C-o>gj" ``` Note that we added the `<expr>` keyword here. Now Vim expects that the right-hand is some (valid) VimScript expressi...
3,561
<p>It's really frustrating when I need to edit a file as root and use <code>sudo vim somefile.conf</code> and I can't use any of my keybindings and settings and plugins.</p> <p>Is there a way to get all my customizations when I need to edit as root?</p> <p>I am using vim-plug for my plugins.</p>
[ { "answer_id": 3562, "author": "Robbie Wxyz", "author_id": 2221, "author_profile": "https://vi.stackexchange.com/users/2221", "pm_score": 3, "selected": false, "text": "<p>It looks like all you have to do is symlink root's <code>~/.vimrc</code> and <code>~/.vim/</code> to your's.</p>\n\n...
2015/06/10
[ "https://vi.stackexchange.com/questions/3561", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2221/" ]
It's really frustrating when I need to edit a file as root and use `sudo vim somefile.conf` and I can't use any of my keybindings and settings and plugins. Is there a way to get all my customizations when I need to edit as root? I am using vim-plug for my plugins.
Rather than opening vim as root, you can simply save as root by redirecting to tee. Here is an example: ``` :w !sudo tee % > /dev/null ``` This may be useful to alias in your .vimrc, I use `:Sw`: ``` command! -nargs=0 Sw w !sudo tee % > /dev/null ```
3,576
<p>I don't have a full understanding of how my color scheme is interacting with the <code>term</code> setting in vim and this is impeding my ability to get it to display correctly in neovim.</p> <p>In my .vimrc file, correct behavior of the color scheme in question requires setting</p> <pre><code>set term=xterm set t...
[ { "answer_id": 3577, "author": "Jeff Buttas", "author_id": 2460, "author_profile": "https://vi.stackexchange.com/users/2460", "pm_score": 0, "selected": false, "text": "<p>Try setting your <code>$TERM</code>environment variable like this: </p>\n\n<pre><code>TERM=xterm-256color\n</code></...
2015/06/13
[ "https://vi.stackexchange.com/questions/3576", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/783/" ]
I don't have a full understanding of how my color scheme is interacting with the `term` setting in vim and this is impeding my ability to get it to display correctly in neovim. In my .vimrc file, correct behavior of the color scheme in question requires setting ``` set term=xterm set t_Co=256 ``` Omitting either of...
Main Issue ---------- The main problem you are experiencing is caused by the ordering of the commands in your `.vimrc`. You set the `g:impact_transbg` variable *after* you load the colorscheme, and so the variable does *not* exist when checked by the colorscheme's `if` statement, and the second version of the colorsc...
3,600
<p>I know I can execute the current file, lets say a bash file, with <code>:! bash %</code>. But what can I do if I want to execute the current file in a different directory (such as the location of the current file) than the current vim working directory. I know that I could change to the working directory of the cur...
[ { "answer_id": 3601, "author": "Janis", "author_id": 2479, "author_profile": "https://vi.stackexchange.com/users/2479", "pm_score": 2, "selected": true, "text": "<p>There are various possibilities, but I think you'd either have to jump back (<code>cd -</code>), or execute the command in ...
2015/06/16
[ "https://vi.stackexchange.com/questions/3600", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/436/" ]
I know I can execute the current file, lets say a bash file, with `:! bash %`. But what can I do if I want to execute the current file in a different directory (such as the location of the current file) than the current vim working directory. I know that I could change to the working directory of the current file by `...
There are various possibilities, but I think you'd either have to jump back (`cd -`), or execute the command in a subshell; e.g.: ``` :! cd somedir; bash ~-/% ; cd - :! bash -c 'cd somedir ; bash ~-/%' ```
3,604
<p>I have the following:</p> <pre><code>e.printStackTrace(); </code></pre> <p>with the block cursor over the semicolon, what is the easiest way to delete that and end up with the cursor where the first <code>e</code> is?</p> <p>So <code>dd</code> for deleting the line is out, I guess <code>ciw</code> would only dele...
[ { "answer_id": 3605, "author": "Janis", "author_id": 2479, "author_profile": "https://vi.stackexchange.com/users/2479", "pm_score": 2, "selected": false, "text": "<p>I'm not sure that is the optimal way, but I'd basically do: <code>dB</code>. That will keep the <code>;</code>, so that de...
2015/06/16
[ "https://vi.stackexchange.com/questions/3604", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2488/" ]
I have the following: ``` e.printStackTrace(); ``` with the block cursor over the semicolon, what is the easiest way to delete that and end up with the cursor where the first `e` is? So `dd` for deleting the line is out, I guess `ciw` would only delete the `();` part of the line, or I could press `v` to highlight g...
Probably the best thing you can do in this case is use `cc`/`S` and just retype the `e`. ``` Se ``` However as you look like you are using a language that uses `;` as endings and `.`'s, then you probably just want to do something like `cT.` to make your changes. In my opinion it is probably not worth optimizing you...
3,612
<p>Vim keeps unindenting the lines I want to keep indented if I don't write anything on them... I'll give an example, where the | is the caret.</p> <ol> <li><p>Caret is indented and I press enter</p> <pre><code>if expression: print("hello world") | </code></pre></li> <li><p>Caret is indented on the next line,...
[ { "answer_id": 3613, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 2, "selected": false, "text": "<p>To keep the indent ... write something on that line, before moving to other lines! Otherwise, since you are a good Vim ...
2015/06/17
[ "https://vi.stackexchange.com/questions/3612", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2497/" ]
Vim keeps unindenting the lines I want to keep indented if I don't write anything on them... I'll give an example, where the | is the caret. 1. Caret is indented and I press enter ``` if expression: print("hello world") | ``` 2. Caret is indented on the next line, and now I press the up arrow ``` if express...
What you're seeing is the normal behavior of `'autoindent'` which the Python indent plugin uses. See `:help 'ai'`. You can watch what happens to the indent as you type by executing ``` :set list ``` There is no way that I know of to make Vim automatically preserve your indent in the case you describe. Setting the `I...
3,615
<p>If I have the folowing file:</p> <pre><code>XX:YY:ZZ foobar: some text XX:YY:ZZ foobar: some other text a text breaking the pattern XX:YY:ZZ foobar: some more text </code></pre> <p>And I want to operate on the differents parts <code>XX:YY:ZZ foobar:</code> of the lines. When I am on the first line I can select the...
[ { "answer_id": 3616, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 2, "selected": false, "text": "<p>I think the 'vim way' does not rely on using the visual mode to do something with the selection, but the other way arou...
2015/06/17
[ "https://vi.stackexchange.com/questions/3615", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
If I have the folowing file: ``` XX:YY:ZZ foobar: some text XX:YY:ZZ foobar: some other text a text breaking the pattern XX:YY:ZZ foobar: some more text ``` And I want to operate on the differents parts `XX:YY:ZZ foobar:` of the lines. When I am on the first line I can select the text that I want with, for example, ...
You could simply create a quick mapping: ``` :nnoremap <key> 0v3f: ``` Or use a macro recording: ``` qq 0v3f: q ``` then: ``` @q ``` Here is another method, lifted from the "experimental" part of my config: ``` function! GetVisualSelection() let old_reg = @v normal! gv"vy let raw_search = @v let @v = ...
3,632
<p>I have in my <code>.vimrc</code> some simple mappings to resize split windows easily:</p> <pre><code>noremap &lt;Leader&gt;&lt;UP&gt; &lt;C-w&gt;+ noremap &lt;Leader&gt;&lt;DOWN&gt; &lt;C-w&gt;- </code></pre> <p>That works pretty fine but for example, when I want to resize the window of 10 lines I have to pres...
[ { "answer_id": 3633, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 5, "selected": true, "text": "<p>You could try entering a ... Vim <a href=\"https://github.com/kana/vim-submode\">submode</a>! For your case, something l...
2015/06/18
[ "https://vi.stackexchange.com/questions/3632", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
I have in my `.vimrc` some simple mappings to resize split windows easily: ``` noremap <Leader><UP> <C-w>+ noremap <Leader><DOWN> <C-w>- ``` That works pretty fine but for example, when I want to resize the window of 10 lines I have to press and release `Leader`+`UP` 10 times. **How can I repeat this mapping wh...
You could try entering a ... Vim [submode](https://github.com/kana/vim-submode)! For your case, something like this: ``` call submode#enter_with('grow/shrink', 'n', '', '<leader><up>', '<C-w>+') call submode#enter_with('grow/shrink', 'n', '', '<leader><down>', '<C-w>-') call submode#map('grow/shrink', 'n', '', '<down>...
3,638
<p>I am using gvim 7.4 on Windows (32 bit) and using the <a href="http://www.vim.org/scripts/script.php?script_id=1191">wc</a> word-counting macro <code>:WC</code> by jcline. When I manually set a range and run the macro, e.g., <code>:'a,.WC&lt;CR&gt;</code>, I get the expected <code>counted XXX words</code> output. ...
[ { "answer_id": 3640, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 3, "selected": false, "text": "<p>You can't prevent Vim from erasing the status line. You can however make the output recallable, by changing <code>echo</...
2015/06/19
[ "https://vi.stackexchange.com/questions/3638", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1430/" ]
I am using gvim 7.4 on Windows (32 bit) and using the [wc](http://www.vim.org/scripts/script.php?script_id=1191) word-counting macro `:WC` by jcline. When I manually set a range and run the macro, e.g., `:'a,.WC<CR>`, I get the expected `counted XXX words` output. `:WC` produces this using `echo "counted " . wc_count ....
I found a solution thanks to the lead from @lcd047, which I greatly appreciate! I edited the script to run `redraw` before the `echo` per [`:help :echo-redraw`](http://vimdoc.sourceforge.net/htmldoc/eval.html#:echo-redraw). At least in my particular situation, the message now stays visible until I start scrolling. The ...
3,655
<p>I'm writing a script that does a search like so: <code>normal /needle^M</code>. This works like I want, except that I want to be able to use <code>n</code> or <code>N</code> to repeat the search. </p> <p>In case it helps, here's the full function:</p> <pre><code>function! MakeChoices() let start = line('.') ...
[ { "answer_id": 3657, "author": "Vitor", "author_id": 599, "author_profile": "https://vi.stackexchange.com/users/599", "pm_score": 1, "selected": false, "text": "<p>You probably are doing that inside a function, which will reset the <code>/</code> after it completes. From <code>:help quot...
2015/06/22
[ "https://vi.stackexchange.com/questions/3655", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2511/" ]
I'm writing a script that does a search like so: `normal /needle^M`. This works like I want, except that I want to be able to use `n` or `N` to repeat the search. In case it helps, here's the full function: ``` function! MakeChoices() let start = line('.') let choiceStartLine = search('^*choice', 'bW') ...
From [`:help function-search-undo`](http://vimhelp.appspot.com/eval.txt.html#function%2dsearch%2dundo) > > The last used search pattern and the redo command "." > will not be changed by the function. This also > implies that the effect of `:nohlsearch` is undone > when the function returns. > > > This is a bit...
3,670
<p>I have the following mappings to make it easy to move out of a terminal pane in neovim:</p> <pre><code>tnoremap &lt;C-h&gt; &lt;C-\&gt;&lt;C-n&gt;&lt;C-w&gt;h " Workaround since &lt;C-h&gt; isn't working in neovim right now tnoremap &lt;C-w&gt;h &lt;C-\&gt;&lt;C-n&gt;&lt;C-w&gt;h tnoremap &lt;C-j&gt; &lt;C-\&gt;&lt...
[ { "answer_id": 3765, "author": "Benoît Faucon", "author_id": 2646, "author_profile": "https://vi.stackexchange.com/users/2646", "pm_score": 6, "selected": true, "text": "<p>A terminal buffer name always starts with <code>term://</code>:</p>\n\n<p><code>autocmd BufWinEnter,WinEnter term:/...
2015/06/23
[ "https://vi.stackexchange.com/questions/3670", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/226/" ]
I have the following mappings to make it easy to move out of a terminal pane in neovim: ``` tnoremap <C-h> <C-\><C-n><C-w>h " Workaround since <C-h> isn't working in neovim right now tnoremap <C-w>h <C-\><C-n><C-w>h tnoremap <C-j> <C-\><C-n><C-w>j tnoremap <C-k> <C-\><C-n><C-w>k tnoremap <C-l> <C-\><C-n><C-w>l ``` T...
A terminal buffer name always starts with `term://`: `autocmd BufWinEnter,WinEnter term://* startinsert` Note that this will always put you in insert mode when you move to the terminal window, regardless of the mode you were using when leaving the window. --- You can also use a similar autocommand to always get bac...
3,680
<p>I have a line looking like this:</p> <pre><code>pattern1 any text pattern2 any text pattern2 any text pattern2 any text </code></pre> <p>And I want it to become:</p> <pre><code>pattern1 any text pattern1 pattern2 any text pattern1 pattern2 any text pattern1 pattern2 any text </code></pre> <p>and I'll be applying...
[ { "answer_id": 3685, "author": "Volker Siegel", "author_id": 925, "author_profile": "https://vi.stackexchange.com/users/925", "pm_score": 0, "selected": false, "text": "<p>Why not just replace <code>pattern2</code> by <code>\\n</code> <code>pattern1 pattern2</code>?</p>\n\n<pre><code>:%s...
2015/06/24
[ "https://vi.stackexchange.com/questions/3680", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2572/" ]
I have a line looking like this: ``` pattern1 any text pattern2 any text pattern2 any text pattern2 any text ``` And I want it to become: ``` pattern1 any text pattern1 pattern2 any text pattern1 pattern2 any text pattern1 pattern2 any text ``` and I'll be applying this to thousands of lines This command: `%s/\(...
That answer works for plain text, but not for patterns - you can't have patterns in the replace string unless you use an evaluated expression \=. I've figured this out: ``` :%s/pattern2/\="\r" . matchstr(getline('.'), 'pattern1') . submatch(0)/g ``` So in my actual file, I'd use ``` pattern1 = .\{-}: (everything ...
3,681
<p>On MS Windows using gVim, is it possible to select several files from the explorer and open them in the same instance of gVim in different buffers?</p> <p>At the moment if I select 3 different files on Windows graphical explorer and press <kbd>enter</kbd> they get open in 3 different instances of gVim. What I want ...
[ { "answer_id": 3693, "author": "mjturner", "author_id": 2582, "author_profile": "https://vi.stackexchange.com/users/2582", "pm_score": 3, "selected": true, "text": "<p>By default gVim for Windows adds an option to the Explorer right-click menu that contains an option <em>Edit with single...
2015/06/24
[ "https://vi.stackexchange.com/questions/3681", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
On MS Windows using gVim, is it possible to select several files from the explorer and open them in the same instance of gVim in different buffers? At the moment if I select 3 different files on Windows graphical explorer and press `enter` they get open in 3 different instances of gVim. What I want is to open them in ...
By default gVim for Windows adds an option to the Explorer right-click menu that contains an option *Edit with single Vim* when multiple files are selected and that works as expected, opening them in a single window. That doesn't handle pressing `Enter` with multiple files selected though. There is a solution presente...
3,682
<p>One of my friend told me that I can use the trick below to remove a pair of curly brackets.</p> <p>Put the cursor inside the curly bracket pair you want to remove.</p> <p><kbd>y</kbd> <kbd>i</kbd> <kbd>{</kbd> to yank the text in braces , then <kbd>v</kbd> <kbd>a</kbd> <kbd>{</kbd> then paste <kbd>p</kbd>. </p> <...
[ { "answer_id": 3693, "author": "mjturner", "author_id": 2582, "author_profile": "https://vi.stackexchange.com/users/2582", "pm_score": 3, "selected": true, "text": "<p>By default gVim for Windows adds an option to the Explorer right-click menu that contains an option <em>Edit with single...
2015/06/24
[ "https://vi.stackexchange.com/questions/3682", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2573/" ]
One of my friend told me that I can use the trick below to remove a pair of curly brackets. Put the cursor inside the curly bracket pair you want to remove. `y` `i` `{` to yank the text in braces , then `v` `a` `{` then paste `p`. It works well like: ``` for(int i = 0; i < s.length(); i++) { int index = s[...
By default gVim for Windows adds an option to the Explorer right-click menu that contains an option *Edit with single Vim* when multiple files are selected and that works as expected, opening them in a single window. That doesn't handle pressing `Enter` with multiple files selected though. There is a solution presente...
3,683
<p>This might be more suitable for IDE, not for Vim, but still I would appreciate if there was a way that would allow me to connect to either local or remote MySQL/SQLite databases. Is there such a way to do this?</p> <p>I think it could be placed in a split window or in its own tab. I would want to read, update, dele...
[ { "answer_id": 3708, "author": "Lerner Zhang", "author_id": 1788, "author_profile": "https://vi.stackexchange.com/users/1788", "pm_score": 1, "selected": false, "text": "<p>I'm myself trying to work it out these days. I think <a href=\"https://github.com/vim-scripts/dbext.vim\" rel=\"nof...
2015/06/24
[ "https://vi.stackexchange.com/questions/3683", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2530/" ]
This might be more suitable for IDE, not for Vim, but still I would appreciate if there was a way that would allow me to connect to either local or remote MySQL/SQLite databases. Is there such a way to do this? I think it could be placed in a split window or in its own tab. I would want to read, update, delete rows, i...
Even though I agree with @Vitor's comment saying that Vim is not meant to interact with a database, here is another solution: Tim Pope recently released [vim-dadbod](https://github.com/tpope/vim-dadbod) that he calls "a more modern take on dbext.vim" > > > ``` > DB is a Vim plugin for interacting with databases. > ...
3,694
<p>I would like to go to the file I just edited last and next kind of like MRU plugins do.</p> <p><code>:bnext</code> and <code>:bprev</code> works sometimes, but more often than not I just end up in some obscure file I don't remember editing and forced to fall back to MRU plugin.</p> <p>Is there a way to fix it?</p>...
[ { "answer_id": 504, "author": "Dhruva Sagar", "author_id": 74, "author_profile": "https://vi.stackexchange.com/users/74", "pm_score": 3, "selected": false, "text": "<p><code>&lt;C-6&gt;</code> is what you need, that takes you back to the previous buffer you had open before the current on...
2015/06/25
[ "https://vi.stackexchange.com/questions/3694", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/237/" ]
I would like to go to the file I just edited last and next kind of like MRU plugins do. `:bnext` and `:bprev` works sometimes, but more often than not I just end up in some obscure file I don't remember editing and forced to fall back to MRU plugin. Is there a way to fix it? `Ctrl-^` swaps between two last files. Wh...
I wrote a little function to repeatedly hit CTRL-O for me, until the buffer changes. You can find it [here](https://github.com/joeytwiddle/rc_files/blob/master/.vim/plugin/back_to_recent_buffer.vim). I mapped it to CTRL-U but you could override CTRL-O if you wanted to. ``` function! GoBackToRecentBuffer() let start...
3,697
<p>When writing a Vim help file, it's often useful to set the <code>filetype</code> to <code>help</code> to show syntax highlighting and such. But I find this annoying to work with when editing the document due to the "concealed" characters; my cursor behaves in "strange" ways and I often remove the concealed character...
[ { "answer_id": 3698, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": false, "text": "<h1>Asked: Setting the filetype</h1>\n\n<p>The autocommands in the question are a good start, and with 2 extra pieces o...
2015/06/25
[ "https://vi.stackexchange.com/questions/3697", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/51/" ]
When writing a Vim help file, it's often useful to set the `filetype` to `help` to show syntax highlighting and such. But I find this annoying to work with when editing the document due to the "concealed" characters; my cursor behaves in "strange" ways and I often remove the concealed characters by accident. I now set...
Asked: Setting the filetype =========================== The autocommands in the question are a good start, and with 2 extra pieces of knowledge we can finish it: * You can define autocommands everywhere. `autocmd` and `augroup` are "just" regular Vim commands, not special syntax or keywords. So defining an autocmd fr...
3,699
<p>I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work). </p> <p>Is there any command that I can type to enter Visual Block mode?</p> <p>Ideally I could set something up so that <code>:vb</c...
[ { "answer_id": 3701, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": false, "text": "<p>As far as I can find, there is no built-in command to start visual mode.</p>\n\n<p>However, you can easily add these...
2015/06/25
[ "https://vi.stackexchange.com/questions/3699", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2276/" ]
I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work). Is there any command that I can type to enter Visual Block mode? Ideally I could set something up so that `:vb` would enter visual bloc...
There is no built in command to start visual block mode in vim, but you can define one yourself: ``` command! Vb normal! <C-v> ``` Here is a breakdown of how it works: * `command! Vb` - This creates a command called "Vb". The `!` after `command` means that vim will not throw an error if the command is already defin...
3,704
<p>I'm trying to set a custom <code>breakat</code> for plain text files. Aiming for a very small set of characters -- just hyphens, slashes, and whitespace. That means I need to add tabs, which I do by setting <code>breakat+=^I</code>. (Right?)</p> <p>At first, I didn't understand how control characters worked, and ap...
[ { "answer_id": 3706, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 3, "selected": true, "text": "<p>You can do it like this:</p>\n\n<pre><code>let &amp;breakat = \"-/ \\t\"\n</code></pre>\n\n<p><code>set</code> syntax is w...
2015/06/26
[ "https://vi.stackexchange.com/questions/3704", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2593/" ]
I'm trying to set a custom `breakat` for plain text files. Aiming for a very small set of characters -- just hyphens, slashes, and whitespace. That means I need to add tabs, which I do by setting `breakat+=^I`. (Right?) At first, I didn't understand how control characters worked, and appended `^` `I` to my `breakat` v...
You can do it like this: ``` let &breakat = "-/ \t" ``` `set` syntax is weird, you probably want to avoid it if possible. Fortunately `set option=...` is equivalent to `let &option = ...`, and `let` syntax is nicer. In particular `let` allows you to use full expressions as values, such as the above. On a related to...
3,711
<p>I usually exit vim to open other files, I know it is not productive and I want to avoid it. I want to use <em>netrw</em> instead to open the files I want. Is there any way to prevent me from exiting vim, using <code>:x</code>, <code>:wq</code> and others ?</p> <p>I've found out <a href="http://www.vim.org/scripts/s...
[ { "answer_id": 3712, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p><strong>Update</strong>: I created a <a href=\"http://code.arp242.net/confirm_quit.vim\">confirm_quit.vim</a> plugin;...
2015/06/26
[ "https://vi.stackexchange.com/questions/3711", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1262/" ]
I usually exit vim to open other files, I know it is not productive and I want to avoid it. I want to use *netrw* instead to open the files I want. Is there any way to prevent me from exiting vim, using `:x`, `:wq` and others ? I've found out [this](http://www.vim.org/scripts/script.php?script_id=1072) script but it r...
**Update**: I created a [confirm\_quit.vim](http://code.arp242.net/confirm_quit.vim) plugin; it has some additional options, like only asking for confirmation when quiting the last buffer (rather than closing *any* buffer). I will leave the below code as-is because it demonstrates how you can achieve something like th...
3,716
<p>Some time ago I found an interesting trick on <a href="https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup/blob/master/.vimrc#L875-887" rel="noreferrer">Damian Conway's vimrc</a> which allows to open help files in new tabs instead of split windows. The code is the following:</p> <pre><code>"Only apply to ....
[ { "answer_id": 3717, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<p>We can open help in the current window by <code>set buftype=help</code> and then using the <code>:help</code> command...
2015/06/26
[ "https://vi.stackexchange.com/questions/3716", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
Some time ago I found an interesting trick on [Damian Conway's vimrc](https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup/blob/master/.vimrc#L875-887) which allows to open help files in new tabs instead of split windows. The code is the following: ``` "Only apply to .txt files... augroup HelpInTabs autocm...
We can open help in the current window by `set buftype=help` and then using the `:help` command. We have the following problems: * restore the `'buftype'` value of the previous buffer, `#`, in the success case * restore the `'buftype'` value of the current buffer, `%`, in the error case * let the `:h` error message t...
3,718
<p>I am wondering how to resize the gVim application on Windows 7. For example, I want to grab the corner of the window with my mouse and resize the application so it takes up more space on my screen. Does anyone know how to do this? This question seems silly, but searching on Google just brings back results on resizin...
[ { "answer_id": 3720, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>You can set the \n<a href=\"http://vimhelp.appspot.com/options.txt.html#E593\" rel=\"nofollow noreferrer\"><code>'lin...
2015/06/26
[ "https://vi.stackexchange.com/questions/3718", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1552/" ]
I am wondering how to resize the gVim application on Windows 7. For example, I want to grab the corner of the window with my mouse and resize the application so it takes up more space on my screen. Does anyone know how to do this? This question seems silly, but searching on Google just brings back results on resizing V...
You can set the [`'lines'`](http://vimhelp.appspot.com/options.txt.html#E593) and [`'columns'`](http://vimhelp.appspot.com/options.txt.html#E594) options from within Vim to resize the window. For example: ``` :set lines=55 :set columns=120 ``` You can add this to your vimrc file to do it automatically. This will w...
3,721
<p>The command is</p> <pre><code>nnoremap &lt;leader&gt;; :execute "normal! mqA;\&lt;esc&gt;`q" </code></pre> <p>If you then press <code>&lt;leader&gt;;</code>, you will <code>E114: Missing quote: "normal! mqA;\</code> followed by <code>E15: Invalid expression: "normal! mqA;\</code>. Why is this? The command works fi...
[ { "answer_id": 3722, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 3, "selected": false, "text": "<p>You need to escape the <code>&lt;ESC&gt;</code> in command mode. This is done by prefixing it with <code>&lt;C-v&gt;</co...
2015/06/26
[ "https://vi.stackexchange.com/questions/3721", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2604/" ]
The command is ``` nnoremap <leader>; :execute "normal! mqA;\<esc>`q" ``` If you then press `<leader>;`, you will `E114: Missing quote: "normal! mqA;\` followed by `E15: Invalid expression: "normal! mqA;\`. Why is this? The command works fine if input directly into the commandline. The command adds a `;` at the end...
You need to escape the `<` via `<lt>`: ``` nnoremap <leader>; :execute "normal! mqA;\<lt>esc>`q"<cr> ``` Note: added `<cr>` to execute the command as well. However this can be simplified quite a bit: ``` nnoremap <leader>; mqA;<esc>`q ``` Using an expression mapping you can make your mapping conditional based on...
3,725
<p>Say the following is the current structure of my window:</p> <pre> +-----+---------------------------- | | | A | | | +-----+ | | | B | </pre> <p>The order of A and B is not quite natural. It would be better if B was on top.</p> <p>However, if I go <code>&lt;C-w&gt;K</code>, B will be the very top ...
[ { "answer_id": 3750, "author": "Cometsong", "author_id": 2303, "author_profile": "https://vi.stackexchange.com/users/2303", "pm_score": 3, "selected": false, "text": "<p>In order to swap <code>window</code> positions, the effect is equivalent to swapping buffers that those two windows sh...
2015/06/27
[ "https://vi.stackexchange.com/questions/3725", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1097/" ]
Say the following is the current structure of my window: ``` +-----+---------------------------- | | | A | | | +-----+ | | | B | ``` The order of A and B is not quite natural. It would be better if B was on top. However, if I go `<C-w>K`, B will be the very top of all windows, which is not what I w...
To swap the two parts of a split window simply do: `<C-w> <C-r>`
3,726
<p>English language users probably don't have this trouble, but vim is pretty dumb when it comes to regular expressions. In my case most letters in the Turkish alphabet outside the EN alphabet don't seem to qualify as word characters.</p> <p>Given a document that contains a Turkish word:</p> <blockquote> <p>gerçekl...
[ { "answer_id": 3727, "author": "cxw", "author_id": 1430, "author_profile": "https://vi.stackexchange.com/users/1430", "pm_score": 3, "selected": false, "text": "<p>Looks like there's not an easy way to redefine <code>\\w</code>. See, for example, <a href=\"https://stackoverflow.com/a/19...
2015/06/27
[ "https://vi.stackexchange.com/questions/3726", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/267/" ]
English language users probably don't have this trouble, but vim is pretty dumb when it comes to regular expressions. In my case most letters in the Turkish alphabet outside the EN alphabet don't seem to qualify as word characters. Given a document that contains a Turkish word: > > gerçekleşiyor > > > The search...
`\w` is *explicitly* short-hand for `[0-9A-Za-z_]`. Use `\k` instead if you want to match Unicode characters outside of that range. For example, `/ger\kek` matches `gerçekleşiyor`. By the way, neocomplete is aware of this but intentionally *does not* use `\k` (by default) because of performance concerns. You can chan...
3,728
<p>My terminal doesn't allow me to type <kbd>Ctrl</kbd>+<kbd>W</kbd>, because that's a shortcut for closing a terminal tab.</p> <p>I like working with splits, but I can't find any way to do so without using <code>C-W</code>. This forced me to use tabs, because I can switch between them with <code>gt</code>, <code>gT</...
[ { "answer_id": 3729, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 6, "selected": true, "text": "<p>You can remap <code>&lt;C-w&gt;</code> to another combination, for example:</p>\n<pre><code>:nnoremap &lt;C-e&gt; &lt...
2015/06/27
[ "https://vi.stackexchange.com/questions/3728", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2612/" ]
My terminal doesn't allow me to type `Ctrl`+`W`, because that's a shortcut for closing a terminal tab. I like working with splits, but I can't find any way to do so without using `C-W`. This forced me to use tabs, because I can switch between them with `gt`, `gT` or `#gt` where # is a number, but I find this less conv...
You can remap `<C-w>` to another combination, for example: ``` :nnoremap <C-e> <C-w> ``` You can now use `<C-e>` and it will act as if you've pressed `<C-w>`. This will overwrite the default `<C-e>` mapping (scroll down). Vim already uses every key on the keyboard, and the only way to prevent this is using the lead...
3,730
<p>I'm trying to move my <code>.viminfo</code> file into my <code>.vim/</code> folder for cleaner syncing across multiple machines. (I have my <code>.vim</code> stored on Dropbox, and then create symlinks to it from my home directory.)</p> <p>So this morning, I found <a href="https://stackoverflow.com/a/6286925/486582...
[ { "answer_id": 3731, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>Assuming you didn't change it, the first item in <code>&amp;runtimepath</code> is your runtime directory by default:</p>\n\n...
2015/06/27
[ "https://vi.stackexchange.com/questions/3730", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2593/" ]
I'm trying to move my `.viminfo` file into my `.vim/` folder for cleaner syncing across multiple machines. (I have my `.vim` stored on Dropbox, and then create symlinks to it from my home directory.) So this morning, I found [this answer](https://stackoverflow.com/a/6286925/4865822) on how to do just that. Great! Unfo...
This should work and is platform/plugin agnostic: `fnamemodify(expand("$MYVIMRC"), ":p:h")`
3,732
<p>I've been working on modularizing &amp; converting a code in my <code>vimrc</code> into some self-contained and reusable bundles/plugins plugins. I've run into an issue with autoloading &amp; scope that I'm having difficulty understanding. I've read through <code>:h autoload</code>, <code>:h &lt;sid&gt;</code>, <cod...
[ { "answer_id": 3734, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 4, "selected": false, "text": "<p>I recommend this structure:</p>\n\n<pre><code>.\n└── myplugin\n ├── LICENSE.txt\n ├── README.md\n ├── autoload\n...
2015/06/27
[ "https://vi.stackexchange.com/questions/3732", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2207/" ]
I've been working on modularizing & converting a code in my `vimrc` into some self-contained and reusable bundles/plugins plugins. I've run into an issue with autoloading & scope that I'm having difficulty understanding. I've read through `:h autoload`, `:h <sid>`, `:h script-local`, but I'm still not quite clear on ho...
In the first case, the error you are getting is that you are trying to call a function prior to its existance. That is, Vim is progressing through your script. When it sees the `call` line, it hasn't yet processed the `function` line that creates what you want to call, resulting in the error `unknown function`. If you...
3,738
<p>Currently, I use this:</p> <pre><code>map &lt;F7&gt; &lt;Esc&gt;:if has("gui_running")&lt;Bar&gt;hi comment gui=bold&lt;Bar&gt;else&lt;Bar&gt;hi comment cterm=bold&lt;Bar&gt;endif&lt;LF&gt; </code></pre> <p>It turns comments bold in terminal or in GUI when I press <code>&lt;F7&gt;</code>.</p> <p>And I would like ...
[ { "answer_id": 3739, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 2, "selected": false, "text": "<p>This mapping is probably more suited to a mapping which calls a function, since it contains so many commands. Here ...
2015/06/27
[ "https://vi.stackexchange.com/questions/3738", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2620/" ]
Currently, I use this: ``` map <F7> <Esc>:if has("gui_running")<Bar>hi comment gui=bold<Bar>else<Bar>hi comment cterm=bold<Bar>endif<LF> ``` It turns comments bold in terminal or in GUI when I press `<F7>`. And I would like it also to toggle the bold text. Is there a way to do this? Something like: ``` if hi comm...
You can get the current settings of a highlight group with the [`:highlight`](http://vimhelp.appspot.com/syntax.txt.html#E415) command. For example: ``` :highlight Comment Comment xxx term=bold ctermfg=4 guifg=Blue ``` This will just output the text; there is (as far as I know), no VimScript function to get t...
3,740
<p>I have a file full of text (say Markdown or LaTeX). I would like to count the number of words in a part of this file. </p> <p>I know I can do <kbd>:! wc -w %</kbd> to run wc -w on the current buffer. And I know that I can yank the section of interest into a named register. I'm guessing there's a way to send a named...
[ { "answer_id": 3741, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": true, "text": "<p>You can use <kbd>g</kbd><kbd>CTRL+g</kbd>, which will give you:</p>\n\n<pre><code>Col 1 of 118-121; Line 1 of 5; Word...
2015/06/27
[ "https://vi.stackexchange.com/questions/3740", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/648/" ]
I have a file full of text (say Markdown or LaTeX). I would like to count the number of words in a part of this file. I know I can do `:! wc -w %` to run wc -w on the current buffer. And I know that I can yank the section of interest into a named register. I'm guessing there's a way to send a named register to the op...
You can use `g``CTRL+g`, which will give you: ``` Col 1 of 118-121; Line 1 of 5; Word 1 of 142; Byte 1 of 678 ``` You can also use this from visual mode, if you want to get the word count for just the selection, which is especially useful combined with text objects such as [`ip`](http://vimhelp.appspot.com/motion.tx...
3,746
<p>I'd like to open a file from another branch in the current git repository. I have seen <a href="https://stackoverflow.com/q/7856416/2072269">this SO question</a>, but the suggestions for combining it with Vim are cumbersome (pipe to Vim, open stdin, set filetype, etc. manually). Is there a simpler way that retains s...
[ { "answer_id": 3748, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 7, "selected": true, "text": "<p>You can use <code>:Gedit</code>/<code>:Gsplit</code>/<code>:Gvsplit</code>/... with the form <code>{revision}:{filena...
2015/06/28
[ "https://vi.stackexchange.com/questions/3746", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/205/" ]
I'd like to open a file from another branch in the current git repository. I have seen [this SO question](https://stackoverflow.com/q/7856416/2072269), but the suggestions for combining it with Vim are cumbersome (pipe to Vim, open stdin, set filetype, etc. manually). Is there a simpler way that retains syntax highligh...
You can use `:Gedit`/`:Gsplit`/`:Gvsplit`/... with the form `{revision}:{filename}` ``` :Gedit branch:/foo/bar.c ``` Note: If the file is the same as the current file you can abbreviate the command like so: `:Gsplit branch:%`. It is often the case that a diff of the current file is preferred than just opening the f...
3,760
<p>I've installed solarized with the bundled togglebg.vim plugin.</p> <p>In my vimrc I set <code>background</code> to <code>light</code> and <code>colorscheme</code> to <code>solarized</code>, so I have light background and matching font colors from solarized-light.</p> <p>When I change <code>background</code> to <co...
[ { "answer_id": 3828, "author": "Ankit Sultana", "author_id": 2704, "author_profile": "https://vi.stackexchange.com/users/2704", "pm_score": 2, "selected": false, "text": "<p>If you want to toggle background, add this to your <code>vimrc</code>, (edit mapping according to what you like)</...
2015/06/29
[ "https://vi.stackexchange.com/questions/3760", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2641/" ]
I've installed solarized with the bundled togglebg.vim plugin. In my vimrc I set `background` to `light` and `colorscheme` to `solarized`, so I have light background and matching font colors from solarized-light. When I change `background` to `dark` in my vimrc and restart vim, it starts with dark background and matc...
If you want to toggle background, add this to your `vimrc`, (edit mapping according to what you like) I use this on OS X 10.10.2 on `iTerm` ``` function! BgToggleSol() if &background == "light" execute ":set background=dark" else execute ":set background=light" endif endfunction nnoremap <leader>ct :ca...
3,761
<p>How can I find out if the vim I'm using is 32 or 64 bit? I'm using Ubuntu so <a href="https://vi.stackexchange.com/questions/3234/how-to-check-whether-vim-is-built-as-a-32-bit-or-64-bit-application">this</a> doesn't apply to me, I think. Also I checked</p> <pre><code>:version </code></pre> <p>and got this output:<...
[ { "answer_id": 3762, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 5, "selected": true, "text": "<p>Since you're on Ubuntu, use the <a href=\"http://manpages.ubuntu.com/file.1\" rel=\"nofollow noreferrer\"><code>file</code></a...
2015/06/30
[ "https://vi.stackexchange.com/questions/3761", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2645/" ]
How can I find out if the vim I'm using is 32 or 64 bit? I'm using Ubuntu so [this](https://vi.stackexchange.com/questions/3234/how-to-check-whether-vim-is-built-as-a-32-bit-or-64-bit-application) doesn't apply to me, I think. Also I checked ``` :version ``` and got this output: ``` VIM - Vi IMproved 7.3 (2010 Aug ...
Since you're on Ubuntu, use the [`file`](http://manpages.ubuntu.com/file.1) command: ``` $ file -L "$(command -v vim)" /usr/bin/vim.gnome: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=acb723f1249782755116f93ed45a30e7115ff423, stripp...
3,771
<p>Suppose that I'm editing a file, then I press <code>:w</code> to store it. And then I use <code>:e.</code> to navigate its containing folder in the netrw. Suppose its containing folder is <code>./A/B/</code>. In netrw, I open a file with path <code>./D/E</code>.</p> <p>My question is when I enter into the file <cod...
[ { "answer_id": 3772, "author": "Matt Boehm", "author_id": 680, "author_profile": "https://vi.stackexchange.com/users/680", "pm_score": 2, "selected": false, "text": "<p><code>:e %:h</code> navigates to the directory of the current file. See <code>:help expand()</code> for more info. Tim ...
2015/06/30
[ "https://vi.stackexchange.com/questions/3771", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1080/" ]
Suppose that I'm editing a file, then I press `:w` to store it. And then I use `:e.` to navigate its containing folder in the netrw. Suppose its containing folder is `./A/B/`. In netrw, I open a file with path `./D/E`. My question is when I enter into the file `./D/E`, how can I return to `./D/` or `./A/B/`? I tried ...
``` :E[xplore] ``` does the same thing as `:e %:h`, and is shorter to type. If you look up `:help :Explore`, you can see that there are also variations to open the directory of the current file in a new tab or split instead of in the current window.
3,773
<p>Is it possible to define a text object in vim that will act on a rectangular region? </p> <p>For instance, suppose I have vertically aligned columns of text, like this:</p> <pre><code>column 1 co column 2 col lumn 1 colu umn 2 column mn 1 column 2 column 2 c 1 column 1 olumn 2 colu </code></pre> <p>W...
[ { "answer_id": 3778, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 4, "selected": true, "text": "<p>Yes, this is possible. @PeterRincker suggests the plugin <a href=\"https://github.com/coderifous/textobj-word-colum...
2015/06/30
[ "https://vi.stackexchange.com/questions/3773", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2657/" ]
Is it possible to define a text object in vim that will act on a rectangular region? For instance, suppose I have vertically aligned columns of text, like this: ``` column 1 co column 2 col lumn 1 colu umn 2 column mn 1 column 2 column 2 c 1 column 1 olumn 2 colu ``` Would it be possible to define a t...
Yes, this is possible. @PeterRincker suggests the plugin [textobj-word-column](https://github.com/coderifous/textobj-word-column.vim), which defines four text objects (`ic`, `ac`, `iC`, and `aC`) for word-based columns. The idea behind this functionality is to create a function that defines a column based motion, and ...
3,782
<p>I have this function and mapping:</p> <pre><code>fun! TwiceToQuit() sil! q if v:errmsg == 'E37: No write since last change (add ! to override)' echohl ErrorMsg echo 'No write since last change, really quit?' echohl None if !exists('w:countofq') let w:countofq = 0...
[ { "answer_id": 3778, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 4, "selected": true, "text": "<p>Yes, this is possible. @PeterRincker suggests the plugin <a href=\"https://github.com/coderifous/textobj-word-colum...
2015/07/01
[ "https://vi.stackexchange.com/questions/3782", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2620/" ]
I have this function and mapping: ``` fun! TwiceToQuit() sil! q if v:errmsg == 'E37: No write since last change (add ! to override)' echohl ErrorMsg echo 'No write since last change, really quit?' echohl None if !exists('w:countofq') let w:countofq = 0 endif...
Yes, this is possible. @PeterRincker suggests the plugin [textobj-word-column](https://github.com/coderifous/textobj-word-column.vim), which defines four text objects (`ic`, `ac`, `iC`, and `aC`) for word-based columns. The idea behind this functionality is to create a function that defines a column based motion, and ...
3,789
<p>I'm using the <code>a"</code> motion rather often in vim; e.g. using <code>ca"</code> while refactoring a piece of code to replace a hardcoded argument with a variable name. The problem with this approach is that <code>a"</code> <a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#a%60">includes leading whites...
[ { "answer_id": 3790, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 3, "selected": false, "text": "<p>There is, in Wellle's <a href=\"https://github.com/wellle/targets.vim\" rel=\"noreferrer\">targets.vim</a> plugin. To q...
2015/07/02
[ "https://vi.stackexchange.com/questions/3789", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/117/" ]
I'm using the `a"` motion rather often in vim; e.g. using `ca"` while refactoring a piece of code to replace a hardcoded argument with a variable name. The problem with this approach is that `a"` [includes leading whitespace if there is no trailing whitespace](http://vimdoc.sourceforge.net/htmldoc/motion.html#a%60): >...
From <https://superuser.com/questions/537453/vim-copy-quoted-string-without-whitespace> : use `2i"` instead of `a"`. Also see `:help i'`.
3,792
<p>I have <code>'a</code> and <code>'b</code> bounding some lines of text. I want to convert all the <code>w</code>, <code>h</code>, <code>n</code>, and <code>m</code> variables to upper case. A sample line:</p> <pre><code>f(w,h,n,m) | w &lt;= 0 | h &lt;= 0 | n &lt; 0 | m &lt; 0 = 0 </code></pre> <p>It seems to me ...
[ { "answer_id": 3793, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 2, "selected": false, "text": "<p>Try this:</p>\n\n<pre><code>:'a,'b s/\\v(&lt;[whnm]&gt;)/\\U\\1/g\n</code></pre>\n\n<p>Short expl.:</p>\n\n<p><code>\\v...
2015/07/02
[ "https://vi.stackexchange.com/questions/3792", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2678/" ]
I have `'a` and `'b` bounding some lines of text. I want to convert all the `w`, `h`, `n`, and `m` variables to upper case. A sample line: ``` f(w,h,n,m) | w <= 0 | h <= 0 | n < 0 | m < 0 = 0 ``` It seems to me that this should work: ``` :'a,'b g/\<[whnm]\>/normal ~ ``` This doesn't work. It matches the line, but...
Try this: ``` :'a,'b s/\v(<[whnm]>)/\U\1/g ``` Short expl.: `\v` - very magic `(...)` - create 1st group `\U\1` - make 1st group uppercase Good references: [vimregex](http://vimregex.com/), [W.A.Zintz'](http://dahu.github.io/vim_waz_ere/)s articles --- To operate *on each match*, repeatedly, using a "normal-mo...
3,809
<p>I'm having the following CSS class structure </p> <pre><code>.mAIcon .mAIcon-reject .mAIcon-edit .mAIcon-accept .event </code></pre> <p>and so on.</p> <p>Inside my HTML files I want to autocomplete these class names.</p> <p>But when I type</p> <pre><code>&lt;span class="mAIcon mA|"&gt; </code></pre> <p>and I w...
[ { "answer_id": 3811, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 3, "selected": false, "text": "<p>Yes, you can define what characters are considered part of keywords with the <code>'iskeyword'</code> option:</p>\n\n<pre><c...
2015/07/03
[ "https://vi.stackexchange.com/questions/3809", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/350/" ]
I'm having the following CSS class structure ``` .mAIcon .mAIcon-reject .mAIcon-edit .mAIcon-accept .event ``` and so on. Inside my HTML files I want to autocomplete these class names. But when I type ``` <span class="mAIcon mA|"> ``` and I want to autocomplete the rest the only thing I get is ``` <span class...
I solved the problem by writing a small python script that creates a tag file. The script searches for CSS classes and prints a tag line for every class. At the moment I run the script by hand with ``` css_tags $file >> tags ``` which adds the files to the tags file. This works since tag completion isn't limited by...
3,814
<p>I recently realized that my <code>vimrc</code> is now more than 400 lines long (which IMO is too much I'll try to reduce that) and to make it easier to navigate, read and edit it I decided to investigate the concept of folding in vim <em>(which I wasn't familiar with)</em>.</p> <ul> <li>I tried to set the folding m...
[ { "answer_id": 3816, "author": "Gustav Blomqvist", "author_id": 2689, "author_profile": "https://vi.stackexchange.com/users/2689", "pm_score": 2, "selected": false, "text": "<p>Basic best practises: </p>\n\n<ul>\n<li><p>Divide into sections:</p>\n\n<ul>\n<li>Plugins</li>\n<li>Settings</l...
2015/07/03
[ "https://vi.stackexchange.com/questions/3814", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
I recently realized that my `vimrc` is now more than 400 lines long (which IMO is too much I'll try to reduce that) and to make it easier to navigate, read and edit it I decided to investigate the concept of folding in vim *(which I wasn't familiar with)*. * I tried to set the folding method to `indent` but I didn't l...
I have the following modelines at the bottom of my `vimrc` which I copied from godlygeek, the author of [tabular](https://github.com/godlygeek/tabular): ``` "" vim:fdm=expr:fdl=0 "" vim:fde=getline(v\:lnum)=~'^""'?'>'.(matchend(getline(v\:lnum),'""*')-2)\:'=' ``` This will make any line starting with 2+ `"`'s a fold...
3,821
<p>I already know that you can copy something to the a register using: (plus a yank, delete, etc. command)</p> <pre><code>"a </code></pre> <p>I also understand that you can append to the a register using:</p> <pre><code>"A </code></pre> <p>In addition I understand how to copy something to the clipboard register usi...
[ { "answer_id": 3822, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 3, "selected": false, "text": "<p>You can call <code>setreg('+', lines, 'a')</code>, but as far as I can tell there is no way to do that with normal mode c...
2015/07/04
[ "https://vi.stackexchange.com/questions/3821", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2695/" ]
I already know that you can copy something to the a register using: (plus a yank, delete, etc. command) ``` "a ``` I also understand that you can append to the a register using: ``` "A ``` In addition I understand how to copy something to the clipboard register using: ``` "+ ``` What do I type to append to the...
There is no normal mode command for that but you can simply append to another register and `:let` the clipboard register to the content of that register: ``` "Ay "Ay "Ay :let @+ = @A ```
3,831
<p>I need a vim shortcut to display all non-duplicate <code>struct</code> names in the file being edited. I have made <a href="https://stackoverflow.com/questions/31202598/search-and-print-all-non-duplicate-struct-names-inside-input-file">this C program</a> which does this, however I have to leave the editor and execut...
[ { "answer_id": 3826, "author": "Jason Basanese", "author_id": 2695, "author_profile": "https://vi.stackexchange.com/users/2695", "pm_score": -1, "selected": false, "text": "<p>A hot-fix is to just put in the following alias:</p>\n\n<pre><code>alias dim='cd /home/usr/Documents/; vim'\n</c...
2015/07/05
[ "https://vi.stackexchange.com/questions/3831", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2706/" ]
I need a vim shortcut to display all non-duplicate `struct` names in the file being edited. I have made [this C program](https://stackoverflow.com/questions/31202598/search-and-print-all-non-duplicate-struct-names-inside-input-file) which does this, however I have to leave the editor and execute the program in `bash` a...
First of all wherever you open vim, you have access to the whole filesystem from within vim. If you open vim without parameters or if you open a new buffer inside of vim with `:new` you can then save it to the drive with `:w \path\to\file` Then to access to those files you have a lot of different options. For example...
3,835
<p>The name of the language sometimes known as Vimscript is a topic of debate. Some places use Viml (or is it VimL?), others Vimscript. Does it have an official name, and if it does, what is it and since when is it official?</p> <ul> <li><a href="https://stackoverflow.com/q/4398312/2072269">SO question on VimL vs Vims...
[ { "answer_id": 3839, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": false, "text": "<p>The name <em>VimL</em> appeared in the documentation <a href=\"https://github.com/vim/vim/commit/fae66b13ff51f3c35832245dc2e...
2015/07/05
[ "https://vi.stackexchange.com/questions/3835", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/205/" ]
The name of the language sometimes known as Vimscript is a topic of debate. Some places use Viml (or is it VimL?), others Vimscript. Does it have an official name, and if it does, what is it and since when is it official? * [SO question on VimL vs Vimscript](https://stackoverflow.com/q/4398312/2072269) (~5 years old) ...
The name *VimL* appeared in the documentation [in July 2013](https://github.com/vim/vim/commit/fae66b13ff51f3c35832245dc2e43aa81b0d944f#diff-c1daf587351a4db5b6b54f1a86a5dd27). Vim's scripting language didn't have a name before that. *VimL* is the only name mentioned in the documentation. It doesn't really make it the ...
3,845
<p>How can I move X bytes forward, starting from the current cursor location (including line breaks)?</p> <p><a href="http://vimdoc.sourceforge.net/htmldoc/motion.html#go" rel="nofollow noreferrer"><code>[count]go</code></a> could be used to move forward X bytes from the start of the buffer. I tried <code>Shift + V, G...
[ { "answer_id": 3846, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 4, "selected": false, "text": "<p>This search moves 40 <em>chars</em> (not bytes, though) forward:</p>\n\n<pre><code>/\\_.\\{40}/e\n</code></pre>\n\n<p>b...
2015/07/06
[ "https://vi.stackexchange.com/questions/3845", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2720/" ]
How can I move X bytes forward, starting from the current cursor location (including line breaks)? [`[count]go`](http://vimdoc.sourceforge.net/htmldoc/motion.html#go) could be used to move forward X bytes from the start of the buffer. I tried `Shift + V, G, [count]go` (assuming that `[count]go` would start counting fr...
I ended up using the following solution, which implements the logic from my question. * `[count]GO` to move `[count]` bytes forward. * `[count]Go` to move `[count]` bytes backwards. Add this to your `.vimrc`: ``` function! JumpToByte(byte_nr) " See https://vi.stackexchange.com/a/3911/2720 for the byte counting b...
3,847
<p>How can I evaluate Ruby code on-the-fly when you are writing it?</p> <p>This is what it looks like:</p> <pre><code>5 + 5 # =&gt; 10 </code></pre>
[ { "answer_id": 3849, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 2, "selected": false, "text": "<p>Take a look at the <a href=\"https://github.com/SciRuby/iruby\" rel=\"nofollow\">IRuby</a> kernel for <a href=\"https://j...
2015/07/06
[ "https://vi.stackexchange.com/questions/3847", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/237/" ]
How can I evaluate Ruby code on-the-fly when you are writing it? This is what it looks like: ``` 5 + 5 # => 10 ```
Take a look at the [IRuby](https://github.com/SciRuby/iruby) kernel for [Jupyter](https://jupyter.org/) / [IPython](http://ipython.org/) and [ipython-vimception](https://github.com/ivanov/ipython-vimception). If you must do it in Vim itself you might try the [vim-ipython](https://github.com/ivanov/vim-ipython) plugin, ...
3,848
<p>I saw that you could display the current byte offset in the statusline using <code>%o</code>, but I found no function or command which does the same. Is there a way of getting the current byte offset pragmatically?</p>
[ { "answer_id": 3850, "author": "lcd047", "author_id": 1577, "author_profile": "https://vi.stackexchange.com/users/1577", "pm_score": 4, "selected": true, "text": "<p>Try this:</p>\n\n\n\n<pre><code>function! FileOffset()\n return line2byte(line('.')) + col('.') - 1\nendfunction\n</cod...
2015/07/06
[ "https://vi.stackexchange.com/questions/3848", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/865/" ]
I saw that you could display the current byte offset in the statusline using `%o`, but I found no function or command which does the same. Is there a way of getting the current byte offset pragmatically?
Try this: ``` function! FileOffset() return line2byte(line('.')) + col('.') - 1 endfunction ``` This returns the 1-based offset in file, which is the same as `%o` in `statusline`. You can, of course, subtract 1 to get the 0-based offset.
3,853
<p>I am porting autotools project to CMake. So, every directory of the project has <code>CMakeLists.txt</code> and <code>Makefile.am</code>.</p> <p>I want to make a split: <code>CMakeLists.txt</code> on one side and the corresponding <code>Makefile.am</code> on the other.</p> <p>I want to automatically arrange it so ...
[ { "answer_id": 3855, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 3, "selected": true, "text": "<p>As an alternative (pun!) maybe look into file switcher like <a href=\"http://www.vim.org/scripts/script.php?script_id...
2015/07/06
[ "https://vi.stackexchange.com/questions/3853", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2727/" ]
I am porting autotools project to CMake. So, every directory of the project has `CMakeLists.txt` and `Makefile.am`. I want to make a split: `CMakeLists.txt` on one side and the corresponding `Makefile.am` on the other. I want to automatically arrange it so that When on the one side file is opened, it has to open corr...
As an alternative (pun!) maybe look into file switcher like [a.vim](http://www.vim.org/scripts/script.php?script_id=31), [fswitch](https://github.com/derekwyatt/vim-fswitch), or [altr](http://www.vim.org/scripts/script.php?script_id=4202). These let you switch between related files. It is often used to switch between `...
3,862
<p>Sometimes in insert mode I hit <code>&lt;CR&gt;</code> by mistake and I have to hit the backspace multiple times (depends on the indentation) to get back where I was.</p> <p>e.g. </p> <pre><code>&lt;div&gt; &lt;p&gt; This is some text []&lt;/p&gt; &lt;/div&gt; </code></pre> <p>The cursor is <code>[]</code> and...
[ { "answer_id": 3864, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>How about:</p>\n\n<pre><code>inoremap &lt;C-\\&gt; &lt;C-o&gt;:left 0&lt;Cr&gt;&lt;BS&gt;\n</code></pre>\n\n<p><code>...
2015/07/07
[ "https://vi.stackexchange.com/questions/3862", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1821/" ]
Sometimes in insert mode I hit `<CR>` by mistake and I have to hit the backspace multiple times (depends on the indentation) to get back where I was. e.g. ``` <div> <p> This is some text []</p> </div> ``` The cursor is `[]` and I hit `<CR>` : ``` <div> <p> This is some text []</p> </div> ``` Now I have t...
How about: ``` inoremap <C-\> <C-o>:left 0<Cr><BS> ``` `<C-o>` will execute a normal mode command (`:left 0`), which will remove all indent, this will also put your cursor at the start of the line. `<BS>` will get you back to the last line. This is a bit like a "backwards `J`". Unfortunately, mapping Shift+Enter o...
3,869
<p>I have a file that contains words that I want to save, along with other junk that I do not need. I just want to delete everything except the words that contain a certain pattern. Take email addresses for example:</p> <p><code>foo foo foo foo foo foo@foo.com foo foo foo2@foo2.net</code></p> <p>Run some magic and s...
[ { "answer_id": 3871, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<h3>Easy way - <code>grep</code></h3>\n\n<p>The easiest technique is to use <code>:%!grep -o {pat}</code>. The <code>-o<...
2015/07/07
[ "https://vi.stackexchange.com/questions/3869", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/318/" ]
I have a file that contains words that I want to save, along with other junk that I do not need. I just want to delete everything except the words that contain a certain pattern. Take email addresses for example: `foo foo foo foo foo foo@foo.com foo foo foo2@foo2.net` Run some magic and save everything from `@` to th...
### Easy way - `grep` The easiest technique is to use `:%!grep -o {pat}`. The `-o`/`--only-matching` make grep only display the matches. ``` :%!grep -o 'foo\w*bar' ``` Note: that grep's regex's are a different variant from PCRE and Vim's. ### Pure Vim method with plugin - still easy For a pure native vim solution...
3,875
<p>I wonder if I can insert a new line without leaving normal mode. For example, I have two lines:</p> <pre><code>this is line one this is line two </code></pre> <p>And the cursor is on line one. Now I want a new line between line one and line two, like this:</p> <pre><code>this is line one this is line two </code>...
[ { "answer_id": 3877, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>I use a mapping for that:</p>\n<pre><code>&quot; Quickly insert an empty new line without entering insert mode\n nnorem...
2015/07/08
[ "https://vi.stackexchange.com/questions/3875", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2206/" ]
I wonder if I can insert a new line without leaving normal mode. For example, I have two lines: ``` this is line one this is line two ``` And the cursor is on line one. Now I want a new line between line one and line two, like this: ``` this is line one this is line two ``` I know that when I am in normal mode, ...
I use a mapping for that: ``` " Quickly insert an empty new line without entering insert mode nnoremap <Leader>o o<Esc> nnoremap <Leader>O O<Esc> ``` This way you can insert a line under your cursor with `<Leader>o` and one on the previous line with `<Leader>O`. **Note:** One could argue that it requires as...
3,879
<p>I have opened several files in vim (particularly, in vimdiff). They are opened in multiple (vertically split) windows.</p> <p>Is there a simple way, in which I can duplicate all this to another tab?</p> <p>I could write a function, which will open a new tab &amp; loop through all buffers in current tab to open in ...
[ { "answer_id": 3883, "author": "anishsane", "author_id": 2749, "author_profile": "https://vi.stackexchange.com/users/2749", "pm_score": 2, "selected": false, "text": "<p>Wrote this function. Worked for me.</p>\n\n<p>Note: This will only work for windows split vertically. This was suffici...
2015/07/08
[ "https://vi.stackexchange.com/questions/3879", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2749/" ]
I have opened several files in vim (particularly, in vimdiff). They are opened in multiple (vertically split) windows. Is there a simple way, in which I can duplicate all this to another tab? I could write a function, which will open a new tab & loop through all buffers in current tab to open in new tab using split/d...
You can use `:mksession` with a specialized `'sessionoptions'` to make this easier. ``` :set sessionoptions=blank,help,folds,winsize,localoptions :mksession :tabnew :source Session.vim ``` Using this technique we can create an easy to use command. Put the following command in your `vimrc`: ``` command! -bar Duplica...
3,885
<p>My question comes from this two commands I added on my <code>_vimrc</code> file:</p> <pre><code>nnoremap &lt;C-[&gt; :set columns+=1&lt;CR&gt; nnoremap &lt;C-]&gt; :set lines+=1&lt;CR&gt; </code></pre> <p>As is known, it will resize your gvim (I am using gvim on windows) with one more column when you hit <kbd>Ctrl...
[ { "answer_id": 3886, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 5, "selected": true, "text": "<p>You can do this with <code>|</code> (on windows, in the <code>_vimrc</code> file, so you have to replace it with <code>&lt;...
2015/07/08
[ "https://vi.stackexchange.com/questions/3885", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2206/" ]
My question comes from this two commands I added on my `_vimrc` file: ``` nnoremap <C-[> :set columns+=1<CR> nnoremap <C-]> :set lines+=1<CR> ``` As is known, it will resize your gvim (I am using gvim on windows) with one more column when you hit `Ctrl-[`, and one more line when you hit `Ctrl-]`. That is really cool...
You can do this with `|` (on windows, in the `_vimrc` file, so you have to replace it with `<bar>`). e.g. ``` " unix nnoremap <C-[> :set columns+=1 | lines+=1<CR> " windows nnoremap <C-[> :set columns+=1 <bar> lines+=1<CR> ``` See the documentation : `:help :bar` ref: <https://stackoverflow.com/a/3249303/2558252...
3,894
<p>I was looking at some of the special characters for use in a status line, and I found one that shows the percentage through file of displayed window (<code>%P</code>). However, I can find no way of getting this value through a function or a command that is provided by default. I did see that this is the value disp...
[ { "answer_id": 3895, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 2, "selected": false, "text": "<p>A simple way (line number accuracy):</p>\n\n<pre><code>function! LinePercent()\n return line('.') * 100 / line('$') ...
2015/07/08
[ "https://vi.stackexchange.com/questions/3894", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/865/" ]
I was looking at some of the special characters for use in a status line, and I found one that shows the percentage through file of displayed window (`%P`). However, I can find no way of getting this value through a function or a command that is provided by default. I did see that this is the value displayed by the `ru...
If you're really determined to do it, it can be done. A mostly accurate translation of the [source function](https://github.com/vim/vim/blob/master/src/buffer.c#L4405-L4434) might look like this: ``` function! Stl_P() let above = line('w0') - 1 let below = line('$') - line('w$') if below <= 0 retu...
3,897
<p>Whenever I open a tmux session in terminal, all of the tabs containing vim sessions are labelled <code>vim</code>. </p> <p>My question is: How to configure it to label tmux tabs with the name of the edited file or something like <code>vim | test.cpp</code> used as the title of the tabs in question.</p>
[ { "answer_id": 3898, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 5, "selected": true, "text": "<p>There you go : </p>\n\n<pre><code>autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system(\"tmux rename-window '...
2015/07/08
[ "https://vi.stackexchange.com/questions/3897", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2758/" ]
Whenever I open a tmux session in terminal, all of the tabs containing vim sessions are labelled `vim`. My question is: How to configure it to label tmux tabs with the name of the edited file or something like `vim | test.cpp` used as the title of the tabs in question.
There you go : ``` autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window 'vim | " . expand("%:t") . "'") ``` Decomposing : ``` autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call ``` On buffer read, file read or buffer new file event (see `:help autocmd-events`) execute ...
3,915
<p>I really like how the less pager uses <kbd>w</kbd> to scroll up and <kbd>z</kbd> to scroll down since they are single keys, in vim I have to use <kbd>CTRL</kbd>+<kbd>d</kbd>/<kbd>CTRL</kbd>+<kbd>f</kbd> to get the same effect. Having to hold <kbd>ctrl</kbd> is a bit of a nuisance. </p> <p>Of course I could just rem...
[ { "answer_id": 3898, "author": "nobe4", "author_id": 1821, "author_profile": "https://vi.stackexchange.com/users/1821", "pm_score": 5, "selected": true, "text": "<p>There you go : </p>\n\n<pre><code>autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system(\"tmux rename-window '...
2015/07/11
[ "https://vi.stackexchange.com/questions/3915", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2792/" ]
I really like how the less pager uses `w` to scroll up and `z` to scroll down since they are single keys, in vim I have to use `CTRL`+`d`/`CTRL`+`f` to get the same effect. Having to hold `ctrl` is a bit of a nuisance. Of course I could just remap the scroll keys, but that might break plugins, generate bad karma, etc...
There you go : ``` autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window 'vim | " . expand("%:t") . "'") ``` Decomposing : ``` autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call ``` On buffer read, file read or buffer new file event (see `:help autocmd-events`) execute ...
3,920
<p>I am trying to create a small plugin to learn vimscript, my goal is to create some functions processing a selected text and replacing it with the result. The script contains the following items:</p> <ul> <li><p><strong>Two functions processing text:</strong> they take a string as parameter an return the string whic...
[ { "answer_id": 3921, "author": "cxw", "author_id": 1430, "author_profile": "https://vi.stackexchange.com/users/1430", "pm_score": 1, "selected": false, "text": "<p>Build the command in a string and use <code>:exe</code> to run it. See <a href=\"http://vimdoc.sourceforge.net/htmldoc/eval...
2015/07/11
[ "https://vi.stackexchange.com/questions/3920", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1841/" ]
I am trying to create a small plugin to learn vimscript, my goal is to create some functions processing a selected text and replacing it with the result. The script contains the following items: * **Two functions processing text:** they take a string as parameter an return the string which should be used to replace th...
To answer your question: the prototype of `call()` in the manual is `call({func}, {arglist} [, {dict}])`; the `{arglist}` argument needs to be literally a List object, not a list of arguments. That is, you have to write it like this: ``` let @x = call(a:functionToExecute, [GetSelectedText()]) ``` This assumes `a:fun...
3,926
<p>I have a <code>LaTeX</code> file with a bunch of commands of the form <code>\label{&lt;word&gt;}</code> where the <code>&lt;word&gt;</code> represents a string that contains special characters, namely <code>á é í ó ú ý ð þ æ ö</code>. I'm looking for a quick way to change the special characters into a corresponding ...
[ { "answer_id": 3927, "author": "VanLaser", "author_id": 1800, "author_profile": "https://vi.stackexchange.com/users/1800", "pm_score": 4, "selected": true, "text": "<p>How about ... a substitution inside another one, and all thrown in a loop? E.g.</p>\n\n<pre><code>function! s:replaceSpe...
2015/07/12
[ "https://vi.stackexchange.com/questions/3926", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2804/" ]
I have a `LaTeX` file with a bunch of commands of the form `\label{<word>}` where the `<word>` represents a string that contains special characters, namely `á é í ó ú ý ð þ æ ö`. I'm looking for a quick way to change the special characters into a corresponding ASCII character(s): `a e i o u y dh th ae oe`. To give an e...
How about ... a substitution inside another one, and all thrown in a loop? E.g. ``` function! s:replaceSpecialChars(name) let from = ['á','é','í','ó','ú','ý','ð','þ','æ','ö'] let to = ['a','e','i','o','u','y','dh','th','ae','oe'] let i = 0 while i < len(from) exe '%s/' . a:name . '{\zs.\{-}\ze...
3,929
<p>Sometimes, I need to delete until a character up or down the same column.</p> <p>Consider a file with the following content:</p> <pre><code>abc def hij </code></pre> <p>When cursor is on <code>b</code>, doing a column-wise <code>dfi</code> should remove characters <code>b</code>, <code>e</code> and <code>i</code>...
[ { "answer_id": 3932, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 4, "selected": true, "text": "<p>You can use the <a href=\"https://github.com/machakann/vim-columnmove\"><code>vim-columnmove</code></a> plugin and visual-mode...
2015/07/12
[ "https://vi.stackexchange.com/questions/3929", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2295/" ]
Sometimes, I need to delete until a character up or down the same column. Consider a file with the following content: ``` abc def hij ``` When cursor is on `b`, doing a column-wise `dfi` should remove characters `b`, `e` and `i`. That means only the 1-character-width column of characters should be deleted. Is it p...
You can use the [`vim-columnmove`](https://github.com/machakann/vim-columnmove) plugin and visual-mode block-wise selection to do this. The plugin imitates various groups of motions, and in this case: > > columnmove-f > ============ > > > > > --- > > > columnmove-f and its variants are the commands for bringing...
3,944
<p>Every time I launch vim I have this in clipboard:</p> <pre><code>let g:netrw_dirhistmax =10 let g:netrw_dirhist_cnt =8 let g:netrw_dirhist_1=... let g:netrw_dirhist_2=... let g:netrw_dirhist_3=... let g:netrw_dirhist_4=... let g:netrw_dirhist_5=... let g:netrw_dirhist_6=... let g:netrw_dirhist_7=... let g:netrw_di...
[ { "answer_id": 4935, "author": "JJoao", "author_id": 3002, "author_profile": "https://vi.stackexchange.com/users/3002", "pm_score": 2, "selected": false, "text": "<p>This is a very bad answer (down-votes deserved)</p>\n\n<p>1) <strong>netrw</strong> has to do with history of remote files...
2015/07/14
[ "https://vi.stackexchange.com/questions/3944", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/237/" ]
Every time I launch vim I have this in clipboard: ``` let g:netrw_dirhistmax =10 let g:netrw_dirhist_cnt =8 let g:netrw_dirhist_1=... let g:netrw_dirhist_2=... let g:netrw_dirhist_3=... let g:netrw_dirhist_4=... let g:netrw_dirhist_5=... let g:netrw_dirhist_6=... let g:netrw_dirhist_7=... let g:netrw_dirhist_8=... `...
This is a very bad answer (down-votes deserved) 1) **netrw** has to do with history of remote files editing. (from: <https://stackoverflow.com/a/9850662/2991627>: **netrw** is a kind of vim plugin/script which supports reading and writing files across networks. .netrwhist is a history file which maintains all the di...
3,947
<p>I wonder how folks navigate efficiently with in a nerdtree window, for example if I'm in a folder like this:</p> <pre><code>├── m1.py ├── m1.pyc ├── m2.py ├── m2.py.bak ├── m2.pyc ├── main.py ├── matplotdemo.py ├── phonecount.py ├── haha ├── helloworld │   ├── someothercode.py │   └── source │   └── somecode.py...
[ { "answer_id": 3948, "author": "Pak", "author_id": 1115, "author_profile": "https://vi.stackexchange.com/users/1115", "pm_score": 3, "selected": false, "text": "<p>I usually use a combination of <code>j</code> and the <code>/</code> search (with the <code>incsearch</code> setting enabled...
2015/07/14
[ "https://vi.stackexchange.com/questions/3947", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2621/" ]
I wonder how folks navigate efficiently with in a nerdtree window, for example if I'm in a folder like this: ``` ├── m1.py ├── m1.pyc ├── m2.py ├── m2.py.bak ├── m2.pyc ├── main.py ├── matplotdemo.py ├── phonecount.py ├── haha ├── helloworld │   ├── someothercode.py │   └── source │   └── somecode.py ├── images_st...
I usually use a combination of `j` and the `/` search (with the `incsearch` setting enabled) to jump to where I want to be. In your example, I probably would have done something like `/hello<enter><enter>/sou/<enter><enter>j<enter>`. One thing I really like about this method is that I can search for any substring. Some...
3,951
<p>Many times in vim I would like to delete a line completely, so I use dd. However, I then need to paste that line into some other position within a line, but this inserts a newline before pasting, therefore, making it very difficult for me to get the desired result. For example,</p> <pre><code>while( pasteInHere ) {...
[ { "answer_id": 3952, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 2, "selected": false, "text": "<p>You can achieve something that works quite well with an <code>imap</code>. Add the following to your <code>vimrc</...
2015/07/14
[ "https://vi.stackexchange.com/questions/3951", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1305/" ]
Many times in vim I would like to delete a line completely, so I use dd. However, I then need to paste that line into some other position within a line, but this inserts a newline before pasting, therefore, making it very difficult for me to get the desired result. For example, ``` while( pasteInHere ) { cin >> n;...
You can go anywhere in the line above the line you want to delete, then press `JD` and paste it with `p` at the desired point. * `J` joins the two lines and moves you at the start of the text you wanted to delete. This deletes a new-line character and the indentation of the line you want to move. * `D` deletes from t...
3,968
<p>I'd like to trigger an <code>autocmd</code> on two events but not in a way it is usually done, i.e. if either of the events happened then trigger an <code>autocmd</code>. I want to trigger it if both events happened.</p> <p>For example:<br/> The usual way to do it</p> <pre><code>autocmd BufWrite,BufRead *.c *.py ...
[ { "answer_id": 3971, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 5, "selected": true, "text": "<p>An autocommand command is executed when one event occurs. You want a command to be executed after a sequence of events h...
2015/07/17
[ "https://vi.stackexchange.com/questions/3968", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2865/" ]
I'd like to trigger an `autocmd` on two events but not in a way it is usually done, i.e. if either of the events happened then trigger an `autocmd`. I want to trigger it if both events happened. For example: The usual way to do it ``` autocmd BufWrite,BufRead *.c *.py *.h :call StripTrailingWhitespaces() ``` Thi...
An autocommand command is executed when one event occurs. You want a command to be executed after a sequence of events has occurred. One way to do that is like this: ``` autocmd FileType c,cpp,python \ autocmd BufWritePre <buffer> call StripTrailingWhiteSpaces() ``` The `<buffer>` pattern causes the autocommand ...
3,973
<p>I have the following settings in my vimrc:</p> <pre><code>set listchars=tab:►-,eol:¬,trail:● </code></pre> <p>When I display unprintable characters in my makefile, I get something that looks like the following for one of the targets:</p> <pre><code>target:►prereq1►prereq2►►---prereq3►►---prereq4 </code></pre> <p...
[ { "answer_id": 3974, "author": "Lambert", "author_id": 2874, "author_profile": "https://vi.stackexchange.com/users/2874", "pm_score": 0, "selected": false, "text": "<p>It is because the <code>tab</code> spans 8 positions. Your <code>prereqX</code> text covers already 7 positions and ther...
2015/07/17
[ "https://vi.stackexchange.com/questions/3973", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2865/" ]
I have the following settings in my vimrc: ``` set listchars=tab:►-,eol:¬,trail:● ``` When I display unprintable characters in my makefile, I get something that looks like the following for one of the targets: ``` target:►prereq1►prereq2►►---prereq3►►---prereq4 ``` I expect to see the following: ``` target:►---p...
A tab advances to the next column whose position is a multiple of the tab stop. So, with `tabstop=4`, if your cursor is in column 7 and you press `Tab`, the cursor will advance only one column to column 8, as in the first tab in your example. Tabs are not constant width. You can visualize it thus—each `↓` is a tab sto...
3,985
<p>I'm attempting to get something setup that invokes the vimdiff git merge tool externally, but because of the way the setup works, I need to invoke vimdiff manually (without git mergetool). Does anyone know the exact command git runs with vimdiff to get the proper layout (three windows split horizontally and one vert...
[ { "answer_id": 3986, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 4, "selected": true, "text": "<p>I used the trick from <a href=\"https://stackoverflow.com/questions/10357374/is-it-possible-to-access-vims-command-line-argume...
2015/07/19
[ "https://vi.stackexchange.com/questions/3985", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2888/" ]
I'm attempting to get something setup that invokes the vimdiff git merge tool externally, but because of the way the setup works, I need to invoke vimdiff manually (without git mergetool). Does anyone know the exact command git runs with vimdiff to get the proper layout (three windows split horizontally and one vertica...
I used the trick from [this SO question](https://stackoverflow.com/questions/10357374/is-it-possible-to-access-vims-command-line-arguments-in-vimscript) to see what the command line was, and got this: ``` :exe '!tr "\0" " " </proc/' . getpid() . '/cmdline' :!tr "\0" " " </proc/23932/cmdline gvim -f -d -c wincmd J foo ...
3,990
<p>Is there a way to have vim not flag HTTP URLs and email addresses as spelling errors? Or, more generally, a way to list regexes of valid spellings?</p>
[ { "answer_id": 4003, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": true, "text": "<p>You can add custom syntax rules, and give them the\n<a href=\"http://vimhelp.appspot.com/spell.txt.html#spell%2dsynta...
2015/07/19
[ "https://vi.stackexchange.com/questions/3990", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2894/" ]
Is there a way to have vim not flag HTTP URLs and email addresses as spelling errors? Or, more generally, a way to list regexes of valid spellings?
You can add custom syntax rules, and give them the [`@nospell`](http://vimhelp.appspot.com/spell.txt.html#spell%2dsyntax) keyword, this will tell Vim not to apply spell checking to this syntax match. For example: ``` :syn match UrlNoSpell "\w\+:\/\/[^[:space:]]\+" contains=@NoSpell ``` The above will work for text f...
3,993
<p>I'm using vim and markdown for note taking.</p> <p>Sometimes I find some useful information online, so I'll copy and paste into vim like below:</p> <pre><code>useful information line1 useful information line2 useful information line3 useful information line4 </code></pre> <p>The annoying thing is, when I preview ...
[ { "answer_id": 3994, "author": "jax", "author_id": 1983, "author_profile": "https://vi.stackexchange.com/users/1983", "pm_score": 1, "selected": false, "text": "<p>Assuming you know about regular expressions, you can probably use substitution to match every line, and replace that line wi...
2015/07/20
[ "https://vi.stackexchange.com/questions/3993", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1276/" ]
I'm using vim and markdown for note taking. Sometimes I find some useful information online, so I'll copy and paste into vim like below: ``` useful information line1 useful information line2 useful information line3 useful information line4 ``` The annoying thing is, when I preview my markdown notes in html, these ...
Assuming you put the text with `"*p` you can remap this command to first do a substitution on the `*` register, such that every newline not preceded by two spaces is replaced by a newline preceded by two spaces. ``` nnoremap "*p :let @* = substitute(@*, '\(\S\S\)\(\n\)', '\1 \2', 'g')<CR>"*p ``` If you use a differ...
3,997
<p>I want to create a macro that will take a word <code>logThis</code>, which is selected in visual mode, and turn it into this:</p> <pre><code>console.log 'printing logThis' console.log JSON.stringify(logThis, undefined, 2) </code></pre> <p>I realize that I can get my macro to remember <code>logThis</code> by copyin...
[ { "answer_id": 3998, "author": "romainl", "author_id": 54, "author_profile": "https://vi.stackexchange.com/users/54", "pm_score": 4, "selected": true, "text": "<p>You could include this command at the beginning of your macro to save the current value of register <code>a</code>:</p>\n\n<p...
2015/07/20
[ "https://vi.stackexchange.com/questions/3997", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2897/" ]
I want to create a macro that will take a word `logThis`, which is selected in visual mode, and turn it into this: ``` console.log 'printing logThis' console.log JSON.stringify(logThis, undefined, 2) ``` I realize that I can get my macro to remember `logThis` by copying it with `yw` or some other register, but I mig...
You could include this command at the beginning of your macro to save the current value of register `a`: ``` let old_a = getreg(a) ``` yank the highlighted word to register `a`: ``` "ay ``` and reset register `a` once you are done: ``` call setreg("a", old_a) ``` Macros are great but there's always a point whe...
4,005
<p>I can run this snippit of code within a vimscript block:</p> <pre><code>0read /home/user/.vim/bundle/vim-lorum/lorums/lorum.js </code></pre> <p>As expected, it puts the contents of "lorum.js" into the current buffer</p> <p>But, I need to make this a little more dynamic. If I try something like:</p> <pre><code>le...
[ { "answer_id": 4006, "author": "EvergreenTree", "author_id": 865, "author_profile": "https://vi.stackexchange.com/users/865", "pm_score": 4, "selected": true, "text": "<p>This is because vim does not evaluate variable names or functions with most commands. In your case, vim thinks you l...
2015/07/21
[ "https://vi.stackexchange.com/questions/4005", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2312/" ]
I can run this snippit of code within a vimscript block: ``` 0read /home/user/.vim/bundle/vim-lorum/lorums/lorum.js ``` As expected, it puts the contents of "lorum.js" into the current buffer But, I need to make this a little more dynamic. If I try something like: ``` let g:filePath="/home/user/.vim/bundle/vim-lor...
This is because vim does not evaluate variable names or functions with most commands. In your case, vim thinks you literally want to read the contents of a file called `g:filePath` into the buffer. What you want can be accomplished with the `:execute` command. This command takes a string as an argument, and will then r...
4,009
<p><code>expand(&lt;cword&gt;)</code> gives me the word under the cursor, but it excludes symbols such as <code>@</code> or <code>.</code>. For example, if I call it at the end of <code>@word</code>, it will get me <code>word</code> and exclude the <code>@</code>.</p> <p>Is there a way that I could include symbols as ...
[ { "answer_id": 4011, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 5, "selected": true, "text": "<p>The characters that are included in a Vim <code>word</code> are set by the <code>'iskeyword'</code> option. See</p>\n\n<...
2015/07/21
[ "https://vi.stackexchange.com/questions/4009", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2897/" ]
`expand(<cword>)` gives me the word under the cursor, but it excludes symbols such as `@` or `.`. For example, if I call it at the end of `@word`, it will get me `word` and exclude the `@`. Is there a way that I could include symbols as part of the current word?
The characters that are included in a Vim `word` are set by the `'iskeyword'` option. See ``` :help <word> :help word :help 'iskeyword' ``` To add another character to this set, such as `.`, execute the following: ``` :set iskeyword+=. ``` See ``` :help :set+= ``` Note that the character `@` is special, so it ...
4,018
<p>I will frequently use visual mode and the "norm" command to quickly comment out several lines. </p> <p>Let's say this is my text (line numbers added for clarity):</p> <pre><code>1. #include &lt;iostream&gt; 2. using namespace std; 3. 4. int main() 5. { 6. cout &lt;&lt; "Hello world!\n"; 7. return 0;...
[ { "answer_id": 4020, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 4, "selected": true, "text": "<p>This has nothing todo with the <code>normal</code> command or the visual block. This is due to a setting <code>'for...
2015/07/23
[ "https://vi.stackexchange.com/questions/4018", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2920/" ]
I will frequently use visual mode and the "norm" command to quickly comment out several lines. Let's say this is my text (line numbers added for clarity): ``` 1. #include <iostream> 2. using namespace std; 3. 4. int main() 5. { 6. cout << "Hello world!\n"; 7. return 0; 8. } ``` And my cursor is on ...
This has nothing todo with the `normal` command or the visual block. This is due to a setting `'formatoptions'`, see [`:help 'formatoptions'`](https://vimhelp.appspot.com/options.txt.html#%27formatoptions%27). In particular, the mentioned behaviour comes from the flags `r` and `o`. If you don't like the behaviour, you ...
4,022
<p>Size of one file is 200 Mb, while the size of another file is 20 Mb. I need to press <kbd>ctrl</kbd>+<kbd>c</kbd> to stop loading the big file, when no vimdiff mode is enabled although I run:</p> <pre><code>vimdiff &lt;(hexdump -C r328.raw) &lt;(hexdump -C r328_000.raw) </code></pre> <p>so I am here now but I wou...
[ { "answer_id": 4025, "author": "CanadaRox", "author_id": 355, "author_profile": "https://vi.stackexchange.com/users/355", "pm_score": 4, "selected": true, "text": "<p>You could use use the <code>--length</code> option of hexdump to only load 20Mb of the large file so you don't have to ca...
2015/07/23
[ "https://vi.stackexchange.com/questions/4022", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2923/" ]
Size of one file is 200 Mb, while the size of another file is 20 Mb. I need to press `ctrl`+`c` to stop loading the big file, when no vimdiff mode is enabled although I run: ``` vimdiff <(hexdump -C r328.raw) <(hexdump -C r328_000.raw) ``` so I am here now but I would like to have colours for differences: [![enter...
You could use use the `--length` option of hexdump to only load 20Mb of the large file so you don't have to cancel what Vim is doing as @Carpetsmoker mentioned. Ex: ``` vimdiff <(hexdump -C --length=20000000 big) <(hexdump -C small) ```
4,027
<p>I am trying to create a (git) repository for my vim files. Now, I am already struggling as to what directory I would store my files under. As far as I can see there is either <code>%HOME%</code> or <code>%VIM%</code>, right? Naturally, I feel more inclined to use <code>%VIM%</code>. So I go</p> <pre><code>set VIM=x...
[ { "answer_id": 4028, "author": "Sardathrion - against SE abuse", "author_id": 622, "author_profile": "https://vi.stackexchange.com/users/622", "pm_score": 2, "selected": false, "text": "<p>I have a repository called <code>rc</code> which contains a <code>install.sh</code> script and all ...
2015/07/24
[ "https://vi.stackexchange.com/questions/4027", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/985/" ]
I am trying to create a (git) repository for my vim files. Now, I am already struggling as to what directory I would store my files under. As far as I can see there is either `%HOME%` or `%VIM%`, right? Naturally, I feel more inclined to use `%VIM%`. So I go ``` set VIM=x:\path\to\repo cd %VIM% notepad vimrc ``` t...
Since 7.4, all your configuration files (even your vimrc) are expected to be in this directory: ``` %userprofile%\vimfiles\ ``` But the name and location of that directory only matter to Vim. From Git's point of view, that directory could as well be `/etc/foo/bar/` without any impact whatsoever. So... 1. put your ...