Tag Info

Hot answers tagged

4

I understand your question as your long lines being wrapped around and you can't easily see where the two lines for the comments start and end. There are various options: 1) activate line numbers with :set nu, or 2) prevent wrapping by :set nowrap. What is preferable depends on whether you want to see the whole lines without scrolling or not.


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 ...


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 ...


2

As St├ęphane Chazelas pointed out by using the vim help with :h :m it states the following: :[range]m[ove] {address} *:m* *:mo* *:move* *E134* Move the lines given by [range] to below the line given by {address}. Therefore by moving line 1 below line 3 the result is as stated in the question. ...


2

Try :set mouse=a, should be what you're looking for. Edit: As a side note, when you try to scroll through the file (as in two-finger scroll on a touchpad, for example), the text may not highlight as you'd expect. However, if you click where you want to start, then simply drag the mouse down, then everything should highlight as the mouse moves and the page ...


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

Commands like :copy and :move put the target below the line given by {address}. You can use an address of 0 to move to the first line. Some commands (like :put) also support a reversal of before / after via :put!


1

Without using mouse you can select lines in Vim. Get out of insert mode, hit one of the options below, and then move up or down a few lines. You should see the selected text highlighted. V - selects entire lines v - selects range of text ctrl-v - selects columns gv - reselect block After selecting the text, try d to delete, or y to ...


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 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