Configuring vi / vim ?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Configuring vi / vim ?
# 1  
Old 12-18-2014
Configuring vi / vim ?

Just got a new server running Oracle Linux 6 (a derivitive of RHEL, but I'm not sure the version correlation). This is my first hands on with this verision, having worked in the past with OL 5 (as well as some older Solaris, HPUX and AIX).

Connected with putty.

When I'm editing a file in INSERT mode and paste in a several lines I've copied out of some other source (pasting from the Windows clipboard), if the pasted text includes a comment ('#') every line following will be commented and indented - and with the indent increasing on each line -- each following line indented from the previous.

Obvoiously a config issue, but I've never actually tried to do any persistent configuration for vi. After googling a bit, came to no conclusion except that I do not have the commonly reference config files - vimrc, etc.

I'm not the SA and did not actually install the machine, but I do have root access for a while.

I'm open to any pointers. Especially for exactly what to look at to compare this config to one of my other machines that behave in what I would consider a 'normal' fashion. Smilie
# 2  
Old 12-18-2014
Generally, vi is configured by $HOME/.exrc (vi stands for visual ex, where the : part is ex). Steal a good one or lean out some of the stuff in yours. You can see options with ":se" which is akin to shell comand 'set -o', and displays if not given anything to set/unset. If your vi is vim, $HOME/..vimrc can hide $HOME/..exrc, so be careful.

The UNIX School: What is .exrc file for?
[Chapter 7] Advanced Editing

if vim:
A Good Vimrc

Last edited by DGPickett; 12-18-2014 at 04:58 PM..
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 12-18-2014
Using:
Code:
:set noautoindent

before you paste the text into your file will turn off automatic indentation. You probably don't want to always set noautoindent when you're manually editing new code, but you do want to turn it off before pasting in text that contains indented lines.

To turn automatic indentation back on, use:
Code:
:set autoindent

This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 12-19-2014
I've seen this problem too. It can be a real pain where indentation is critical.

Sometimes (not always), you can place the cursor at the beginning of what you just pasted and do
=G
to format to the bottom of the file.
Or just hilight the pasted text and format just that block with
=
# 5  
Old 12-19-2014
Quote:
Originally Posted by DGPickett
Generally, vi is configured by $HOME/.exrc <snip>
Thanks. After poking around a bit more with these and other links, I think I have a more fundamental question. I have neither a .exrc nor a .vimrc *anywhere* on any of my machines -- neither the new, misbehaving one nor any of my older "good" machines.

And I see this ..
on a 'good' machine:
Code:
--- Options ---
  cscopetag  history=50  ttyfast  t_Sb=^[[4%dm
  cscopeverbose       hlsearch  ttymouse=xterm2     t_Sf=^[[3%dm
  helplang=en  ruler  viminfo='20,"50
  backspace=indent,eol,start
  cscopeprg=/usr/bin/cscope
  fileencodings=utf-8,latin1
  formatoptions=tcql

and on the 'bad' machine:
Code:
--- Options ---
  helplang=enrulerviminfo='20,"50
  history=50ttyfastt_Sb=^[[4%dm
  hlsearchttymouse=xterm2     t_Sf=^[[3%dm
  backspace=indent,eol,start
  fileencodings=ucs-bom,utf-8,latin1
  formatoptions=tcql
  guicursor=n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block,a:blinkon0

(note - I pulled the above out of my putty logs. Unfortunately, logs did not capture the vi command I used to get that ouput, I don't remember what it was, and going back to find the web page that suggested it, I cant' find that either Smilie)

On both machines:
Code:
oracle:orcl$ find / -name '.exrc' 2>/dev/null

oracle:orcl$ find / -name '.vimrc' 2>/dev/null

oracle:orcl$

So at this point I'd like to just figure out how the two are different at all - regardless of the specifics of the differences. Without either of the two configuration files ...

---------- Post updated at 08:31 AM ---------- Previous update was at 08:26 AM ----------

Quote:
Originally Posted by Don Cragun
Using:
Code:
:set noautoindent

before you paste the text into your file will turn off automatic indentation. You probably don't want to always set noautoindent when you're manually editing new code, but you do want to turn it off before pasting in text that contains indented lines.

To turn automatic indentation back on, use:
Code:
:set autoindent

Don,
thanks for the feedback. Actually, I *do* want to turn it off permanently. I've never had it turned on on any system I've ever worked on. Didn't even know it was an option. I'm not against learning new tricks, but this isn't one of them. Smilie

See my previous reply. At this point -- after investigating further -- I'm more curious about determining why two systems are working differently at all. Neither system has either .exrc or .vimrc files. So how is it that the two behave differently at all?
# 6  
Old 12-19-2014
Did you check for different versions of vi and/or vim?
vi -v
vim -v
You might find an /etc/vimrc?
# 7  
Old 12-19-2014
Quote:
Originally Posted by ongoto
Did you check for different versions of vi and/or vim?
vi -v
vim -v
You might find an /etc/vimrc?
Bingo!
for vim versions, on the 'good' server I have version 7.0.237. On the 'bad' server I have version 7.2.411

And copying /etc/vimrc from the good server to my home directory on the bad, then doing a diff between that and the 'bad' /etc/vimrc, I see some difference. I'll explore those and reference back to the help links previously posted.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Vim :f

Can someone please tell me what this does? :f word I thought that was the way to save files with a different name but after a quick google search I saw it was like this. :w filename (4 Replies)
Discussion started by: cokedude
4 Replies

2. Solaris

Very Importan - Vim Settings - Error while opening a File using vim

I downloaded vim.7.2 and compiled the vim source . Added the vim binary path to PATH (Because iam not the root of the box) when i load the file using vim it throws me an error Error detected while processing /home2/e3003091/.vimrc: line 2: E185: Cannot find color scheme darkblue line... (0 Replies)
Discussion started by: girija
0 Replies

3. UNIX for Dummies Questions & Answers

pico vs vim

I always used pico as a text editor in Terminal or SSH. But what is the advantages/disadvantages between vim and pico? (7 Replies)
Discussion started by: timgolding
7 Replies

4. UNIX and Linux Applications

vim in solaris 10

Hi I tried to install vim7.2 in solaris 10 x86 , installation completed but not able to get vim to be use. dependency binary: gtk+ , glib & ncurses install dependency binary package and then install vim7.2. #pkgadd -d vim-7.2-sol10-x86-local $ pkginfo SMCvim application SMCvim vim ... (4 Replies)
Discussion started by: bangbong
4 Replies

5. UNIX for Dummies Questions & Answers

Vim: help with substitution

What is the appropriate command should i use to insert a character(example A) in front of line 1 to line 200...Pls help (7 Replies)
Discussion started by: 793589
7 Replies

6. UNIX for Advanced & Expert Users

vim

Does anyone know the fast way to go to tab/2 distance in vim. I mean set four spaces. (1 Reply)
Discussion started by: mirusnet
1 Replies

7. UNIX and Linux Applications

Help with Vim

How do I use compilers and syntax highlighting in (g)Vim? Specifically, I need a Common Lisp compiler and a C++ compiler. Thanks in advance! (Note: Disregard my other topic.) (1 Reply)
Discussion started by: led3234
1 Replies

8. UNIX for Advanced & Expert Users

About Vim

Hello, what is the maximum size of a file that we can open using vim. (3 Replies)
Discussion started by: nagalenoj
3 Replies

9. UNIX for Dummies Questions & Answers

Need some help with vim

I use vim for writing code. I was using nano but found that vim is a much advanced editor. I am trying to achieve something like this: When trying a loop or a function, I generally type: function name() {} Now when I take my cursor one position to the left and press the return key, it give... (4 Replies)
Discussion started by: Legend986
4 Replies

10. Solaris

Vim 7.0

I want to install VIM 7.0 from sunfreeware.com onto a server. The security guys are giving me a hard time because they found this security vulnerability. http://xforce.iss.net/xforce/xfdb/6259 This vulnerability came out in 2001, and it looks like it was mostly for linux, but I cant be... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies
Login or Register to Ask a Question