LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 01-15-2008, 09:39 PM   #1
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Rep: Reputation: 30
[FIXED] Vim map CTRL-S indenting problem


In my vimrc file, I have mapped CTRL-S in all modes to save my file. However I have a small problem.

Here is my .vimrc file:
Code:
nnoremap <C-s> :update<CR>
cnoremap <C-s> <Esc>:update<CR>
inoremap <C-s> <Esc>:update<CR>a
If I manually an indenting with the TAB key a few times and then hit CTRL-S, there are no problems.

But, I use C-indention (set cindent), so when I am writing code and I hit ENTER on certain lines, Vim will automatically indent me several tabs appropriately. When I have been indented automatically by Vim, and then I press CTRL-S, it will save but then Vim unindents my cursor.

I want to find a way to keep my cursor indented I hit save (after I have been auto-indented by Vim).

Last edited by sadarax; 01-16-2008 at 08:43 PM. Reason: Solved
 
Old 01-16-2008, 04:33 PM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,061

Rep: Reputation: 214Reputation: 214Reputation: 214
The best place to get help on vim is probably the user mailing list at vim.org. It's a busy list and there are many people who can help there.
 
Old 01-16-2008, 08:44 PM   #3
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by dive View Post
The best place to get help on vim is probably the user mailing list at vim.org. It's a busy list and there are many people who can help there.
Thanks, they were very helpful.

Solution:

Code:
inoremap <C-s> <Space><BS><C-\><C-O>:update<CR>
 
Old 01-16-2008, 09:01 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,061

Rep: Reputation: 214Reputation: 214Reputation: 214
Out of curiosity, how did you stop ctrl-s/q from doing xoff/xon?
 
Old 01-16-2008, 10:55 PM   #5
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by dive View Post
Out of curiosity, how did you stop ctrl-s/q from doing xoff/xon?
I don't understand your question.
 
Old 01-17-2008, 08:11 AM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,061

Rep: Reputation: 214Reputation: 214Reputation: 214
Ctrl-s is usually bound in most terminals to xoff, which means it stop outputs in the terminal (actually comes from modems and serial line terminals - data off). Ctrl-q is bound to xon and restarts output. Useful if you have a lot of output scrolling by - you use ctrl-s to freeze output so it can be read.

To be able to bind ctrl-s to a command in vim I would have thought you would have to be able to turn off this behaviour, unless you are using a terminal that doesn't support xon/xoff. Most do but I'm not sure about konsole or gnome terminal. I know rxvt, mrxvt, xterm do.
 
Old 01-17-2008, 01:52 PM   #7
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by dive View Post
Ctrl-s is usually bound in most terminals to xoff, which means it stop outputs in the terminal (actually comes from modems and serial line terminals - data off). Ctrl-q is bound to xon and restarts output. Useful if you have a lot of output scrolling by - you use ctrl-s to freeze output so it can be read.

To be able to bind ctrl-s to a command in vim I would have thought you would have to be able to turn off this behaviour, unless you are using a terminal that doesn't support xon/xoff. Most do but I'm not sure about konsole or gnome terminal. I know rxvt, mrxvt, xterm do.
That is interesting because I have never encountered that before. I normally use the /dev/ttys or Konsole. I did nothing special. I just bound the key and it seemed to work.
 
  


Reply

Tags
save, vim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vim auto indenting? kryptobs2000 Linux - Software 2 10-20-2007 03:11 PM
VIM - How to map Ctrl-F5? BiThian Linux - General 6 10-26-2006 04:15 PM
Vim map - to _ and the reverse sadarax Linux - Software 1 08-27-2006 10:52 PM
disable indenting in VIM Ygrex Linux - Software 3 12-24-2005 04:07 AM
vim and fortran smart-indenting s_siouris Linux - Software 0 11-23-2004 05:00 AM


All times are GMT -5. The time now is 04:34 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration