Skip to main content
10 votes
Accepted

Advice to add `set nocompatible` as first line of .vimrc

Is there any advantages or side-effects of an explicit set nocompatible that I'm perhaps missing? Actually, there are many side-effects. Every time compatible is set or reset Vim rescans all options (...
Matt's user avatar
  • 21k
7 votes
Accepted

Parsing winlayout() For Toggling Multiple Windows At Once

Full restore If you want to restore layout with multiple termina buffers, you must restore other windows and buffers too, so it's in fact a full buffer layout restore, it's usage is not limited to ...
dedowsdi's user avatar
  • 6,298
7 votes

Advice to add `set nocompatible` as first line of .vimrc

One reason you might want to include a guarded set nocompatible in your .vimrc is that compatible will not be automatically unset if you specify the vimrc with the -u flag: Using the "-u" argument ...
Rich's user avatar
  • 32.3k
6 votes

How can I use different vim setting for different filename?

As I have written about extensively, the vim technique for this type of thing is called an ftplugin, which stands for filetype-plugin. What that means is that certain filetypes have different settings ...
D. Ben Knoble's user avatar
  • 26.8k
6 votes

How do I pick a line and write it to an external file?

You can use :[range]w >> file to append the given range to the given file. If the file does not yet exist, use the ! argument to the :w command to force writing the new file. So this means you ...
Christian Brabandt's user avatar
6 votes

Sorting superscript numbers

You can sort these symbols properly by using collation locale sort (modifier l): :%sort l For this to work, you need to have language collate setting set properly, for example: :language collate ...
Mass's user avatar
  • 14.2k
5 votes
Accepted

What does multiple key combinations over a paragraph in the manual mean? That they're synonyms?

They are tag synonyms. That is, any of them can be used to reach the same point whether by way of :help {tagname}, typing Ctrl+] when the cursor is over text of the form *{tagname}* or any of the ...
B Layer's user avatar
  • 20k
5 votes
Accepted

Run `vim -c <command>` before loading vimrc?

If you run vim --help you'll find the answer... $ vim --help | grep vimrc --cmd <command> Execute <command> before loading any vimrc file Some additional details under :help --cmd .....
B Layer's user avatar
  • 20k
5 votes
Accepted

Autocomplete ^X^F mode in another directory

The command to change the Vim current working directory is: :cd path/to/file For the current filename folder you can also use: :cd %:h Remark: There are also variants (lcd and tcd that changes the ...
Vivian De Smedt's user avatar
4 votes
Accepted

Why does ViM use VimScript?

Vim is written in C language. According to Wikipedia, Vim is written in both C and Vimscript, not only Vimscript. The source code of Vim is available here, on Github. The two biggest folders are /src: ...
ewen-goisot's user avatar
4 votes
Accepted

Why do I suddenly receive "Error detected while processing function <SNR>30_Highlight_Matching_Pair"?

The error you see, comes from the plugin matchparen, that is distributed with vim and which does highlight the matching parenthesis as you edit them. Internally is uses the searchpairpos() function. ...
Christian Brabandt's user avatar
4 votes
Accepted

How to escape a pipe (|) in my vimrc

Read :h 'lcs': "Two or three characters to be used to show a tab". First, the first one. Then the second one repeated as many times as needed. set lcs=tab:\|\|
Matt's user avatar
  • 21k
4 votes

Sorting superscript numbers

Because the superscript numbers are not numbers. They are symbols. Let's assume you are using unicode, then the symbols are represented by the hexadecimal codes 0x00b2, 0x00b3, 0x00b9, 0x8304, 0x8308. ...
Karl Yngve Lervåg's user avatar
3 votes
Accepted

Macro "oend^[Ores^[" results in new line "end2es". How?

When vim encounters ^[Or it interprets it as some kind of special key, for instance a function key. Which specific one vim thinks it is I'm not sure, but for comparison the <f3> key is often ^[...
Mass's user avatar
  • 14.2k
3 votes

Most efficient way to insert numbered columns into formatted text using standard Vim commands?

While I was experimenting with Rich's answer, I came up with :global/./put =line('.')|join Which can be shortened to :g/./pu =line('.')|j. And yes, you can adjust the range of :global—:3,25g/./pu =...
D. Ben Knoble's user avatar
  • 26.8k
3 votes
Accepted

Most efficient way to insert numbered columns into formatted text using standard Vim commands?

I’d actually do this using either filbranden’s answer or possibly a macro recording, but as you specifically requested an ex command that takes a 3,25 range, how about using a substitute command that ...
Rich's user avatar
  • 32.3k
3 votes

Most efficient way to insert numbered columns into formatted text using standard Vim commands?

I'd solve this using blockwise Visual mode and the g, Ctrl+A Visual mode command, that increments each line in the selection by a successive number, effectively creating an incrementing sequence. (See ...
filbranden's user avatar
  • 29.1k
3 votes
Accepted

How to delete a character that is present between two specific characters from every line in VIM?

This situation is frustrating. Technically speaking, the CSV file you describe is within MicroSoft's CSV spec - the double-quotes escape the comma, so it's not considered a separator. However, there'...
Ed Grimm's user avatar
  • 201
3 votes
Accepted

How to disable arrows in insert mode VIM

As discussed in the comments, YouCompleteMe is overwriting your mapping with its own. Normally, you can overwrite a setting that a plugin has made by using the .vim/after directory but in this ...
Rich's user avatar
  • 32.3k
3 votes

How can I remove the word "tabs" at the beginning of the tabbar in airline-vim?

The actual behavior occurs because of the vim-airline plugin and can be removed adding the following property to your vimrc: let g:airline#extensions#tabline#tabs_label = '' So there will be no more ...
baxbear's user avatar
  • 314
3 votes
Accepted

Why is `vmap` for both Visual *and* Select mode?

At the time we (maintainers of snippet/template engines) had mappings using :vmap which were targetting the select mode. I still have a few traces of that in my lh-brackets plugin. Also the mswin.vim ...
Luc Hermitte's user avatar
  • 17.6k
3 votes
Accepted

Moving to special marks inside opfunc

What I'm missing? :h '] "To the last character of the previously changed or yanked text." You must keep marks intact until you've done with all of them. Maybe :lockmarks or setline() or ...
Matt's user avatar
  • 21k
3 votes

Moving to special marks inside opfunc

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work. I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do ...
Peter Rincker's user avatar
3 votes
Accepted

Create new Highlight for C pointers

I think you want to add a positive look-ahead for the -> syntax (you could also use \ze or \zs, but that tends to cause problems with syntax because the text is consumed; with a look-ahead/behind, ...
D. Ben Knoble's user avatar
  • 26.8k
3 votes
Accepted

Any ergonomic way to shift block of code to left and right in vim and neovim?

If you are about shifting block of text left or right then :h gv you are using for the J and K does what you want: reselects previous visual selection: xnoremap H <gv xnoremap L >gv Note, ...
Maxim Kim's user avatar
  • 13.7k
3 votes

Autocomplete ^X^F mode in another directory

:!cd /path/to/foo doesn't do what you want because :! executes the external command cd in a subshell. Changing directory outside of Vim, either in a subshell or in its parent shell has no effect ...
romainl's user avatar
  • 41.4k
2 votes
Accepted

How to set colors for vim warnings about existing swap files

It is a bit surprising: my first guess was that one of ErrorMsg, Question, or WarningMsg would work. Turns out the highlight group you are looking for is MoreMsg, e.g.: :highlight MoreMsg guifg=red
Tae's user avatar
  • 2,135
2 votes

Empty space between two &

Try it like this: s/&\zs.\{-}\ze&/ /gc Disassembled: & is the literal ampersand \zs sets the start of the match .\{-} matches any characters - but as few as possible \ze sets the end of ...
Ralf's user avatar
  • 9,317
2 votes
Accepted

Modify syntax highlighting dynamically

As far as I know :h text-properties were designed with this in mind. The main use for text properties is to highlight text. This can be seen as a replacement for syntax highlighting. Instead of ...
Maxim Kim's user avatar
  • 13.7k
2 votes
Accepted

Rebinding i (enter insert mode) and Esc (enter normal mode) to Ctrl-Space

Add an l to the end of your existing imap. This will move the cursor to the right by one position. You might see a difference with column 1 though. I control this with an expression in a remap. ...
Chris Heithoff's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible