New answers tagged

0

This looks like the output of the netrw plugin. This can be disabled by entering in your ~/.vimrc file. let loaded_netrwPlugin = 1 Now if you try and edit a directory you'll get an error is a directory.


3

You can put the following lines in your vimrc to quit vim if any of its arguments are a directory: for f in argv() if isdirectory(f) echomsg "vimrc: Cowardly refusing to edit directory " . f quit endif endfor Alternatively, if you only want to quit if all arguments are directories, you can try something like this: let ndirs = 0 for f in argv()...


0

After analyzing the function GotoJump() described in the link: http://vim.wikia.com/wiki/Jumping_to_previously_visited_locations I figured out that you have to type the jump number in normal mode and then press CTRL+o


0

FYI recent fedora (at least since 18) installs that alias gobally in /etc/profile.d once vim-enchanced is installed.


6

In the replacement side of vim substitution, a newline is represented by \r. Thus, try: %s/\n\n/#\r\r/g The resulting file will look like: elephant# rhino# giraffe# /* animals who live in Africa */ In the first half of a substitute command, \n is a newline and \r is a carriage return. By contrast, in the replacement side of the command, \n is a ...


12

:2,$v/0$/d deletes the lines that don't end in 0 starting from the second one.


16

If you mean you want to keep every 10th line and delete the rest: %norm 9ddj Explanation: % whole file norm execute the following commands in "normal mode" 9dd delete 9 lines j move down one line (i.e. keep it) note: this deletes the first row. Adapted from http://www.rayninfo.co.uk/vimtips.html Or using the global command: Duplicate the first ...


0

The problem is that the color theme asks for more color than exist in the tmux terminal description, and vim is using bold to replace some of the missing colors. Rather than set -g default-terminal "tmux" use a terminal description which has a comparable number of colors, e.g., set -g default-terminal "tmux-256color" If your terminal database has "...


2

you can set global parameter in your .vimrc set hidden or specify hidden attribute for selected buffer using bufhidden. When the buffer is hidden (not abandoned like default) when you modify it outside vim you will be noticed that some changes occured and you can load new content or discard this changes.


1

The screenshots in the question do not show dtterm (some people are confused by the ability to set the TERM environment variable to dtterm, xterm, etc., while using other programs, supposing that those other programs are identical to dtterm, xterm). Here's a screenshot for instance from Oracle's documentation: Given that, it is unclear what actual ...


0

I hacked up something that "misuses" the available standard _scp bash completion function to enable completion of remote hosts/paths/files. A vim-wrapping function then mangles the returned paths in the form ho.st:/fol/der/fi.le into the vim-expected form scp://ho.st///fol/der/fi.le. vim () { local params=(); while [[ ! -z $1 ]]; do if [[ "$1" =~ ^[...


2

The command you are looking for is args: For example: :args /path_to_dir/*.py or :args /path_to_dir/**/*.py ** to match files recursively. (As suggested by @the_velour_fog) will open all files which has .py extension in the directory. Once the files are opened use :tab all to put them in individual tabs.


3

You can position the cursor on the first match using the -s (script) option. According to the vim manual: -s {scriptin} The script file {scriptin} is read. The characters in the file are interpreted as if you had typed them. The same can be done with the command ":source! {scriptin}". If the end of the file is reached before the editor exits, ...


0

I considered using the +/ command option which is documented in the man page as +/{pat} – For the first file the cursor will be positioned on the first occurrence of {pat}. However, the description in the man page is misleading, i.e., the cursor is actually placed on the first character of the first line that contains the search pattern, similar to how ...


1

Question had been solved at stackoverflow.com: Adding noremap <Esc>a h noremap <Esc>s j noremap <Esc>w k noremap <Esc>d l to .vimrc solved the problem.


2

On most installation I have come across: ALT-something is the same as: ESC (release after press) something So, vim commands are always "ALT-Prefixed". But, as you have found out in the meantime, there is a way to specify this key combination in the vimrc.


0

I've had the following in my ~/.vimrc for years: autocmd BufNewFile,BufRead /tmp/mutt* set noautoindent filetype=mail wm=0 tw=78 nonumber digraph nolist autocmd BufNewFile,BufRead ~/tmp/mutt* set noautoindent filetype=mail wm=0 tw=78 nonumber digraph nolist They tell vim to set those options when editing matching files. It works well for me. The only ...


1

You can use a shell script to hold the options, and set your editor variable to that. For example #!/bin/sh vim -c "set fo+=aw" "$@" The Mutt FAQ suggests a similar approach in How to trim quoted replies (like stripping signatures)?, though this is not generally material for an FAQ.


3

In my answer I will not concern myself with Vim, but instead look at the underlying mechanisms, that you have stumbled upon. It is important to understand these, as it affects the security of your entire system. It has nothing to do with owner: try it, make a file not owned by you, then give your self read not write. You will get the same results. So why is ...


5

With "wq", "!" asks Vim to ignore the read-only attribute. From the documentation: :wq [++opt] Write the current file and quit. Writing fails when the file is read-only or the buffer does not have a name. Quitting fails when the last file in the argument list has not been edited. :wq! [++opt] ...


4

Like the accepted answer, I don't think this is possible directly. However, I see at least two ways to still accomplish your goal. Running vim remotely ssh user@myserver sudo vim /some/file This has disadvantages: Your interactions with vim go over the network. Significant lag will be annoying, and if your connection dies, so does vim (eventually). ...


2

You would need the root password or have your public ssh key in ~root/.ssh/authorized_keys. Once you had that, you could probably do vim scp://root@nagios//tmp/notouch Bottom line: this is effectively just a shortcut for scp root@nagios:/tmp/notouch /tmp/notouch vim /tmp/notouch scp /tmp/notouch root@nagios:/tmp/notouch If you have the necessary access ...


8

I'm going to say this is not possible because vim is not executing remote commands. It is simply using scp to copy the file over, edit it locally and scp it back when done. As stated in this question sudo via scp is not possible and it is recommended that you either modify permissions to accomplish what you're wanting or just ssh across to the remote machine....


0

The tmux approach is to use three sessions: an outer session for the panes, an inner session for the windows (you can attach to this from one pane), a secondary view onto the inner session (for the other pane). Yes this is UNIX philosophy gone mad. Let's get started. # Create a session to hold the multiple windows $ tmux new-session -s inner <...



Top 50 recent answers are included