LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1137|回复: 10

已解决:vim恢复光标位置(同样的配置文件,debian下可以实现,gentoo下不行)

[复制链接]
发表于 2008-12-12 07:02:06 | 显示全部楼层 |阅读模式
大家好,

基本上这个题目就是我的问题了。
我把debian下的.vimrc复制到gentoo下,发现vim没法把光标回复到最后编辑的位置,可debian下就可以。看到ubuntu论坛的一个人说是需要装vim-full,可gentoo里哪儿来的vim-full啊?我到目前位置装了vim和vim-core(都是7.2.021)。

请大家指点一下。

谢谢大家。

问题的关键在于~目录下的.viminfo文件的读写权限,gentoo下默认是root用户的600文件。
发表于 2008-12-12 09:49:01 | 显示全部楼层
怎么恢复到最后位置?

分享一下。
回复 支持 反对

使用道具 举报

发表于 2008-12-12 12:34:07 | 显示全部楼层
Post by tionja;1922723

问题的关键在于~目录下的.viminfo文件的读写权限,gentoo下默认是root用户的600文件。

这个就是解决问题的关键
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-12-12 20:59:22 | 显示全部楼层
Post by acevery;1922762
怎么恢复到最后位置?

分享一下。

我想你可能是要知道那段vimrc里的代码,如下:

  1. " Uncomment the following to have Vim jump to the last position when
  2. " reopening a file
  3. "if has("autocmd")
  4. "  au BufReadPost * if line("'"") > 0 && line("'"") <= line("$")
  5. "    \| exe "normal g'"" | endif
  6. "endif
复制代码

试试看吧
回复 支持 反对

使用道具 举报

发表于 2008-12-12 21:17:21 | 显示全部楼层
谢谢,试了一下,感觉没有变化...难道是因为我原先就是回去最后编辑的一行?

另外,分享一下我的一个插件,每当你在插入模式下输到窗口最后一行的时候,自动把当前行卷到窗口中央 主要是用了几天emacs就这个功能和中文的段落重排比较满意,这个自动scroll实现比较简单,就自己动手加到vim里来了。

放到.vim/plugin下即可。
  1. " Filename: iautoscroll.vim
  2. " Author: Yu Yuwei <acevery@gmail.com>
  3. " Verson: 0.4
  4. " Last Modify: Dec 12, 2008
  5. " Function: Scrolling to center when cursor hit the last line in window
  6. "      while inserting
  7. " Usage: in your ~/.vimrc, let g:IAutoScrollMode="<mode>", where <mode>
  8. "        is "center" for scroll to center, or "top" for scroll to top,
  9. "        "off" to disable this plugin.
  10. " Changlog:
  11. "   0.4: Dec 12, 2008
  12. "       move the line and col check into if clause,
  13. "       which is a little overhead before if :)
  14. "   0.3: Oct 06, 2008
  15. "       fix logical error using "off"
  16. "       move cursor to original place after scrolling
  17. "   0.2: Sep 20, 2008
  18. "       support to scroll to top
  19. " ----------
  20. "
  21. if !exists("IAutoScrollMode")
  22.     let IAutoScrollMode = "center"
  23. endif
  24. autocmd! CursorMovedI * silent call ICheck_Scroll()
  25. function ICheck_Scroll()
  26.     " we only check scroll when enabled:)
  27.     if g:IAutoScrollMode != "off"
  28.         " first, get the line number in window
  29.         let cursor_line_no = winline()
  30.         " second, get the window height
  31.         let winht = winheight(winnr())
  32.         " if we hit the bottom, just move to center
  33.         if cursor_line_no == winht
  34.             " now store get the current line and column
  35.             let cur_line = line('.')
  36.             let cur_col = col('.')
  37.             " OK, we are ready to move :)
  38.             if g:IAutoScrollMode == "center"
  39.                 exec "normal zz"
  40.             elseif g:IAutoScrollMode == "top"
  41.                 exec "normal zt"
  42.             else
  43.                 exec "normal zz"
  44.             endif
  45.             " we need move cursor back to the original place,
  46.             " otherwise insert mode in new line
  47.             " would put cursor one space ahead.
  48.             exec "call cursor(cur_line,cur_col)"
  49.         endif
  50.     endif
  51. endfunction
复制代码
回复 支持 反对

使用道具 举报

发表于 2008-12-12 22:29:42 | 显示全部楼层
Post by acevery;1923083
谢谢,试了一下,感觉没有变化...难道是因为我原先就是回去最后编辑的一行?

另外,分享一下我的一个插件,每当你在插入模式下输到窗口最后一行的时候,自动把当前行卷到窗口中央 主要是用了几天emacs就这个功能和中文的段落重排比较满意,这个自动scroll实现比较简单,就自己动手加到vim里来了。

放到.vim/plugin下即可。

  1. " Filename: iautoscroll.vim
  2. " Author: Yu Yuwei <acevery@gmail.com>
  3. " Verson: 0.4
  4. " Last Modify: Dec 12, 2008
  5. " Function: Scrolling to center when cursor hit the last line in window
  6. "      while inserting
  7. " Usage: in your ~/.vimrc, let g:IAutoScrollMode="<mode>", where <mode>
  8. "        is "center" for scroll to center, or "top" for scroll to top,
  9. "        "off" to disable this plugin.
  10. " Changlog:
  11. "   0.4: Dec 12, 2008
  12. "       move the line and col check into if clause,
  13. "       which is a little overhead before if :)
  14. "   0.3: Oct 06, 2008
  15. "       fix logical error using "off"
  16. "       move cursor to original place after scrolling
  17. "   0.2: Sep 20, 2008
  18. "       support to scroll to top
  19. " ----------
  20. "

  21. if !exists("IAutoScrollMode")
  22.     let IAutoScrollMode = "center"
  23. endif

  24. autocmd! CursorMovedI * silent call ICheck_Scroll()

  25. function ICheck_Scroll()
  26.     " we only check scroll when enabled:)
  27.     if g:IAutoScrollMode != "off"
  28.         " first, get the line number in window
  29.         let cursor_line_no = winline()
  30.         " second, get the window height
  31.         let winht = winheight(winnr())
  32.         " if we hit the bottom, just move to center
  33.         if cursor_line_no == winht
  34.             " now store get the current line and column
  35.             let cur_line = line('.')
  36.             let cur_col = col('.')
  37.             " OK, we are ready to move :)
  38.             if g:IAutoScrollMode == "center"
  39.                 exec "normal zz"
  40.             elseif g:IAutoScrollMode == "top"
  41.                 exec "normal zt"
  42.             else
  43.                 exec "normal zz"
  44.             endif
  45.             " we need move cursor back to the original place,
  46.             " otherwise insert mode in new line
  47.             " would put cursor one space ahead.
  48.             exec "call cursor(cur_line,cur_col)"
  49.         endif
  50.     endif
  51. endfunction
复制代码


EBUILD EBUILD :cool:
回复 支持 反对

使用道具 举报

发表于 2008-12-12 22:38:21 | 显示全部楼层
Post by tionja;1922723

问题的关键在于~目录下的.viminfo文件的读写权限,gentoo下默认是root用户的600文件。


如果你确实默认是这样,不妨去报告一个bug
回复 支持 反对

使用道具 举报

发表于 2008-12-12 22:52:46 | 显示全部楼层
我遇到的一般都是 cp root 用户的文件导致的。
比如复制 .vimrc 的使用 sudo cp .vim* ./
回复 支持 反对

使用道具 举报

发表于 2008-12-12 23:23:29 | 显示全部楼层
Post by wd_afei;1923120
我遇到的一般都是 cp root 用户的文件导致的。
比如复制 .vimrc 的使用 sudo cp .vim* ./


我用什么用户cp之后就是什么用户文件,也没有设置过。


Blahster, 感觉这个功能比较简单

刚刚修改了一下从大家起来学vim教程是找到的中文段落重排的插件format.vim,终于能在utf8下用gq motion和gqq正确重排中文了,一起贴出来共享之
因为比较大,就用附件上传吧。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-12-12 23:24:17 | 显示全部楼层
@acevery
感谢分享这个插件,在次之前我一直用set so=9999这个办法的。

@zhllg
我隐约记得debian下的.viminfo文件最初也是root600文件,所以不知道这个权限设置是不是有意而为之的。也不清楚改了会有啥后果...
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表