Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Saturday, July 15, 2023

Ubuntu customizations compendium

Do this when moving into a new Ubuntu machine on Windows Subsystem for Linux:

Brighten bash colors and brighten the bash prompt:

.bashrc

LS_COLORS='rs=0:di=1;35:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:';
export LS_COLORS

PS1='\e[37;1m\u@\h \e[35m\w/ \e[0m\$ '

------------------------------------

 

Turn off the bells

.inputrc:

 set bell-style none

------------------------------------

 More bells, brighten colors in VIM, and fix double-characters in VIM

.vimrc

 set background=dark
set t_u7=
set belloff=all

------------------------------------

 



Wednesday, November 2, 2016

My .vimrc customizations on OS X (MacOS)

I have bits and pieces of this scattered throughout this blog.  This is an effort to put it into one place. Don't be surprised if I add more to this post later.

Helpful customizations for .vimrc:

" This turns off the annoying bell every time I hit the wrong key
set visualbell

" The following two lines turn on syntax highlighting
filetype plugin indent on
syntax on

" This tells vim that I am using a black background and need light colored text
set background=dark

Wednesday, July 29, 2015

Brighter comments in vim

By default, colors in vim are too dark to read.  Brighten comments with the following vim command:

:hi comment ctermfg=blue

Another option is to tell vim that it is running a dark background:

:set background=dark

Put this in the .vimrc file so you do not have to type it in during every session:

set background=dark


Thursday, January 9, 2014

Turn off wordwrap in Vim

Turns off wordwrap in Vim --

:set nowrap

Turns it back on --

:set wrap


Saturday, December 21, 2013

Vim - How to add contents of external file to current buffer

This will insert the contents of test.txt into the buffer directly below the cursor:

:r ~/test.txt

r = Read contents

This will replace the buffer with the contents of test.txt:

:%!cat ~/test.txt

Breaking the above command down:

% = Entire contents of buffer
! = Run an external command
cat = Concatenate (display)
~ = Home directory
test.txt = Filename

The ! (bang) command lets us run external programs from the shell.  Of particular interest, we can run commands against the Vim buffer.  For example, the command below will run a shell sort command against the contents of the Vim buffer:

:%!sort %

The first % is necessary because it tells Vim we are about to do something to the entire contents of the buffer.  Everything after the !bang is the external command.

Another (silly) example - this runs the word count (wc) command:

:%!wc %
:%!wc

More realistic examples would use various external commands to chop up the contents of the Vim buffer - commands such as cut, sed, and so on.

Note to self:  There is a subtle difference here between appending the second "%" symbol in the first command and leaving it out in the second command.  This needs further investigation.

---

Shout out to my buddy Mark Moser for sending me a one-liner and making me remember/research this!  His one liner follows.

:r! cal 2014







Sunday, December 15, 2013

gvim font style and size

Put this in your .gvimrc file:

if has("gui_running")
  if has("gui_gtk2")
    set guifont=Inconsolata\ 16
  elseif has("gui_macvim")
    set guifont=Menlo\ Regular:h18
  elseif has("gui_win32")
    set guifont=Consolas:h11:cANSI
  endif
endif

This sets the font style and size depending on which environment you are running.  For example, I am running Mac OSX so my font is set to "Menlo Regular:h18".

Select your preferred font by looking at Edit | Font | Show Fonts
To reveal what that means to gvim, run this within gvim:

:set gfn?

For example, if I use the graphical menu to select "English Andale Mono | Regular | 24", the command "set gfn?" would reveal "guifont=Andale Mono:h24"

With that knowledge, we can craft what font we need to provide in the .gvimrc file from above.  Escape spaces with a backslash, so we get:

Andale\ Mono:h24

So my .gvimrc script line would read:

set guifont=Andale\ Mono:h24


Thursday, December 5, 2013

Turn off bells in Vim

:set visualbell

This tells Vim to flash the screen instead of ringing a bell.

To make it permanent, put it in your .vimrc file:


set visualbell



Wednesday, December 4, 2013

How to insert/remove comments in Vim

Insert comments (for example, the "#" symbol):

Go to the line you want to comment.
Press CTRL-V (might be CTRL-Q in Windows because of shortcut conflict)
Cursor to the last line
Press I, #, [Esc]
("I", then "#", then "Escape")
(Case matters.  Uppercase "I", not lowercase "i")




Remove comments:

Go to the line you want to comment.
Press CTRL-V (might be CTRL-Q in Windows because of shortcut conflict)
Cursor to the last line
Press x


Tuesday, November 26, 2013

Change dark blue comments in vim to a brighter color

Can't see comments and other dark blue text in a vim window? Try this:

:set background=dark


If you like it, you can make it permanent by adding this line to your ~/.vimrc file:


set background=dark