jamessan
  • Member for 6 years, 11 months
  • Last seen more than a month ago
How to detect whether swp files contain unsaved changes?
8 votes

Is it possible to only have .*.swp-files, when file on disk and file in vim are different? Yes. The snippet below (adapted from tpope's vimrc) will disable the swap file for a buffer when it isn'...

View answer
Match and replace very specific number
Accepted answer
7 votes

Instead of moving more logic into the regular expression, move more logic into the replacement. function! IncrementIf(fn, n) if a:fn(a:n) return n + 1 endif return n endfunction :%...

View answer
How to change Vim's :hardcopy printfont?
7 votes

Instead of printing from Vim, you could instead generate an HTML file using :TOhtml. Then you can use CSS to set the font used for the HTML and print that.

View answer
How to reverse the order of lines?
6 votes

In the spirit of functional VimL: :call setline(1, reverse(getline(1, line('$')))) getline(1, line('$')) returns a list of all the lines in the buffer. '$' is a special argument for line() which ...

View answer
Can add() and insert() be performed on a dictionary?
Accepted answer
6 votes

Dictionaries aren't ordered, so there's no need for add() or insert(). Values are added to a dictionary using either let d.foo = 'bar' or let d['foo'] = 'bar' syntax. I would also suggest ...

View answer
How is the `dict` attribute processed internally?
Accepted answer
6 votes

This is described at :help Dictionary-function: *Dictionary-function* *self* *E725* *E862* When a function is defined with the "dict" attribute it can be used in a special way with a ...

View answer
Why does vim use temporary file or pipe for shell commands?
Accepted answer
6 votes

How else do you expect Vim to retrieve the output of the commands? Your :%!ls writes the contents of the buffer to ls's stdin, reads the stdout from ls, and replaces the contents of the buffer with ...

View answer
Passing a # character to the shell in vimscript?
6 votes

shellescape({string}[, {special}]) has an extra, optional argument {special} which exists exactly for this purpose. When the {special} argument is present and it's a non-zero Number or a non-empty ...

View answer
How to copy from current line to the `n`-th line?
6 votes

The :[range]y[ank] [x] command allows specifying the range through the normal cmdline range syntax. In your example, you could use :.,20y to yank from the current line through line 20 into the ...

View answer
Indentation of preprocessor directives
Accepted answer
6 votes

This specific behavior is handled by the 'cinkeys' option. 'cinkeys' is similar to 'indentkeys' but is only used when 'cindent' is enabled. By default, it contains the 0# setting which causes the ...

View answer
searching duplicate words
Accepted answer
6 votes

:help /\w shows that \w is a regex metacharacter matching a word character -- any character that is either an underscore (_) or in the ranges 0-9, a-z, or A-Z. The example regex is parsed as \( ...

View answer
Did Vim ever use a different versioning scheme?
Accepted answer
6 votes

Yes, they were both caused by changes to the packaging and unrelated to Vim itself. The first epoch bump (since all packages without an explicit epoch have an implicit 0 epoch) was introduced when ...

View answer
How do I make vim look in a set of directories for a file, if it doesn't exist in the current directory?
Accepted answer
6 votes

Vim's 'path' option allows you to specify directories which commands like gf and :find will search for a file. If you only want this functionality to trigger for a specific set of files, then you ...

View answer
Define custom commands for the * and + registers
6 votes

A few <expr> mapping should be able to do the job here. The basic structure would be function! ClipboardOrXclip(command, register) if a:register !~ '[+*]' || has('xterm_clipboard') || has('...

View answer
What types of buffers are there?
6 votes

Those posts are incorrectly using the term buffer when they mean register. As aharris88's answer shows, a buffer typically represents a file that is currently being edited. There are buffers that ...

View answer
Prevent colorscheme from changing background color
Accepted answer
5 votes

If the background is changing, then the colorscheme is changing it. You can either choose a colorscheme that doesn't do that, or try overriding the colorscheme. autocmd ColorScheme * highlight ...

View answer
Specify UTF-8 encoding in Vimrc
Accepted answer
5 votes

It would be set encoding=utf-8, no quotes. set encoding="utf-8" would be an error because "utf-8" would be considered a comment, thus it would be the same as set encoding=. Vim does not actually ...

View answer
How to "find" or "till" a bigram?
5 votes

The sneak plugin provides that functionality. By default, it's bound to the s key, so you would need to use sts for your example. The documentation also gives example mappings to put sneak's ...

View answer
Set &viminfo differently in neovim and vim
Accepted answer
5 votes

I would suggest appending your specific additions to the viminfo option rather than duplicating default information. That is, set viminfo+=!. Additionally, it seems like setting the n option isn't ...

View answer
How to change buffer name for NeoVim Terminal special buffer
5 votes

You can change the name of any buffer by using the :file {name} command. However, doing so changes that alternate-file to the previous name, which you may not want in this case. The :keepalt command ...

View answer
How to repeat the last command in Ex?
Accepted answer
5 votes

:help E30 states The command-line is only stored in this register when at least one character of it was typed. Thus it remains unchanged if the command was completed from a mapping. It seems like ...

View answer
Why double negative regex matches when positive one doesn't?
5 votes

\W isn't understood as a character class inside a collection, so [^\Wub] is specifying Match any character other than \, W, u, and b. See :help /[ for the specifics about what can be used inside a ...

View answer
How to match a word ending with uppercase letter and a specific letter?
5 votes

It looks like you may have changed Vim's 'magic' option from its default to 'nomagic'. You can check this with the command :verbose set magic? As documented at :help /magic, 'nomagic' causes the . ...

View answer
Strange key combination: <CTRL-\><e> (in Cmdline mode)
Accepted answer
5 votes

:help CTRL-\Ctrl+D will show you all the help topics that contain CTRL-\. As you can see, there are a number of default keybindings that use CTRL-\. As to whether that will cause problems, well that ...

View answer
Absolute script-file line-numbers in Vim-function errors
Accepted answer
5 votes

There was an RFC suggesting this, but there was no response from Bram at the time.

View answer
Split same file into multiple windows "extending" each other
Accepted answer
4 votes

The 'scrollbind' option allows you to do what you want. Here's how you can set up 2 windows to scroll together: :vsplit to have two windows showing the same buffer. They start with the same ...

View answer
neovim doesn't change cursor in st terminal
Accepted answer
4 votes

This should be fixed in the release after 0.2.2. This was reported in neovim/neovim#7641 and the issue was that st's terminfo incorrectly specifies how to change the cursor shape. The fix in neovim ...

View answer
How to safely switch from vim-athena to vim-gtk?
4 votes

You don't have to uninstall any of the existing packages. The vim-{athena,gtk,gtk3,nox} etc. packages just provide the Vim binary built with different feature sets and linked against different GUI ...

View answer
Text manipulation by calling external binaries or scripts
4 votes

You can filter (part of) a buffer through an external command by using :{range}!{command}. The range of the buffer written to the external command is replaced by the output of the command. If you ...

View answer
Can I show the git diff status on a per-line basis?
4 votes

gitgutter and signify are two plugins I know of which provide this sort of functionality. When a buffer is saved, the sign column is updated to show where lines have been added/modified/deleted. ...

View answer