Tag Info

Hot answers tagged

25

While the original vi is still available, I do not think it is much used on current linux or BSD distributions;1 apparently it was dusted off in 2000 after having been mothballed a decade before that, and the last release was 2005. There are various implementations of vi around, which is really now a POSIX specification. These include nvi and elvis, but ...


15

If you are using Debian then vi is opening as vim because of the entry of vi in /etc/alternatives. Let me break this up for you. When you do ls -l /usr/bin/vi: lrwxrwxrwx 1 root root 20 Jul 1 2014 /usr/bin/vi -> /etc/alternatives/vi As you can see the vi binary is a symbolic link to /etc/alternatives/vi. Now if you do ls -l /etc/alternatives/vi: ...


9

On many Linux systems, the default vi really is a version of Vim, typically one compiled with fewer options (no built-in perl and python support, no GUI, etc) than the one you would get if you installed a Vim package. for example the arrow keys print ABCD instead of moving. This is caused by an inconsistency between your terminal emulator and Vim's ...


4

The original question has already been answered explaining that vi is an alias for vim, and that it is normal for the command vi to start vim. What should be noted is that vim is (in some setups) sensitive to which name it is called by. Even though vi and vim both execute the same binary they can behave differently.


3

To determine what editor to run, sudo checks three environment variables (in order): SUDO_EDITOR, VISUAL, and EDITOR, and uses the first editor it finds. (If it doesn't find one, it falls back to a default.) So you can make it run vimdiff instead of vim as follows: $ VISUAL=vimdiff sudoedit file1 file2 If your sudoers policy only lets you edit certain ...


3

It seems like if it's a tab. You can confirm this by placing your cursor on it and press ga in normal mode. If it displays <^I> 9, Hex 09, Octal 011 then it's a tab. A space looks like this: < > 32, Hex 20, Octal 040 To change each tab to a single space: %s/\t/ /g


3

This is nothing to do with the shell, or with the version of vim. It's a simple configuration thing, as the operation of backspace in insert mode is ordinary vim configurable behaviour. Specifically, it is vim's backspace setting. On one machine you (most probably) have that set to the empty string, and on another you have it set to include the value ...


3

This answer should really be a comment, but I do not have the reputation on this StackExchange yet. Anyway, vim is a superset of vi. Meaning, everything that works in vi works in vim. For all intents and purposes, it is a more extensible version of vi. for example the arrow keys print ABCD instead of moving. There are 2 solutions to this. Change ...


2

The SwapStrings.vim plugin allows to do this elegantly: :%SwapStrings car truck :%SwapStrings cat dog More alternatives can be found here.


2

:%s/match\$\zs\(\w\+\)\(.*match\$\)xxx/\1\2\1/ Explanation match\$\zs: anchor the match at the first match$; I use \zs to start the match after that, to avoid yet another capturing group \(\w\+\): capture the text after the first occurrence of match$ \(.*match\$\): capture what's after that, up to the second occurrence of match$, and capture that as we ...


2

To have search results highlighted, the option is hlsearch. According to the help it is off by default. So either use :set hlsearch or add it to your .vimrc. The command :nohlsearch turns the highlighting off temporarily, until the next search. To make the cursor position more obvious I also use set cul and set cuc to highlight the current line and ...


2

/\/var\/adm\> \< means start of a word (/var is not start of a word)


2

If you automate things with scripts and make scripts on a regular basis, you should automate the script creation...with a script. So instead of calling: vi some_new_program.py you should have a script newpy: #!/bin/bash echo '#!/usr/bin/env python' > "$1" echo '# coding: utf-8' >> "$1" echo '' >> "$1" chmod +x "$1" vi +3 "$1" Of course ...


2

Start just above the first function and jump to the opening brace with ]M. You can now jump to the next one with ]}]M (]} = closing brace, then ]M again), which is a bit long-winded, so map that to an f-key: :nmap <F9> ]}]M If you use "goldilocks" style indenting, e.g.: void foo (int bar) { This takes you to the same line as the signature -- ...


2

Alternatives Unless you really need special Vim capabilities, you're probably better off using non-interactive tools like sed, awk, or Perl / Python / Ruby / your favorite scripting language here. That said, you can use Vim non-interactively: Silent Batch Mode For very simple text processing (i.e. using Vim like an enhanced 'sed' or 'awk', maybe just ...


2

You can drop-ship text from the cut buffer with swap-pasting -- pasting into a selection swaps, so dwVP line-deletes everything but the deleted word. Start with Use three words. This is the first string of another block of strings. This is the second string of another block of strings. This is the third string of another block of strings. and do ...


1

Here is a fiddly solution. Please feel free to optimise it! Perhaps this might work in ~/vimrc? Open both files with sudoedit $ sudoedit file1 file2 Vertically split one buffer :vsp | b2 In each window, run :diffthis


1

One options is to use: if system("uname") == "Linux" set filetype off match ExtraWhitespace /\s\+$/ endif


1

From your description I suspect you're looking for enabling Paste mode in Vim. You may do this as follows: :set paste It can be disabled with :set nopaste This mode is useful when you copy-paste some code snippet from your OS buffer to Vim. This will prevent Vim from adding lots of extra spaces to line beginnings making pasted text look ugly.


1

automatic edition should be done using sed(1) (see man sed ) The commend your are looking for are sed -i -e s/old/new/g -e /deletethis/d -e '/^$/d' postgresdb.out I am not sure what you expect with :%s/\n\n//d. where -i means edit in place (usually sed will output edition do standard output) -e ... do the edition/deletion -e '/^$/d' shoudl delete ...


1

sed -e 's/\(match\)\([_[:alnum:]]*\)\(\(.*\)\n\)*/\1\ /2;tc' -e b -e :c -e 's//\1\2\4\2/' The above sequence will always handle only the first and second occurrence of match on a line - regardless of how many there may be on a line. It works by doing the the first s///ubstitution on the s///2cd occurrence of the pattern, then, if the substitution tests ...


1

:%s/\v(match\$(\w+).*match\$)xxx/\1\2/ \v very magical (we can use less \\)


1

Try this: sed -e 's/\(match\$\)\([a-zA-Z_]\+\)\([a-zA-Z ]\+match\$\)[a-zA-Z]\+/\1\2\3\2/' < input.txt > output.txt Using an input.txt of: text match$something_here and match$xxx blablabla text match$something_else_here and match$xxx blablabla I get an output.txt of: text match$something_here and match$something_here blablabla text ...


1

You can use the \= special replacement which allows to run vim code: For instance, to swap foo and bar: %s/foo\|bar/\=submatch(0) == "foo" ? "bar" : "foo"/g Or for your example: %s/ca[rt]/\=submatch(0) == "car" ? "truck" : "dog"/g See: :h sub-replace-expression for details.


1

The [:foo:] bracket expression is meant to be used inside a [...] collection, like this: :g/[[:digit:]]/s/1/2/g This allows you to specify multiple (alternative; otherwise it would be concatenation) groups, and mix with other characters, e.g.: [[:space:][:digit:]abc].


1

I think you are looking for :tabe +set\ nomodifiable|set\ ro filename Using + after tabe lets you specify a set of commands to run when opening the file. For more details, see :help +cmd If this is something you do often, you can set up a custom command to do this for you :command! -nargs=+ -complete=file Tabread tabe +set\ nomodifiable|set\ ro ...


1

This is either triggered by a mapping or an autocmd (that subsequently somehow inactivates itself). You can capture a full log of a Vim session with vim -V20vimlog. After quitting Vim, examine the vimlog log file for suspect commands. You can also list suspecting autocmds via :verbose autocmd CursorMoved.


1

One possible incremental security improvement would be to replace: user ALL=(ALL) /usr/bin/vim /etc/httpd/confs/httpd.conf with user ALL=(ALL) /usr/bin/rvim /etc/httpd/confs/httpd.conf and then have the user run sudo rvim /etc/httpd/confs/httpd.conf instead. Vim supports a restricted mode triggered with the -Z command line option or by starting the ...


1

You can jump between tags using visual operators, in example: Place the cursor on the tag. Enter visual mode by pressing v. Select the outer tag block by pressing a+t or i+t for inner tag block. Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press o or O to jump to opposite tag. Now you can ...



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