All Questions
14,010
questions
29
votes
5
answers
3k
views
How can I reformat a multi-line string in Vim when using the Python filetype?
Let's assume I am editing some Python code in Vim that looks a bit like:
myobj.myfunc("Some string parameter that goes on and on and on and on and sometimes doesn't"
"split ...
28
votes
5
answers
13k
views
Can I do an interactive :substitute (search & replace)?
Sometimes I use :s with a complicated regexp which may or may not be correct, or I'm not sure if I want to replace all matches.
Is there any way I can tell Vim to confirm every match it finds before ...
28
votes
2
answers
20k
views
File Type dependent key mapping
I'm trying to setup mappings for <C-]> that, depending on the buffer's file type, trigger different functions. For example, if I'm in a Javascript buffer, I want <C-]> to trigger :TernDef. ...
28
votes
4
answers
21k
views
Multiple cursors at desired location
I'm using vim-multiple-cursors plugin.
I would like to put cursors exactly where I want. For example ([x] are the cursor positions):
Lorem ipsum dolor sit amet[1], consectetur adipiscing elit,
sed ...
28
votes
5
answers
6k
views
Delete until the right end of the current inner block
Let's say that I have a code like this (| represents the cursor position):
func1(x|, func2(), y);
I would like to get:
func1(x|);
Is there a way to delete the code from the position of the cursor ...
28
votes
6
answers
6k
views
How can I really have some fun in Vim? [closed]
I love Vim. I spend my whole life using it: At work I develop code with Vim, I edit config files with it, I write my emails with it. At home I write my todo lists and my buckets lists with it. On my ...
28
votes
3
answers
15k
views
Can the split separator in vim be less than a full column wide?
I use a tiling window manager (awesome) + a terminal multiplexer (tmux) + splits inside of vim. I have no window decorations at all, so there is no visual split between them at all if the content of ...
28
votes
2
answers
8k
views
Make panes resize when host window is resized
I like to use vimdiff as a git diff/merge tool. The problem is when I resize the host terminal window to a new size: of the two split panes, the leftmost remain of the same width, while the rightmost ...
28
votes
2
answers
24k
views
Which directory to put color schemes?
In vim, I can put color schemes inside ~/.vim/colors/ folder. Where should I put color schemes so that NeoVim can pick them up?
28
votes
3
answers
18k
views
Jumping to a byte offset, and displaying position as byte offset
How can I move the cursor to the nth byte in the buffer?
How can I display the current cursor position in the ruler in terms of the byte offset, rather than lines and columns? (Follow-up question: ...
28
votes
5
answers
7k
views
How can I make Vim open help in a vertical split?
I usually work in a drop-down terminal, running about 25 characters high. Since I prefer tabs to windows1, usually a lot of horizontal space is wasted - around half of the terminal width.
On top of ...
28
votes
1
answer
4k
views
Disable <Esc> but keep <C-[>
For switching back from Insert mode I'm used to <Esc>. Now I'm looking to retrain myself to <C-[> instead of <Esc>. For that i need to disable <Esc> to help with the ...
28
votes
2
answers
10k
views
How do I open a new buffer without opening it in a split?
I know I can use :new to open a new buffer in a split window (defined by set splitbelow and set splitright).
But how can I just open a new, empty buffer without opening it in a split?
28
votes
1
answer
5k
views
After pressing qq, the status line says "recording". How do I get out of this mode?
I accidentally pressed qq, and now the status line says recording. What does that mean? How do I get out of this "recording" mode?
Pressing Esc doesn't work.
28
votes
2
answers
3k
views
Elastic Tabstops in Vim?
Is there a plugin or a built-in feature in Vim that allows for elastic tabstops? I've searched a bit, and I found some references saying it was not possible in Vim, but those were quite old.
Is ...
28
votes
1
answer
7k
views
End of python block motion
I need a motion that moves to end/beginning of a python block, and I need another motion that moves to begining/end of previous/next method/class (all combinations).
I've tried vim-indent-object, ...
27
votes
8
answers
12k
views
How to add permanent line numbers to a file?
I have a text file like this (using gVim on Windows)
foo bar baz quux
corge grault garply
waldo fred plugh
[...150 more lines...]
xyzzy thud
I want to add a number to each line in the file. Not ...
27
votes
11
answers
16k
views
Quickly calculate the total of a column of numbers
I'm writing down a markdown table which looks like this:
| 13/05/15 | 09:30-16:00 | 6.5 |
| 14/05/15 | 10:00-16:30 | 6.5 |
| 16/05/15 | 15:30-01:00 | 9.5 |
| 21/05/15 | 09:00-16:30 | 7.5 |
| 22/...
27
votes
3
answers
10k
views
What does `<Bar>` mean?
In answering a question just now, I mentioned using a normal mode key mapping that can be found at the Vim Tips Wiki. In the middle of explaining the key mapping, I realized that I had no idea what &...
27
votes
6
answers
15k
views
What are practical uses of the client-server mode?
I know that Vim allows a client server mode (:h clientserver): it is possible to turn it into a server which will get some commands and execute them and as a client which will send the commands to the ...
27
votes
4
answers
10k
views
How to edit content from the standard input?
I would like to edit content in vim which was dynamically generated from the command-line without having the file yet.
In example:
$ echo This is example. | vim /dev/stdin
$ cat /etc/hosts | vim /dev/...
27
votes
1
answer
14k
views
How to edit files non-interactively (e.g. in pipeline)?
I would like to edit files passed in pipeline input using vim in non-interactive way or edit files in-place (similar to sed).
Few examples using sed:
$ sed -i'.bak' s/foo/test/g file # Edit file ...
27
votes
2
answers
5k
views
How to save a file for which I have no write permissions?
Sometimes it happens that I open a file and make some modifications as my own
user, without noticing or "forgetting" to noticing the [read-only] warning in
the status line (ie. some random /etc config ...
27
votes
1
answer
33k
views
How to install NERDTree with Vundle?
I'm starting to use Vim and I chose Vundle instead of Pathogen.
I would like to know if I can install the NERDTree using Vundle.
I'm starting Vim and searching for NERDTree like this:
:BundleSearch ...
27
votes
3
answers
4k
views
Is there search and replace history in Vim?
We can retrieve search and replace history on IDEs and text editors.
Likewise is there a search history or a way to retrieve previously searched expression in Vim?
27
votes
2
answers
69k
views
How do I configure the Vim airline plugin to look like its own project screenshot?
I am trying to get the vim-airline up and running.
I have required it via vundle in my ~./vimrc:
Plugin 'bling/vim-airline'
I have installed it and expected my Vim to look like the screenshot on ...
27
votes
7
answers
7k
views
Move existing window to existing tab
Sometimes I need to move windows into an already existing tab, and I was wondering if there was a command/keyboard shortcut that could do this. I know I can close the window, switch to the tab, and ...
27
votes
1
answer
9k
views
Hand Placement for Vim Navigation
I'm a new Vim user, and I want to ask this somewhat elementary question in order to make sure I start learning Vim the right way and don't develop bad habits.
When you use Vim, how do you position ...
27
votes
2
answers
7k
views
Is there a way to AND events in the autocmd?
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 ...
27
votes
1
answer
5k
views
How to make movements respect camelCase or snake_case?
It is common to use either camelCase or snake_case to separate multiple words which form an identifier. It would be nice if the "word" movements (b, w, e) would detect those inner-identifier ...
26
votes
5
answers
1k
views
How can a complete beginner learn Vim using just Vim itself?
As a complete beginner with no vi experience, how can I learn to use Vim using just Vim itself? Is there a built-in tutorial, and how can I access it?
Assume I have a laptop with Linux and Vim ...
26
votes
8
answers
9k
views
Is there a best practice to fold a vimrc file
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 ...
26
votes
3
answers
9k
views
Automatically load Vi into insert mode
I use Vi as my preferred (and, in fact, only) text editor on Linux Systems. I know how to change modes from normal to insert, and vice-versa.
Is it possible to have Vi automatically load into Insert ...
26
votes
6
answers
2k
views
After copying a visual selection, return to original location
My cursor is in the middle of a paragraph when I decide suddenly I need to copy that paragraph:
So I type vip to select the paragraph visually:
Now I hit cmd+C to copy to clipboard (this may vary on ...
26
votes
4
answers
12k
views
How to enter insert mode when entering neovim terminal pane?
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 ...
26
votes
1
answer
17k
views
How to find what slows down Vim? [duplicate]
In some occasions, Vim respond is very slow. Is there a procedure to easily identify what causes the problem?
26
votes
7
answers
40k
views
Vim 8.0 Python support
I'm trying to upgrade my Vim installation to version 8.0, but it doesn't support both Python and Python 3 as the below image.
(PS: Because of this problem, I cannot use the YCM (YouCompleteMe) plugin ...
26
votes
1
answer
16k
views
Renaming variables
What is the simplest way to rename variables in Vim, without adding any new packages? Is there a way without using regexps, too?
26
votes
1
answer
7k
views
Can I map a Ctrl + upper-case letter separately from Ctrl + lower-case letter?
I am trying to figure out how to navigate windows little quicker, so I would like to map the following:
:nmap <silent> <C-F> :wincmd f<CR>
The problem is this remaps the ^f (lower-...
26
votes
1
answer
4k
views
What is the difference between "mapped key sequences" and "key codes"? (timeoutlen v ttimeoutlen)
The vim manual says we can use timeoutlen to specify the timeout length of mapped key sequences and can use ttimeoutlen to specify the timeout length of key codes:
A useful setting would be
:set ...
26
votes
0
answers
1k
views
How does `\zs` interact with syntax matches?
Consider the text:
foobarbaz
First we highlight the regular expression /foobar/:
:syntax match Special /foobar/
Next we highlight the regular expression /foobarbaz/:
:syntax match Error /foobarbaz/
...
25
votes
2
answers
28k
views
Insert tabs in INSERT mode when expandtab is set
I have set expandtab in my .vimrc file to convert tab to multiple space characters. However some files (like Makefile) need actual the tab character inserted.
Is there an easy way to force the ...
25
votes
4
answers
5k
views
How to replace inner text with yanked text
An editing pattern I frequently run into is the following: I want to yank a piece of text inside quotes or brackets, and replace that piece of text inside another pair of quotes/brackets.
For example,...
25
votes
2
answers
16k
views
Replace a pattern with current line number
I'd like to replace 'x' in this file with current line number. That is, change
x
x
x
to
1
2
3
For now, I use a Perl one-liner:
perl -pi -e '$x=$.; s/x/$x/' myfile.txt
I think UltraEdit can do it ...
25
votes
5
answers
2k
views
GitHub for .vimrc and plugins
I know many people store their .vimrc on GitHub to make it easier to get right to work on new machines, and that makes complete sense to me. Including plugins, however, is problematic, because the ...
25
votes
2
answers
10k
views
ale linter + eslint: Jump to next error
I use eslint with ale to lint my Javascript code. After editing a code block, I often have a few errors to fix. Fixing is done by navigating to the next erroneous line, reading the problem from the ...
25
votes
4
answers
16k
views
Don't add new line at the end of a file
Vim always adds a new line at the end of my files when saving, and it is causing errors in my PHP scripts.
How can I make vim not add this new line on save?
25
votes
3
answers
19k
views
What is the purpose of `s`?
What is the intended use case for the s command in normal mode?
I've been looking at it for some time, inadvertently pressing s, but can't find any use case that would make sense for me.
25
votes
4
answers
6k
views
How can I send just-yanked text to the clipboard?
If I've already yanked 37 lines, is there a way to send them to the clipboard without having to select them again?
I need to move those yanked lines into a GUI application.
25
votes
8
answers
4k
views
How can I source a visual selection of vimscript?
If I have a couple of lines of vimscript that I want to test before putting in my vimrc, is it possible to visually select, then source them?
I have tried
make visual selection v, then motions to ...