You are not logged in.

#1 2011-09-11 01:58:51

shadyabhi
Member
From: Bangalore
Registered: 2010-05-23
Posts: 262
Website

[SOLVED] /bin/bash: endif: command not found ERROR while saving in vim

My .vimrc file

set expandtab
set number
syntax on
set autoindent shiftwidth=4
set smartindent
set tabstop=4
set smartcase
colorscheme elflord
set incsearch
set hlsearch
au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif
" Tell vim to remember certain things when we exit
"  '10  :  marks will be remembered for up to 10 previously edited files
"  "100 :  will save up to 100 lines for each register
"  :20  :  up to 20 lines of command-line history will be remembered
"  %    :  saves and restores the buffer list
"  n... :  where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo
function! ResCur()
	if line("'\"") <= line("$")
	normal! g`"
	return 1
	endif
	endfunction

	augroup resCur
	autocmd!
autocmd BufWinEnter * call ResCur()
	augroup END

On some files, I get this error http://i.imgur.com/lKFvm.png at the bottom of vim . Please note that I get the error not on all files. Its driving me crazy!

Last edited by shadyabhi (2011-09-11 02:41:52)

Offline

#2 2011-09-11 02:04:11

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] /bin/bash: endif: command not found ERROR while saving in vim

Have you tried commenting out e.g.

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif

this line or maybe that ResCur() function?

Last edited by karol (2011-09-11 02:04:42)

Offline

#3 2011-09-11 02:14:41

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [SOLVED] /bin/bash: endif: command not found ERROR while saving in vim

Replace this:

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif

with this:

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent execute "!chmod a+x <afile>" | endif | endif

If the above doesn't work for you (though it should in Vim > 7), try a different way of doing the same thing:

function ModeChange()
	if getline(1) =~ "^#!"
		if getline(1) =~ "/bin/"
			silent !chmod a+x <afile> 
		endif
	endif
endfunction
au BufWritePost * call ModeChange()

Last edited by bohoomil (2011-09-11 02:29:58)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#4 2011-09-11 02:41:39

shadyabhi
Member
From: Bangalore
Registered: 2010-05-23
Posts: 262
Website

Re: [SOLVED] /bin/bash: endif: command not found ERROR while saving in vim

bohoomil wrote:

Replace this:

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif

with this:

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent execute "!chmod a+x <afile>" | endif | endif

Doing this solved the issue. Thanks.

Offline

Board footer

Powered by FluxBB